Skip to content

Commit 41c53ce

Browse files
authored
ecdsa: use CtOption::into_option (#1031)
Infers types and makes these conversions less ugly
1 parent 18be026 commit 41c53ce

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

ecdsa/src/recovery.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,21 +376,20 @@ where
376376
let z = Scalar::<C>::reduce(&bits2field::<C>(prehash)?);
377377

378378
let r_bytes = if recovery_id.is_x_reduced() {
379-
Option::<C::Uint>::from(
380-
C::Uint::decode_field_bytes(&r.to_repr()).checked_add(&C::ORDER),
381-
)
382-
.ok_or_else(Error::new)?
383-
.encode_field_bytes()
379+
C::Uint::decode_field_bytes(&r.to_repr())
380+
.checked_add(&C::ORDER)
381+
.into_option()
382+
.ok_or_else(Error::new)?
383+
.encode_field_bytes()
384384
} else {
385385
r.to_repr()
386386
};
387387

388-
let R: ProjectivePoint<C> = Option::<AffinePoint<C>>::from(AffinePoint::<C>::decompress(
389-
&r_bytes,
390-
u8::from(recovery_id.is_y_odd()).into(),
391-
))
392-
.ok_or_else(Error::new)?
393-
.into();
388+
let R: ProjectivePoint<C> =
389+
AffinePoint::<C>::decompress(&r_bytes, u8::from(recovery_id.is_y_odd()).into())
390+
.into_option()
391+
.ok_or_else(Error::new)?
392+
.into();
394393

395394
let r_inv = *r.invert();
396395
let u1 = -(r_inv * z);

ecdsa/src/verifying.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ where
108108

109109
/// Initialize [`VerifyingKey`] from an [`EncodedPoint`].
110110
pub fn from_encoded_point(public_key: &EncodedPoint<C>) -> Result<Self> {
111-
Option::from(PublicKey::<C>::from_encoded_point(public_key))
111+
PublicKey::<C>::from_encoded_point(public_key)
112+
.into_option()
112113
.map(|public_key| Self { inner: public_key })
113114
.ok_or_else(Error::new)
114115
}

0 commit comments

Comments
 (0)