diff --git a/Cargo.lock b/Cargo.lock index 8180bd50b..079009e4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1269,9 +1269,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" diff --git a/elliptic-curve/Cargo.toml b/elliptic-curve/Cargo.toml index 8efb97d4b..532dfd522 100644 --- a/elliptic-curve/Cargo.toml +++ b/elliptic-curve/Cargo.toml @@ -21,7 +21,7 @@ base16ct = "0.2" crypto-bigint = { version = "=0.6.0-pre.12", default-features = false, features = ["rand_core", "hybrid-array", "zeroize"] } hybrid-array = { version = "0.2.0-rc.8", default-features = false, features = ["zeroize"] } rand_core = { version = "0.6.4", default-features = false } -subtle = { version = "2", default-features = false } +subtle = { version = "2.6", default-features = false } zeroize = { version = "1.7", default-features = false } # optional dependencies diff --git a/elliptic-curve/src/error.rs b/elliptic-curve/src/error.rs index f4463fa4d..ba2d0b368 100644 --- a/elliptic-curve/src/error.rs +++ b/elliptic-curve/src/error.rs @@ -21,6 +21,12 @@ impl From for Error { } } +impl From for Error { + fn from(_: core::array::TryFromSliceError) -> Error { + Error + } +} + #[cfg(feature = "pkcs8")] impl From for Error { fn from(_: pkcs8::Error) -> Error { diff --git a/elliptic-curve/src/point/non_identity.rs b/elliptic-curve/src/point/non_identity.rs index 81c31cd19..436410d7c 100644 --- a/elliptic-curve/src/point/non_identity.rs +++ b/elliptic-curve/src/point/non_identity.rs @@ -188,7 +188,8 @@ where where D: de::Deserializer<'de>, { - Option::from(Self::new(P::deserialize(deserializer)?)) + Self::new(P::deserialize(deserializer)?) + .into_option() .ok_or_else(|| de::Error::custom("expected non-identity point")) } } diff --git a/elliptic-curve/src/public_key.rs b/elliptic-curve/src/public_key.rs index ddad0aa0b..f0490671c 100644 --- a/elliptic-curve/src/public_key.rs +++ b/elliptic-curve/src/public_key.rs @@ -126,7 +126,7 @@ where AffinePoint: FromEncodedPoint + ToEncodedPoint, { let point = EncodedPoint::::from_bytes(bytes).map_err(|_| Error)?; - Option::from(Self::from_encoded_point(&point)).ok_or(Error) + Self::from_encoded_point(&point).into_option().ok_or(Error) } /// Convert this [`PublicKey`] into the diff --git a/elliptic-curve/src/scalar/nonzero.rs b/elliptic-curve/src/scalar/nonzero.rs index 601206ad0..dfcd2e776 100644 --- a/elliptic-curve/src/scalar/nonzero.rs +++ b/elliptic-curve/src/scalar/nonzero.rs @@ -13,7 +13,6 @@ use core::{ }; use crypto_bigint::{ArrayEncoding, Integer}; use ff::{Field, PrimeField}; -use hybrid_array::{typenum::Unsigned, Array}; use rand_core::CryptoRngCore; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; use zeroize::Zeroize; @@ -287,11 +286,9 @@ where type Error = Error; fn try_from(bytes: &[u8]) -> Result { - if bytes.len() == C::FieldBytesSize::USIZE { - Option::from(NonZeroScalar::from_repr(Array::clone_from_slice(bytes))).ok_or(Error) - } else { - Err(Error) - } + NonZeroScalar::from_repr(bytes.try_into()?) + .into_option() + .ok_or(Error) } } @@ -346,7 +343,7 @@ where let mut bytes = FieldBytes::::default(); if base16ct::mixed::decode(hex, &mut bytes)?.len() == bytes.len() { - Option::from(Self::from_repr(bytes)).ok_or(Error) + Self::from_repr(bytes).into_option().ok_or(Error) } else { Err(Error) } @@ -376,7 +373,8 @@ where D: de::Deserializer<'de>, { let scalar = ScalarPrimitive::deserialize(deserializer)?; - Option::from(Self::new(scalar.into())) + Self::new(scalar.into()) + .into_option() .ok_or_else(|| de::Error::custom("expected non-zero scalar")) } } diff --git a/elliptic-curve/src/scalar/primitive.rs b/elliptic-curve/src/scalar/primitive.rs index 877bacb61..a4d31cb3e 100644 --- a/elliptic-curve/src/scalar/primitive.rs +++ b/elliptic-curve/src/scalar/primitive.rs @@ -84,7 +84,7 @@ where /// Decode [`ScalarPrimitive`] from a big endian byte slice. pub fn from_slice(slice: &[u8]) -> Result { let bytes = Array::try_from(slice).map_err(|_| Error)?; - Option::from(Self::from_bytes(&bytes)).ok_or(Error) + Self::from_bytes(&bytes).into_option().ok_or(Error) } /// Borrow the inner `C::Uint`. diff --git a/elliptic-curve/src/secret_key.rs b/elliptic-curve/src/secret_key.rs index 02ba9d092..b0a5bd458 100644 --- a/elliptic-curve/src/secret_key.rs +++ b/elliptic-curve/src/secret_key.rs @@ -142,8 +142,9 @@ where /// Deserialize secret key from an encoded secret scalar. pub fn from_bytes(bytes: &FieldBytes) -> Result { - let inner: ScalarPrimitive = - Option::from(ScalarPrimitive::from_bytes(bytes)).ok_or(Error)?; + let inner = ScalarPrimitive::::from_bytes(bytes) + .into_option() + .ok_or(Error)?; if inner.is_zero().into() { return Err(Error);