X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fser.rs;fp=src%2Fser.rs;h=3cb3c89f2814bddd05566cd9ad88f49bbcf4a62d;hb=78af60e0fbddbf73c44a7a46952c42b0a57be2cb;hp=dfd89932e6afd15e46591504dd3f098c7885697a;hpb=ef16eea85a1416a593acae018abb1aa57c68794a;p=dnssec-prover diff --git a/src/ser.rs b/src/ser.rs index dfd8993..3cb3c89 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -7,7 +7,7 @@ use crate::rr::*; use crate::query::QueryBuf; pub(crate) fn read_u8(inp: &mut &[u8]) -> Result { - let res = *inp.get(0).ok_or(())?; + let res = *inp.first().ok_or(())?; *inp = &inp[1..]; Ok(res) } @@ -27,7 +27,7 @@ pub(crate) fn read_u32(inp: &mut &[u8]) -> Result { } pub(crate) fn read_u8_len_prefixed_bytes(inp: &mut &[u8]) -> Result, ()> { - 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()); @@ -39,7 +39,7 @@ pub(crate) fn read_u8_len_prefixed_bytes(inp: &mut &[u8]) -> Result, ()> pub(crate) fn write_nsec_types_bitmap(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()); @@ -52,7 +52,7 @@ pub(crate) fn nsec_types_bitmap_len(types: &[u8; 8192]) -> u16 { 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; } @@ -102,7 +102,7 @@ fn read_wire_packet_labels(inp: &mut &[u8], wire_packet: &[u8], name: &mut Strin pub(crate) fn read_wire_packet_name(inp: &mut &[u8], wire_packet: &[u8]) -> Result { 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]); } @@ -115,7 +115,7 @@ pub(crate) fn write_name(out: &mut W, name: &str) { 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()); } @@ -126,7 +126,7 @@ pub(crate) fn name_len(name: &Name) -> u16 { 1 } else { let mut res = 0; - for label in name.split(".") { + for label in name.split('.') { res += 1 + label.len(); } res as u16