Skip to content

Commit 252053c

Browse files
committed
Add from_u8_masked RecoveryId constructor
Add an infallible constructor that takes a u8 and masks off the top 6 bits.
1 parent 073e2af commit 252053c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/ecdsa/recovery.rs

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ pub enum RecoveryId {
2525
Three,
2626
}
2727

28+
impl RecoveryId {
29+
/// Creates a `RecoveryId` from a `u8` value by masking off the top 6 bits.
30+
#[inline]
31+
pub const fn from_u8_masked(id: u8) -> RecoveryId {
32+
match id & 0x03 {
33+
0 => RecoveryId::Zero,
34+
1 => RecoveryId::One,
35+
2 => RecoveryId::Two,
36+
_ => RecoveryId::Three,
37+
}
38+
}
39+
}
40+
2841
impl TryFrom<i32> for RecoveryId {
2942
type Error = Error;
3043
#[inline]

0 commit comments

Comments
 (0)