hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit bd0a080ab89d45806ec5c466ba861e4509d770a9
parent 3fbc8c57af743be541b7d872eef000c16bdd419e
Author: Conrad Hoffmann <ch@bitfehler.net>
Date:   Tue, 13 Jun 2023 21:55:18 +0200

net::dns: add support for SSHFP records

Signed-off-by: Conrad Hoffmann <ch@bitfehler.net>

Diffstat:
Mnet/dns/decode.ha | 12++++++++++++
Mnet/dns/types.ha | 13++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/net/dns/decode.ha b/net/dns/decode.ha @@ -207,6 +207,8 @@ fn decode_rdata(dec: *decoder, rtype: rtype, rlen: size) (rdata | format) = { return decode_soa(&sub); case rtype::SRV => return decode_srv(&sub); + case rtype::SSHFP => + return decode_sshfp(&sub); case rtype::TXT => return decode_txt(&sub); case => @@ -306,6 +308,16 @@ fn decode_srv(dec: *decoder) (rdata | format) = { }; }; +fn decode_sshfp(dec: *decoder) (rdata | format) = { + let r = sshfp { + algorithm = decode_u8(dec)?, + fp_type = decode_u8(dec)?, + fingerprint = [], + }; + append(r.fingerprint, dec.cur[..]...); + return r; +}; + fn decode_txt(dec: *decoder) (rdata | format) = { let success = false; let items: txt = []; diff --git a/net/dns/types.ha b/net/dns/types.ha @@ -17,6 +17,7 @@ export type rtype = enum u16 { TXT = 16, AAAA = 28, SRV = 33, + SSHFP = 44, DNSKEY = 48, CAA = 257, }; @@ -32,6 +33,7 @@ export type qtype = enum u16 { TXT = 16, AAAA = 28, SRV = 33, + SSHFP = 44, DNSKEY = 48, // ... AXFR = 252, @@ -181,6 +183,13 @@ export type srv = struct { target: []str, }; +// An SSHFP record. +export type sshfp = struct { + algorithm: u8, + fp_type: u8, + fingerprint: []u8, +}; + // A TXT record. export type txt = [][]u8; @@ -188,7 +197,7 @@ export type txt = [][]u8; export type unknown_rdata = []u8; // Tagged union of supported rdata types. -export type rdata = (a | aaaa | caa | cname | mx | ns | ptr | soa | srv | txt | unknown_rdata); +export type rdata = (a | aaaa | caa | cname | mx | ns | ptr | soa | srv | sshfp | txt | unknown_rdata); // A DNS message, Hare representation. See [[encode]] and [[decode]] for the DNS // representation. @@ -247,6 +256,8 @@ fn rrecord_finish(rr: *rrecord) void = { strings::freeall(so.rname); case let sr: srv => strings::freeall(sr.target); + case let sf: sshfp => + free(sf.fingerprint); case let tx: txt => bytes_free(tx: [][]u8); case => void;