diff --git a/lib/src/storage/mod.rs b/lib/src/storage/mod.rs index d5fdbe7f..6b27dec2 100644 --- a/lib/src/storage/mod.rs +++ b/lib/src/storage/mod.rs @@ -215,9 +215,9 @@ impl Storage { fn ensure_version(&self) -> Result { Ok( if let Some(version) = self.db.get(&self.default_cf, b"oxversion")? { - let mut buffer = [0; 8]; - buffer.copy_from_slice(&version); - u64::from_be_bytes(buffer) + u64::from_be_bytes(version.as_ref().try_into().map_err(|e| { + CorruptionError::new(format!("Error while parsing the version key: {}", e)) + })?) } else { self.update_version(LATEST_STORAGE_VERSION)?; LATEST_STORAGE_VERSION diff --git a/lib/src/xsd/date_time.rs b/lib/src/xsd/date_time.rs index 8d8ccff0..1ca17002 100644 --- a/lib/src/xsd/date_time.rs +++ b/lib/src/xsd/date_time.rs @@ -1181,17 +1181,14 @@ impl Timestamp { } fn from_be_bytes(bytes: [u8; 18]) -> Self { - let mut value = [0; 16]; - value.copy_from_slice(&bytes[0..16]); - let mut timezone_offset = [0; 2]; - timezone_offset.copy_from_slice(&bytes[16..18]); - Self { - value: Decimal::from_be_bytes(value), - timezone_offset: if timezone_offset == [u8::MAX; 2] { + value: Decimal::from_be_bytes(bytes[0..16].try_into().unwrap()), + timezone_offset: if bytes[16..18] == [u8::MAX; 2] { None } else { - Some(TimezoneOffset::from_be_bytes(timezone_offset)) + Some(TimezoneOffset::from_be_bytes( + bytes[16..18].try_into().unwrap(), + )) }, } } diff --git a/lib/src/xsd/duration.rs b/lib/src/xsd/duration.rs index 935f5041..67f7fbfa 100644 --- a/lib/src/xsd/duration.rs +++ b/lib/src/xsd/duration.rs @@ -25,13 +25,9 @@ impl Duration { } pub fn from_be_bytes(bytes: [u8; 24]) -> Self { - let mut months = [0; 8]; - months.copy_from_slice(&bytes[0..8]); - let mut seconds = [8; 16]; - seconds.copy_from_slice(&bytes[8..24]); Self { - year_month: YearMonthDuration::from_be_bytes(months), - day_time: DayTimeDuration::from_be_bytes(seconds), + year_month: YearMonthDuration::from_be_bytes(bytes[0..8].try_into().unwrap()), + day_time: DayTimeDuration::from_be_bytes(bytes[8..24].try_into().unwrap()), } }