use std::net::ToSocketAddrs;
use std::time::SystemTime;
+
+ #[test]
+ fn test_cloudflare_txt_query() {
+ let sockaddr = "8.8.8.8:53".to_socket_addrs().unwrap().next().unwrap();
+ let query_name = "cloudflare.com.".try_into().unwrap();
+ let proof = build_txt_proof(sockaddr, query_name).unwrap();
+
+ let mut rrs = parse_rr_stream(&proof).unwrap();
+ rrs.shuffle(&mut rand::rngs::OsRng);
+ let verified_rrs = verify_rr_stream(&rrs).unwrap();
+ assert!(verified_rrs.verified_rrs.len() > 1);
+
+ let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
+ assert!(verified_rrs.valid_from < now);
+ assert!(verified_rrs.expires > now);
+ }
+
#[test]
fn test_txt_query() {
let sockaddr = "8.8.8.8:53".to_socket_addrs().unwrap().next().unwrap();
use alloc::string::String;
use alloc::borrow::ToOwned;
+use core::cmp::Ordering;
+
use crate::ser::*;
/// A valid domain name.
}
}
-#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] // TODO: ord is wrong cause need to consider len first, maybe
+#[derive(Debug, Clone, PartialEq, Eq, Ord)]
/// A text resource record, containing arbitrary text data
pub struct Txt {
/// The name this record is at.
/// is an arbitrary series of bytes here.
pub data: Vec<u8>,
}
+impl PartialOrd for Txt {
+ fn partial_cmp(&self, o: &Txt) -> Option<Ordering> {
+ Some(self.name.cmp(&o.name)
+ .then_with(|| self.data.len().cmp(&o.data.len()))
+ .then_with(|| self.data.cmp(&o.data)))
+ }
+}
impl StaticRecord for Txt {
const TYPE: u16 = 16;
fn name(&self) -> &Name { &self.name }