From 5621847ca7183e2f5bd8fb2e21e499e1bac71138 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 26 Jul 2024 08:24:19 -0600 Subject: [PATCH] Bump `hybrid-array` to v0.2.0-rc.9 (#1616) Also fixes the deprecation warnings --- Cargo.lock | 4 ++-- aead/src/lib.rs | 12 +++++++----- digest/src/core_api/ct_variable.rs | 2 +- digest/src/core_api/rt_variable.rs | 5 ++--- digest/src/core_api/wrapper.rs | 3 +-- elliptic-curve/src/public_key.rs | 6 +++++- elliptic-curve/src/secret_key.rs | 4 ++-- signature/tests/derive.rs | 5 ++++- 8 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5755006f..13860c87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -731,9 +731,9 @@ dependencies = [ [[package]] name = "hybrid-array" -version = "0.2.0-rc.8" +version = "0.2.0-rc.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53668f5da5a41d9eaf4bf7064be46d1ebe6a4e1ceed817f387587b18f2b51047" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" dependencies = [ "typenum", "zeroize", diff --git a/aead/src/lib.rs b/aead/src/lib.rs index 157401f1..74ea8535 100644 --- a/aead/src/lib.rs +++ b/aead/src/lib.rs @@ -249,13 +249,15 @@ pub trait AeadMut: AeadCore { /// postfix authentication tag will need to define their own implementation. macro_rules! impl_decrypt_in_place { ($aead:expr, $nonce:expr, $aad:expr, $buffer:expr) => {{ - if $buffer.len() < Self::TagSize::to_usize() { - return Err(Error); - } + let tag_pos = $buffer + .len() + .checked_sub(Self::TagSize::to_usize()) + .ok_or(Error)?; - let tag_pos = $buffer.len() - Self::TagSize::to_usize(); let (msg, tag) = $buffer.as_mut().split_at_mut(tag_pos); - $aead.decrypt_in_place_detached($nonce, $aad, msg, Tag::::from_slice(tag))?; + let tag = Tag::::try_from(&*tag).expect("tag length mismatch"); + + $aead.decrypt_in_place_detached($nonce, $aad, msg, &tag)?; $buffer.truncate(tag_pos); Ok(()) }}; diff --git a/digest/src/core_api/ct_variable.rs b/digest/src/core_api/ct_variable.rs index fe917bfd..b676a352 100644 --- a/digest/src/core_api/ct_variable.rs +++ b/digest/src/core_api/ct_variable.rs @@ -221,7 +221,7 @@ where fn serialize(&self) -> SerializedState { let serialized_inner = self.inner.serialize(); - let serialized_outsize = Array::::clone_from_slice(&[OutSize::U8]); + let serialized_outsize = Array([OutSize::U8]); serialized_inner.concat(serialized_outsize) } diff --git a/digest/src/core_api/rt_variable.rs b/digest/src/core_api/rt_variable.rs index ccbb563a..b1a42942 100644 --- a/digest/src/core_api/rt_variable.rs +++ b/digest/src/core_api/rt_variable.rs @@ -157,10 +157,9 @@ where fn serialize(&self) -> SerializedState { let serialized_core = self.core.serialize(); - let serialized_pos = - Array::::clone_from_slice(&[self.buffer.get_pos().try_into().unwrap()]); + let serialized_pos = Array([self.buffer.get_pos().try_into().unwrap()]); let serialized_data = self.buffer.clone().pad_with_zeros(); - let serialized_output_size = Array::::clone_from_slice(&[self.output_size]); + let serialized_output_size = Array([self.output_size]); serialized_core .concat(serialized_pos) diff --git a/digest/src/core_api/wrapper.rs b/digest/src/core_api/wrapper.rs index d366249f..5d8f45d4 100644 --- a/digest/src/core_api/wrapper.rs +++ b/digest/src/core_api/wrapper.rs @@ -197,8 +197,7 @@ where fn serialize(&self) -> SerializedState { let serialized_core = self.core.serialize(); - let serialized_pos = - Array::::clone_from_slice(&[self.buffer.get_pos().try_into().unwrap()]); + let serialized_pos = Array([self.buffer.get_pos().try_into().unwrap()]); let serialized_data = self.buffer.clone().pad_with_zeros(); serialized_core diff --git a/elliptic-curve/src/public_key.rs b/elliptic-curve/src/public_key.rs index f0490671..aa728d2f 100644 --- a/elliptic-curve/src/public_key.rs +++ b/elliptic-curve/src/public_key.rs @@ -269,7 +269,11 @@ where FieldBytesSize: ModulusSize, { fn from(public_key: &PublicKey) -> CompressedPoint { - CompressedPoint::::clone_from_slice(public_key.to_encoded_point(true).as_bytes()) + public_key + .to_encoded_point(true) + .as_bytes() + .try_into() + .expect("wrong compressed point size") } } diff --git a/elliptic-curve/src/secret_key.rs b/elliptic-curve/src/secret_key.rs index b0a5bd45..87f4b791 100644 --- a/elliptic-curve/src/secret_key.rs +++ b/elliptic-curve/src/secret_key.rs @@ -163,8 +163,8 @@ where /// NOTE: this function is variable-time with respect to the input length. To avoid a timing /// sidechannel, always ensure that the input has been pre-padded to `C::FieldBytesSize`. pub fn from_slice(slice: &[u8]) -> Result { - if slice.len() == C::FieldBytesSize::USIZE { - Self::from_bytes(FieldBytes::::from_slice(slice)) + if let Ok(field_bytes) = <&FieldBytes>::try_from(slice) { + Self::from_bytes(field_bytes) } else if (Self::MIN_SIZE..C::FieldBytesSize::USIZE).contains(&slice.len()) { let mut bytes = Zeroizing::new(FieldBytes::::default()); let offset = C::FieldBytesSize::USIZE.saturating_sub(slice.len()); diff --git a/signature/tests/derive.rs b/signature/tests/derive.rs index da24a21c..a63ece5e 100644 --- a/signature/tests/derive.rs +++ b/signature/tests/derive.rs @@ -35,7 +35,10 @@ impl TryFrom<&[u8]> for DummySignature { type Error = Error; fn try_from(bytes: &[u8]) -> Result { - Ok(DummySignature(Array::clone_from_slice(bytes))) + bytes + .try_into() + .map(DummySignature) + .map_err(|_| Error::new()) } }