Skip to content

Commit e66bd11

Browse files
committed
Merge #778: Add from_u8_masked RecoveryId constructor
252053c Add `from_u8_masked` `RecoveryId` constructor (Jamil Lambert, PhD) Pull request description: Add an infallible constructor that takes a u8 and masks off the top 6 bits. Mentioned in rust-bitcoin/rust-bitcoin#3965 ACKs for top commit: tcharding: ACK 252053c Kixunil: ACK 252053c apoelstra: ACK 252053c; successfully ran local tests Tree-SHA512: 698b5289358e39c9cf3137d5291dc08de9bc65c0d36aaad839b9e00e1414a72901c02dd101354422019f9fe396c8c7c4e28465ba38700e67a790c9fa29bd682b
2 parents b7e8ba7 + 252053c commit e66bd11

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)