// If the string has more characters than are required to alphabet_encode the number of bytes
// decodable, treat the string as invalid.
match data.len() % 8 { 1|3|6 => return Err(()), _ => {} }
- Ok(decode_data(data, RFC4648_INV_ALPHABET)?)
+ decode_data(data, RFC4648_INV_ALPHABET)
}
/// Encode a byte slice into a base32 string.
// Luckily, it seems to work fine in 1.63 with the feature flag (and RUSTC_BOOTSTRAP=1) enabled.
#![cfg_attr(all(feature = "validation", rust_1_63), feature(const_slice_from_raw_parts))]
+#![allow(clippy::new_without_default)] // why is this even a lint
+#![allow(clippy::result_unit_err)] // Why in the hell is this a lint?
+#![allow(clippy::get_first)] // Sometimes this improves readability
#![allow(clippy::needless_lifetimes)] // lifetimes improve readability
#![allow(clippy::needless_borrow)] // borrows indicate read-only/non-move
#![allow(clippy::too_many_arguments)] // sometimes we don't have an option
// Luckily, it seems to work fine in 1.63 with the feature flag (and RUSTC_BOOTSTRAP=1) enabled.
#![cfg_attr(rust_1_63, feature(const_slice_from_raw_parts))]
+#![allow(clippy::new_without_default)] // why is this even a lint
+#![allow(clippy::result_unit_err)] // Why in the hell is this a lint?
+#![allow(clippy::get_first)] // Sometimes this improves readability
#![allow(clippy::needless_lifetimes)] // lifetimes improve readability
#![allow(clippy::needless_borrow)] // borrows indicate read-only/non-move
#![allow(clippy::too_many_arguments)] // sometimes we don't have an option
// Only read the answers and NSEC records in authorities, skipping additional entirely.
let mut min_ttl = u32::MAX;
for _ in 0..answers {
- let (rr, ttl) = parse_wire_packet_rr(&mut read, &resp)?;
+ let (rr, ttl) = parse_wire_packet_rr(&mut read, resp)?;
write_rr(&rr, ttl, proof);
min_ttl = cmp::min(min_ttl, ttl);
if let RR::RRSig(rrsig) = rr { rrsig_key_names.push(rrsig.key_name); }
for _ in 0..authorities {
// Only include records from the authority section if they are NSEC/3 (or signatures
// thereover). We don't care about NS records here.
- let (rr, ttl) = parse_wire_packet_rr(&mut read, &resp)?;
+ let (rr, ttl) = parse_wire_packet_rr(&mut read, resp)?;
match &rr {
RR::RRSig(rrsig) => {
if rrsig.ty != NSec::TYPE && rrsig.ty != NSec3::TYPE {
if self.pending_queries == 0 { return Err(()); }
let mut rrsig_key_names = Vec::new();
- let min_ttl = handle_response(&resp, &mut self.proof, &mut rrsig_key_names)?;
+ let min_ttl = handle_response(resp, &mut self.proof, &mut rrsig_key_names)?;
self.min_ttl = cmp::min(self.min_ttl, min_ttl);
self.pending_queries -= 1;
} else if n == 0 {
Some(".")
} else {
- self.as_str().splitn(labels as usize - n as usize + 1, ".").last()
+ self.as_str().splitn(labels as usize - n as usize + 1, '.').last()
}
}
}
if *s.as_bytes().last().unwrap_or(&0) != b"."[0] { return Err(()); }
if s.len() > 255 { return Err(()); }
if s.chars().any(|c| !c.is_ascii_graphic() || c == '"') { return Err(()); }
- for label in s.split(".") {
+ for label in s.split('.') {
if label.len() > 63 { return Err(()); }
}
}
}
-#[derive(Debug, Clone, PartialEq, Eq, Ord)]
+#[derive(Debug, Clone, PartialEq, Eq)]
/// A text resource record, containing arbitrary text data
pub struct Txt {
/// The name this record is at.
}
/// The wire type for TXT records
pub const TXT_TYPE: u16 = 16;
-impl PartialOrd for Txt {
- fn partial_cmp(&self, o: &Txt) -> Option<Ordering> {
- Some(self.name.cmp(&o.name)
+impl Ord for Txt {
+ fn cmp(&self, o: &Txt) -> Ordering {
+ self.name.cmp(&o.name)
.then_with(|| {
// Compare in wire encoding form, i.e. compare in 255-byte chunks
for i in 1..(self.data.len() / 255) + 2 {
if !slice_cmp.is_eq() { return slice_cmp; }
}
Ordering::Equal
- }))
+ })
}
}
+impl PartialOrd for Txt {
+ fn partial_cmp(&self, o: &Txt) -> Option<Ordering> { Some(self.cmp(o)) }
+}
impl StaticRecord for Txt {
const TYPE: u16 = TXT_TYPE;
fn name(&self) -> &Name { &self.name }
fn read_from_data(name: Name, data: &[u8], _wire_packet: &[u8]) -> Result<Self, ()> {
if data.len() != 4 { return Err(()); }
let mut address = [0; 4];
- address.copy_from_slice(&data);
+ address.copy_from_slice(data);
Ok(A { name, address })
}
fn write_u16_len_prefixed_data<W: Writer>(&self, out: &mut W) {
fn read_from_data(name: Name, data: &[u8], _wire_packet: &[u8]) -> Result<Self, ()> {
if data.len() != 16 { return Err(()); }
let mut address = [0; 16];
- address.copy_from_slice(&data);
+ address.copy_from_slice(data);
Ok(AAAA { name, address })
}
fn write_u16_len_prefixed_data<W: Writer>(&self, out: &mut W) {
use crate::query::QueryBuf;
pub(crate) fn read_u8(inp: &mut &[u8]) -> Result<u8, ()> {
- let res = *inp.get(0).ok_or(())?;
+ let res = *inp.first().ok_or(())?;
*inp = &inp[1..];
Ok(res)
}
}
pub(crate) fn read_u8_len_prefixed_bytes(inp: &mut &[u8]) -> Result<Vec<u8>, ()> {
- let len = *inp.get(0).ok_or(())?;
+ let len = *inp.first().ok_or(())?;
*inp = &inp[1..];
if inp.len() < len.into() { return Err(()); }
let mut res = Vec::with_capacity(len.into());
pub(crate) fn write_nsec_types_bitmap<W: Writer>(out: &mut W, types: &[u8; 8192]) {
for (idx, flags) in types.chunks(32).enumerate() {
debug_assert_eq!(flags.len(), 32);
- if flags != &[0; 32] {
+ if flags != [0; 32] {
let last_nonzero_idx = flags.iter().rposition(|flag| *flag != 0)
.unwrap_or_else(|| { debug_assert!(false); 0 });
out.write(&(idx as u8).to_be_bytes());
let mut total_len = 0;
for flags in types.chunks(32) {
debug_assert_eq!(flags.len(), 32);
- if flags != &[0; 32] {
+ if flags != [0; 32] {
total_len += 3 + flags.iter().rposition(|flag| *flag != 0)
.unwrap_or_else(|| { debug_assert!(false); 0 }) as u16;
}
pub(crate) fn read_wire_packet_name(inp: &mut &[u8], wire_packet: &[u8]) -> Result<Name, ()> {
let mut name = String::with_capacity(1024);
read_wire_packet_labels(inp, wire_packet, &mut name)?;
- Ok(name.try_into()?)
+ name.try_into()
}
pub(crate) trait Writer { fn write(&mut self, buf: &[u8]); }
if canonical_name == "." {
out.write(&[0]);
} else {
- for label in canonical_name.split(".") {
+ for label in canonical_name.split('.') {
out.write(&(label.len() as u8).to_be_bytes());
out.write(label.as_bytes());
}
1
} else {
let mut res = 0;
- for label in name.split(".") {
+ for label in name.split('.') {
res += 1 + label.len();
}
res as u16
ctx.update(&dnskey.alg.to_be_bytes());
ctx.update(&dnskey.pubkey);
let hash = ctx.finish();
- if hash.as_ref() == &ds.digest {
+ if hash.as_ref() == ds.digest {
validated_dnskeys.push(*dnskey);
break;
}
let mut found_unsupported_alg = false;
for sig in sigs {
- match verify_rrsig(sig, validated_dnskeys.iter().map(|k| *k), records.clone()) {
+ match verify_rrsig(sig, validated_dnskeys.iter().copied(), records.clone()) {
Ok(()) => return Ok(sig),
Err(ValidationError::UnsupportedAlgorithm) => {
// There may be redundant signatures by different keys, where one we don't
}
fn nsec_ord(a: &str, b: &str) -> Ordering {
- let mut a_label_iter = a.rsplit(".");
- let mut b_label_iter = b.rsplit(".");
+ let mut a_label_iter = a.rsplit('.');
+ let mut b_label_iter = b.rsplit('.');
loop {
match (a_label_iter.next(), b_label_iter.next()) {
(Some(_), None) => return Ordering::Greater,
(Some(_), None) => return Ordering::Greater,
(None, Some(_)) => return Ordering::Less,
(Some(mut a), Some(mut b)) => {
- if a >= 'A' as u8 && a <= 'Z' as u8 {
- a += 'a' as u8 - 'A' as u8;
+ if a.is_ascii_uppercase() {
+ a += b'a' - b'A';
}
- if b >= 'A' as u8 && b <= 'Z' as u8 {
- b += 'a' as u8 - 'A' as u8;
+ if b.is_ascii_uppercase() {
+ b += b'a' - b'A';
}
if a != b { return a.cmp(&b); }
},
.filter(|nsec| nsec.name.ends_with(zone.as_str()));
for nsec in nsec_search {
let name_matches = nsec.name.as_str() == name;
- let name_contained = nsec_ord(&nsec.name, &name) != Ordering::Greater &&
+ let name_contained = nsec_ord(&nsec.name, name) != Ordering::Greater &&
nsec_ord(&nsec.next_name, name) == Ordering::Greater;
if (name_matches && !nsec.types.contains_type(ty)) || name_contained {
rrs_needing_non_existence_proofs
{ continue; }
let mut hasher = crypto::hash::Hasher::sha1();
- write_name(&mut hasher, &name);
+ write_name(&mut hasher, name);
hasher.update(&nsec3.salt);
for _ in 0..nsec3.hash_iterations {
let res = hasher.finish();
hash
} else { continue };
- let (start_hash_base32, _) = nsec3.name.split_once(".")
+ let (start_hash_base32, _) = nsec3.name.split_once('.')
.unwrap_or_else(|| { debug_assert!(false); ("", "")});
let start_hash = if let Ok(start_hash) = base32::decode(start_hash_base32) {
start_hash
continue;
}
- return self.verified_rrs.iter().filter(|rr| rr.name() == name).map(|rr| *rr).collect();
+ return self.verified_rrs.iter().filter(|rr| rr.name() == name).copied().collect();
}
}
}