|
@@ -1,3 +1,4 @@
|
|
|
+use std::io::Read;
|
|
|
use std::net::Ipv6Addr;
|
|
|
|
|
|
use log::*;
|
|
@@ -24,24 +25,19 @@ impl Wire for AAAA {
|
|
|
|
|
|
#[cfg_attr(all(test, feature = "with_mutagen"), ::mutagen::mutate)]
|
|
|
fn read(stated_length: u16, c: &mut Cursor<&[u8]>) -> Result<Self, WireError> {
|
|
|
- let mut buf = Vec::new();
|
|
|
- for _ in 0 .. stated_length {
|
|
|
- buf.push(c.read_u8()?);
|
|
|
+ if stated_length != 16 {
|
|
|
+ warn!("Length is incorrect (stated length {:?}, but should be sixteen)", stated_length);
|
|
|
+ let mandated_length = MandatedLength::Exactly(16);
|
|
|
+ return Err(WireError::WrongRecordLength { stated_length, mandated_length });
|
|
|
}
|
|
|
|
|
|
- if let [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = *buf {
|
|
|
- let address = Ipv6Addr::from([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p]);
|
|
|
- // probably the best two lines of code I have ever written
|
|
|
+ let mut buf = [0_u8; 16];
|
|
|
+ c.read_exact(&mut buf)?;
|
|
|
|
|
|
- trace!("Parsed IPv6 address -> {:?}", address);
|
|
|
- Ok(Self { address })
|
|
|
- }
|
|
|
- else {
|
|
|
- warn!("Length is incorrect (stated length {:?}, but should be sixteen)", stated_length);
|
|
|
+ let address = Ipv6Addr::from(buf);
|
|
|
+ trace!("Parsed IPv6 address -> {:?}", address);
|
|
|
|
|
|
- let mandated_length = MandatedLength::Exactly(16);
|
|
|
- Err(WireError::WrongRecordLength { stated_length, mandated_length })
|
|
|
- }
|
|
|
+ Ok(Self { address })
|
|
|
}
|
|
|
}
|
|
|
|