diff --git a/Cargo.toml b/Cargo.toml index 29b5a7d..61da81e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dns-stamp-parser" -version = "3.0.0" +version = "3.0.1" authors = ["LinkTed ", "Evan Cameron "] license = "BSD-3-Clause" edition = "2018" @@ -14,7 +14,7 @@ categories = ["parser-implementations", "encoding"] base64 = "0.22" bitflags = "2" thiserror = "1" -trust-dns-resolver = { version = "0.20", optional = true } +trust-dns-resolver = { version = "0.23", optional = true } [features] default = [] diff --git a/src/lib.rs b/src/lib.rs index 81dd0d0..fe5615c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -291,12 +291,7 @@ fn bootstrap_hostname(addr: Option, host: &str, bootstrap: &[IpAddr]) -> i let mut config = ResolverConfig::new(); for ip in bootstrap { let socket_addr = SocketAddr::new(*ip, 53); - config.add_name_server(NameServerConfig { - socket_addr, - protocol: Protocol::Udp, - tls_dns_name: None, - trust_nx_responses: false, - }); + config.add_name_server(NameServerConfig::new(socket_addr, Protocol::Udp)); } let resolver = Resolver::new(config, ResolverOpts::default()).unwrap(); diff --git a/tests/ip_addr.rs b/tests/ip_addr.rs index f5335e5..ab86ef0 100644 --- a/tests/ip_addr.rs +++ b/tests/ip_addr.rs @@ -8,25 +8,9 @@ static DNS_STAMPS: [&str; 2] = [ #[test] fn ip_addrs() { for stamp_1 in DNS_STAMPS.iter() { - match DnsStamp::decode(stamp_1) { - Ok(dns_stamp_1) => match dns_stamp_1.encode() { - Ok(stamp_2) => match DnsStamp::decode(&stamp_2) { - Ok(dns_stamp_2) => { - if dns_stamp_1 != dns_stamp_2 { - panic!("Not equal: {} {}", stamp_1, stamp_2); - } - } - Err(e) => { - panic!("Decode 2: {:?}: {} {}", e, stamp_1, stamp_2); - } - }, - Err(e) => { - panic!("Encode 1: {:?}: {}", e, stamp_1); - } - }, - Err(e) => { - panic!("Decode 1: {:?}: {}", e, stamp_1); - } - } + let dns_stamp_1 = DnsStamp::decode(stamp_1).unwrap(); + let stamp_2 = dns_stamp_1.encode().unwrap(); + let dns_stamp_2 = DnsStamp::decode(&stamp_2).unwrap(); + assert_eq!(dns_stamp_1, dns_stamp_2); } } diff --git a/tests/odoh-relays.rs b/tests/odoh-relays.rs new file mode 100644 index 0000000..c9694d1 --- /dev/null +++ b/tests/odoh-relays.rs @@ -0,0 +1,22 @@ +use dns_stamp_parser::DnsStamp; + +// The list is from https://github.com/DNSCrypt/dnscrypt-resolvers/blob/master/v3/odoh-relays.md +static DNS_STAMPS: [&str; 4] = [ + "sdns://hQcAAAAAAAAADDg5LjM4LjEzMS4zOAAYb2RvaC1ubC5hbGVrYmVyZy5uZXQ6NDQzBi9wcm94eQ", + "sdns://hQcAAAAAAAAAAAAab2RvaC1yZWxheS5lZGdlY29tcHV0ZS5hcHABLw", + "sdns://hQcAAAAAAAAADjIxMy4xOTYuMTkxLjk2ABhpYmtzdHVybS5zeW5vbG9neS5tZTo0NDMGL3Byb3h5", + "sdns://hQcAAAAAAAAADTQ1LjE1My4xODcuOTYAGG9kb2gtc2UuYWxla2JlcmcubmV0OjQ0MwYvcHJveHk", +]; + +/// Test all DNS Stamp from the [list] by decode and encode and decode it again. +/// +/// [list]: https://github.com/DNSCrypt/dnscrypt-resolvers/blob/master/v3/odoh-relays.md +#[test] +fn relays() { + for stamp_1 in DNS_STAMPS.iter() { + let dns_stamp_1 = DnsStamp::decode(stamp_1).unwrap(); + let stamp_2 = dns_stamp_1.encode().unwrap(); + let dns_stamp_2 = DnsStamp::decode(&stamp_2).unwrap(); + assert_eq!(dns_stamp_1, dns_stamp_2); + } +} diff --git a/tests/onion_services.rs b/tests/onion_services.rs index 3b1d2ee..20a53fe 100644 --- a/tests/onion_services.rs +++ b/tests/onion_services.rs @@ -11,25 +11,9 @@ static DNS_STAMPS: [&str; 1] = [ #[test] fn parental_control() { for stamp_1 in DNS_STAMPS.iter() { - match DnsStamp::decode(stamp_1) { - Ok(dns_stamp_1) => match dns_stamp_1.encode() { - Ok(stamp_2) => match DnsStamp::decode(&stamp_2) { - Ok(dns_stamp_2) => { - if dns_stamp_1 != dns_stamp_2 { - panic!("Not equal: {} {}", stamp_1, stamp_2); - } - } - Err(e) => { - panic!("Decode 2: {:?}: {} {}", e, stamp_1, stamp_2); - } - }, - Err(e) => { - panic!("Encode 1: {:?}: {}", e, stamp_1); - } - }, - Err(e) => { - panic!("Decode 1: {:?}: {}", e, stamp_1); - } - } + let dns_stamp_1 = DnsStamp::decode(stamp_1).unwrap(); + let stamp_2 = dns_stamp_1.encode().unwrap(); + let dns_stamp_2 = DnsStamp::decode(&stamp_2).unwrap(); + assert_eq!(dns_stamp_1, dns_stamp_2); } } diff --git a/tests/opennic.rs b/tests/opennic.rs index 1651445..b7761c3 100644 --- a/tests/opennic.rs +++ b/tests/opennic.rs @@ -17,25 +17,9 @@ static DNS_STAMPS: [&str; 7] = [ #[test] fn opennic() { for stamp_1 in DNS_STAMPS.iter() { - match DnsStamp::decode(stamp_1) { - Ok(dns_stamp_1) => match dns_stamp_1.encode() { - Ok(stamp_2) => match DnsStamp::decode(&stamp_2) { - Ok(dns_stamp_2) => { - if dns_stamp_1 != dns_stamp_2 { - panic!("Not equal: {} {}", stamp_1, stamp_2); - } - } - Err(e) => { - panic!("Decode 2: {:?}: {} {}", e, stamp_1, stamp_2); - } - }, - Err(e) => { - panic!("Encode 1: {:?}: {}", e, stamp_1); - } - }, - Err(e) => { - panic!("Decode 1: {:?}: {}", e, stamp_1); - } - } + let dns_stamp_1 = DnsStamp::decode(stamp_1).unwrap(); + let stamp_2 = dns_stamp_1.encode().unwrap(); + let dns_stamp_2 = DnsStamp::decode(&stamp_2).unwrap(); + assert_eq!(dns_stamp_1, dns_stamp_2); } } diff --git a/tests/parental_control.rs b/tests/parental_control.rs index e3a92f2..be156d5 100644 --- a/tests/parental_control.rs +++ b/tests/parental_control.rs @@ -31,25 +31,9 @@ static DNS_STAMPS: [&str; 21] = [ #[test] fn parental_control() { for stamp_1 in DNS_STAMPS.iter() { - match DnsStamp::decode(stamp_1) { - Ok(dns_stamp_1) => match dns_stamp_1.encode() { - Ok(stamp_2) => match DnsStamp::decode(&stamp_2) { - Ok(dns_stamp_2) => { - if dns_stamp_1 != dns_stamp_2 { - panic!("Not equal: {} {}", stamp_1, stamp_2); - } - } - Err(e) => { - panic!("Decode 2: {:?}: {} {}", e, stamp_1, stamp_2); - } - }, - Err(e) => { - panic!("Encode 1: {:?}: {}", e, stamp_1); - } - }, - Err(e) => { - panic!("Decode 1: {:?}: {}", e, stamp_1); - } - } + let dns_stamp_1 = DnsStamp::decode(stamp_1).unwrap(); + let stamp_2 = dns_stamp_1.encode().unwrap(); + let dns_stamp_2 = DnsStamp::decode(&stamp_2).unwrap(); + assert_eq!(dns_stamp_1, dns_stamp_2); } } diff --git a/tests/parse.rs b/tests/parse.rs index d0ddbb7..fece7ca 100644 --- a/tests/parse.rs +++ b/tests/parse.rs @@ -39,50 +39,21 @@ fn decode_uint64() { assert_eq!(DnsStamp::decode(stamp), Err(DecodeError::NotEnoughBytes)) } -// The list is from https://github.com/DNSCrypt/dnscrypt-resolvers/blob/master/v2/public-resolvers.md -static DNS_STAMPS: [&str; 15] = [ - "sdns://AgcAAAAAAAAAACA-GhoPbFPz6XpJLVcIS1uYBwWe4FerFQWHb9g_2j24OBRpYmtzdHVybS5zeW5vbG9neS5tZQovZG5zLXF1ZXJ5", - "sdns://AQcAAAAAAAAAEDg1LjUuOTMuMjMwOjg0NDMgwc9XUACwW8JsYh9ez5qiVgrOvwB-vss6f_SyDeC0Oe4YMi5kbnNjcnlwdC1jZXJ0Lmlia3N0dXJt", - "sdns://AQcAAAAAAAAALlsyYTAyOjEyMDU6NTA1NTpkZTYwOmIyNmU6YmZmZjpmZTFkOmUxOWJdOjg0NDMgwc9XUACwW8JsYh9ez5qiVgrOvwB-vss6f_SyDeC0Oe4YMi5kbnNjcnlwdC1jZXJ0Lmlia3N0dXJt", - "sdns://AQcAAAAAAAAAETE1MS44MC4yMjIuNzk6NDQ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Z3MuY28", - "sdns://AQcAAAAAAAAADDQ1Ljc2LjExMy4zMSAIVGh4i6eKXqlF6o9Fg92cgD2WcDvKQJ7v_Wq4XrQsVhsyLmRuc2NyeXB0LWNlcnQuZG5zLnNlYnkuaW8", - "sdns://AgcAAAAAAAAADDQ1Ljc2LjExMy4zMSA-GhoPbFPz6XpJLVcIS1uYBwWe4FerFQWHb9g_2j24OBBkb2guc2VieS5pbzo4NDQzCi9kbnMtcXVlcnk", - "sdns://AQcAAAAAAAAADTEzOS45OS4yMjIuNzIgCwVoTw0L4dgal5LC1FbZUtHtLR_rVuV6rVnxO95e4GUbMi5kbnNjcnlwdC1jZXJ0LmRucy5zZWJ5Lmlv", - "sdns://AgcAAAAAAAAADTEzOS45OS4yMjIuNzIgPhoaD2xT8-l6SS1XCEtbmAcFnuBXqxUFh2_YP9o9uDgRZG9oLTIuc2VieS5pbzo0NDMKL2Rucy1xdWVyeQ", +// Self generated dns-stamp via https://dnscrypt.info/stamps. +static DNS_STAMPS: [&str; 4] = [ + "sdns://AwcAAAAAAAAACTEyNy4wLjAuMQAObG9jYWxob3N0OjgwODA", + "sdns://BAcAAAAAAAAACTEyNy4wLjAuMQAObG9jYWxob3N0OjgwODA", + "sdns://BAcAAAAAAAAACTEyNy4wLjAuMQAJbG9jYWxob3N0", + "sdns://BQcAAAAAAAAACWxvY2FsaG9zdAovZG5zLXF1ZXJ5", ]; /// Test all DNS Stamp from the [list] by decode and encode and decode it again. -/// -/// [list]: https://github.com/DNSCrypt/dnscrypt-resolvers/blob/master/v2/opennic.md #[test] -fn opennic() { +fn decode_encode_decode() { for stamp_1 in DNS_STAMPS.iter() { - match dbg!(stamp_1.parse::()) { - Ok(dns_stamp_1) => match dns_stamp_1.encode() { - Ok(stamp_2) => match stamp_2.parse::() { - Ok(dns_stamp_2) => { - if dns_stamp_1 != dns_stamp_2 { - panic!("Not equal: {} {}", stamp_1, stamp_2); - } - } - Err(e) => { - panic!("Decode 2: {:?}: {} {}", e, stamp_1, stamp_2); - } - }, - Err(e) => { - panic!("Encode 1: {:?}: {}", e, stamp_1); - } - }, - Err(e) => { - panic!("Decode 1: {:?}: {}", e, stamp_1); - } - } + let dns_stamp_1 = DnsStamp::decode(stamp_1).unwrap(); + let stamp_2 = dns_stamp_1.encode().unwrap(); + let dns_stamp_2 = DnsStamp::decode(&stamp_2).unwrap(); + assert_eq!(dns_stamp_1, dns_stamp_2); } } diff --git a/tests/public_resolvers.rs b/tests/public_resolvers.rs index 604d87c..f1448e5 100644 --- a/tests/public_resolvers.rs +++ b/tests/public_resolvers.rs @@ -257,25 +257,9 @@ static DNS_STAMPS: [&str; 247] = [ #[test] fn public_resolvers() { for stamp_1 in DNS_STAMPS.iter() { - match DnsStamp::decode(stamp_1) { - Ok(dns_stamp_1) => match dns_stamp_1.encode() { - Ok(stamp_2) => match DnsStamp::decode(&stamp_2) { - Ok(dns_stamp_2) => { - if dns_stamp_1 != dns_stamp_2 { - panic!("Not equal: {} {}", stamp_1, stamp_2); - } - } - Err(e) => { - panic!("Decode 2: {:?}: {} {}", e, stamp_1, stamp_2); - } - }, - Err(e) => { - panic!("Encode 1: {:?}: {}", e, stamp_1); - } - }, - Err(e) => { - panic!("Decode 1: {:?}: {}", e, stamp_1); - } - } + let dns_stamp_1 = DnsStamp::decode(stamp_1).unwrap(); + let stamp_2 = dns_stamp_1.encode().unwrap(); + let dns_stamp_2 = DnsStamp::decode(&stamp_2).unwrap(); + assert_eq!(dns_stamp_1, dns_stamp_2); } } diff --git a/tests/relays.rs b/tests/relays.rs index 58a24d9..4eff654 100644 --- a/tests/relays.rs +++ b/tests/relays.rs @@ -50,25 +50,9 @@ static DNS_STAMPS: [&str; 40] = [ #[test] fn relays() { for stamp_1 in DNS_STAMPS.iter() { - match DnsStamp::decode(stamp_1) { - Ok(dns_stamp_1) => match dns_stamp_1.encode() { - Ok(stamp_2) => match DnsStamp::decode(&stamp_2) { - Ok(dns_stamp_2) => { - if dns_stamp_1 != dns_stamp_2 { - panic!("Not equal: {} {}", stamp_1, stamp_2); - } - } - Err(e) => { - panic!("Decode 2: {:?}: {} {}", e, stamp_1, stamp_2); - } - }, - Err(e) => { - panic!("Encode 1: {:?}: {}", e, stamp_1); - } - }, - Err(e) => { - panic!("Decode 1: {:?}: {}", e, stamp_1); - } - } + let dns_stamp_1 = DnsStamp::decode(stamp_1).unwrap(); + let stamp_2 = dns_stamp_1.encode().unwrap(); + let dns_stamp_2 = DnsStamp::decode(&stamp_2).unwrap(); + assert_eq!(dns_stamp_1, dns_stamp_2); } }