diff --git a/Cargo.toml b/Cargo.toml index b9b47db..8021d39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,6 @@ ed25519-dalek = { version = "2.0.0", default-features = false, features = [ "digest", ] } rand = "0.8" -byteorder = "1.3.4" data-encoding = "2.3.0" log = "0.4.11" crypto_box = { version = "0.9.1", optional = true } # For xKeys support diff --git a/src/crc.rs b/src/crc.rs index e2e0729..07d8bd2 100644 --- a/src/crc.rs +++ b/src/crc.rs @@ -1,7 +1,5 @@ use std::io::Cursor; -use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; - use super::error::{Error, ErrorKind}; use super::Result; @@ -45,26 +43,18 @@ pub(crate) fn valid_checksum(data: &[u8], expected: u16) -> bool { pub(crate) fn push_crc(data: &mut Vec) { let crc = crc16(data); - data.write_u16::(crc).unwrap(); + data.extend(u16::to_le_bytes(crc)); } pub(crate) fn extract_crc(data: &mut Vec) -> Result { - let crc_end_idx = if data.len() >= 2 { - data.len() - 2 - } else { - return Err(Error::new( - ErrorKind::ChecksumFailure, - Some("CRC data vector contains less than two characters"), - )); - }; - let crc_bytes = data[..crc_end_idx].to_vec(); - - let mut reader = Cursor::new(crc_bytes); - (*data).truncate(crc_end_idx); - reader.read_u16::().map_err(|e| { + let data_len = data.len().checked_sub(2).ok_or_else(|| { Error::new( ErrorKind::ChecksumFailure, - Some(format!("failed to read u16: {e}").as_str()), + Some("CRC data vector contains less than two characters"), ) - }) + })?; + + let crc = u16::from_le_bytes(data[..2].try_into().unwrap()); + data.truncate(data_len); + Ok(crc) }