mirror of
https://github.com/RustCrypto/signatures
synced 2026-06-21 13:45:42 +00:00
ecdsa: use CtOption::into_option (#1031)
Infers types and makes these conversions less ugly
This commit is contained in:
+10
-11
@@ -376,21 +376,20 @@ where
|
||||
let z = Scalar::<C>::reduce(&bits2field::<C>(prehash)?);
|
||||
|
||||
let r_bytes = if recovery_id.is_x_reduced() {
|
||||
Option::<C::Uint>::from(
|
||||
C::Uint::decode_field_bytes(&r.to_repr()).checked_add(&C::ORDER),
|
||||
)
|
||||
.ok_or_else(Error::new)?
|
||||
.encode_field_bytes()
|
||||
C::Uint::decode_field_bytes(&r.to_repr())
|
||||
.checked_add(&C::ORDER)
|
||||
.into_option()
|
||||
.ok_or_else(Error::new)?
|
||||
.encode_field_bytes()
|
||||
} else {
|
||||
r.to_repr()
|
||||
};
|
||||
|
||||
let R: ProjectivePoint<C> = Option::<AffinePoint<C>>::from(AffinePoint::<C>::decompress(
|
||||
&r_bytes,
|
||||
u8::from(recovery_id.is_y_odd()).into(),
|
||||
))
|
||||
.ok_or_else(Error::new)?
|
||||
.into();
|
||||
let R: ProjectivePoint<C> =
|
||||
AffinePoint::<C>::decompress(&r_bytes, u8::from(recovery_id.is_y_odd()).into())
|
||||
.into_option()
|
||||
.ok_or_else(Error::new)?
|
||||
.into();
|
||||
|
||||
let r_inv = *r.invert();
|
||||
let u1 = -(r_inv * z);
|
||||
|
||||
@@ -108,7 +108,8 @@ where
|
||||
|
||||
/// Initialize [`VerifyingKey`] from an [`EncodedPoint`].
|
||||
pub fn from_encoded_point(public_key: &EncodedPoint<C>) -> Result<Self> {
|
||||
Option::from(PublicKey::<C>::from_encoded_point(public_key))
|
||||
PublicKey::<C>::from_encoded_point(public_key)
|
||||
.into_option()
|
||||
.map(|public_key| Self { inner: public_key })
|
||||
.ok_or_else(Error::new)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user