diff --git a/src/models/dns.rs b/src/models/dns.rs index 7f3e8a3..8c0f752 100644 --- a/src/models/dns.rs +++ b/src/models/dns.rs @@ -155,6 +155,7 @@ impl From for RData { digest_type: sshfp.fingerprint_type().into(), fingerprint: trust_dns_types::sshfp::HEX.encode(sshfp.fingerprint()), }, + //TODO: This might alter data if not utf8 compatible, probably need to be replaced trust_dns_types::RData::TXT(txt) => RData::TXT { text: format!("{}", txt) }, trust_dns_types::RData::DNSSEC(data) => RData::DNSSEC(data), rdata => { @@ -180,6 +181,7 @@ impl TryFrom for trust_dns_types::RData { Ok(match rdata { RData::A { address } => trust_dns_types::RData::A(address), RData::AAAA { address } => trust_dns_types::RData::AAAA(address), + // TODO: Round trip test all types below (currently not tested...) RData::CAA { issuer_critical, value, property_tag } => { let property = trust_dns_types::caa::Property::from(property_tag); let caa_value = { @@ -203,16 +205,51 @@ impl TryFrom for trust_dns_types::RData { value: caa_value, }) }, - RData::CNAME { target } => todo!(), - RData::MX { preference, mail_exchanger } => todo!(), - RData::NULL { data } => todo!(), - RData::NS { target } => todo!(), - RData::PTR { target } => todo!(), - RData::SOA { master_server_name, maintainer_name, refresh, retry, expire, minimum, serial } => todo!(), - RData::SRV { server, port, priority, weight } => todo!(), - RData::SSHFP { algorithm, digest_type, fingerprint } => todo!(), - RData::TXT { text } => todo!(), + RData::CNAME { target } => trust_dns_types::RData::CNAME(target.into_inner()), + RData::MX { preference, mail_exchanger } => trust_dns_types::RData::MX( + trust_dns_types::mx::MX::new(preference, mail_exchanger.into_inner()) + ), + RData::NULL { data } => trust_dns_types::RData::NULL( + trust_dns_types::null::NULL::with( + base64::decode(data).map_err(|e| ProtoError::from(format!("{}", e)))? + ) + ), + RData::NS { target } => trust_dns_types::RData::NS(target.into_inner()), + RData::PTR { target } => trust_dns_types::RData::PTR(target.into_inner()), + RData::SOA { + master_server_name, + maintainer_name, + refresh, + retry, + expire, + minimum, + serial + } => trust_dns_types::RData::SOA( + trust_dns_types::soa::SOA::new( + master_server_name.into_inner(), + maintainer_name.into_inner(), + serial, + refresh, + retry, + expire, + minimum, + ) + ), + RData::SRV { server, port, priority, weight } => trust_dns_types::RData::SRV( + trust_dns_types::srv::SRV::new(priority, weight, port, server.into_inner()) + ), + RData::SSHFP { algorithm, digest_type, fingerprint } => trust_dns_types::RData::SSHFP( + trust_dns_types::sshfp::SSHFP::new( + // NOTE: This allows unassigned algorithms + trust_dns_types::sshfp::Algorithm::from(algorithm), + trust_dns_types::sshfp::FingerprintType::from(digest_type), + trust_dns_types::sshfp::HEX.decode(fingerprint.as_bytes()).map_err(|e| ProtoError::from(format!("{}", e)))? + ) + ), + RData::TXT { text } => trust_dns_types::RData::TXT(trust_dns_types::txt::TXT::new(vec![text])), + // TODO: Error out for DNSSEC? Prefer downstream checks? RData::DNSSEC(_) => todo!(), + // TODO: Disallow unknown? (could be used to bypass unsopported types?) Prefer downstream checks? RData::Unknown { code, data } => todo!(), }) } diff --git a/src/models/mod.rs b/src/models/mod.rs index dd71b7c..a43b162 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -4,7 +4,7 @@ pub mod users; pub mod trust_dns_types { pub use trust_dns_client::rr::rdata::{ - DNSSECRData, caa, sshfp, + DNSSECRData, caa, sshfp, mx, null, soa, srv, txt }; pub use trust_dns_client::rr::{ RData, DNSClass, Record