Skip to content

Commit fed623e

Browse files
committed
Implement From on u8 for RecoveryId instead of i32
The `i32` is a hangover from before #743, now we have a nice enum and a `from_u8_masked` constructor (along with a `to_u8` getter) lets make the `From<RecoveryId>` impl be on `u8` instead of on `i32`.
1 parent 9b4fa8b commit fed623e

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

examples/sign_verify_recovery.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,5 @@ fn main() {
4747

4848
let (recovery_id, serialize_sig) = signature.serialize_compact();
4949

50-
assert_eq!(
51-
recover(&secp, msg, serialize_sig, Into::<i32>::into(recovery_id) as u8),
52-
Ok(pubkey)
53-
);
50+
assert_eq!(recover(&secp, msg, serialize_sig, recovery_id.to_u8()), Ok(pubkey));
5451
}

src/ecdsa/recovery.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl TryFrom<i32> for RecoveryId {
6262
}
6363
}
6464

65-
impl From<RecoveryId> for i32 {
65+
impl From<RecoveryId> for u8 {
6666
#[inline]
6767
fn from(val: RecoveryId) -> Self {
6868
match val {
@@ -96,7 +96,7 @@ impl RecoverableSignature {
9696
super_ffi::secp256k1_context_no_precomp,
9797
&mut ret,
9898
data.as_c_ptr(),
99-
recid.into(),
99+
i32::from(recid.to_u8()),
100100
) == 1
101101
{
102102
Ok(RecoverableSignature(ret))
@@ -123,7 +123,7 @@ impl RecoverableSignature {
123123
/// Serializes the recoverable signature in compact format.
124124
pub fn serialize_compact(&self) -> (RecoveryId, [u8; 64]) {
125125
let mut ret = [0u8; 64];
126-
let mut recid = RecoveryId::Zero.into();
126+
let mut recid = i32::from(RecoveryId::Zero.to_u8());
127127
unsafe {
128128
let err = ffi::secp256k1_ecdsa_recoverable_signature_serialize_compact(
129129
super_ffi::secp256k1_context_no_precomp,
@@ -461,9 +461,9 @@ mod tests {
461461
assert!(RecoveryId::try_from(3i32).is_ok());
462462
assert!(RecoveryId::try_from(4i32).is_err());
463463
let id0 = RecoveryId::Zero;
464-
assert_eq!(Into::<i32>::into(id0), 0i32);
464+
assert_eq!(Into::<u8>::into(id0), 0u8);
465465
let id1 = RecoveryId::One;
466-
assert_eq!(Into::<i32>::into(id1), 1i32);
466+
assert_eq!(Into::<u8>::into(id1), 1u8);
467467
}
468468
}
469469

0 commit comments

Comments
 (0)