Skip to content

Commit 9f2bbff

Browse files
committed
chore: add back to/from i32 fns
1 parent 2bfda46 commit 9f2bbff

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/ecdsa/recovery.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ pub enum RecoveryId {
2525
Three,
2626
}
2727

28-
impl TryFrom<i32> for RecoveryId {
29-
type Error = Error;
28+
impl RecoveryId {
29+
/// Allows library users to create valid recovery IDs from i32.
3030
#[inline]
31-
fn try_from(id: i32) -> Result<RecoveryId, Error> {
31+
pub fn from_i32(id: i32) -> Result<Self, Error> {
3232
match id {
3333
0 => Ok(RecoveryId::Zero),
3434
1 => Ok(RecoveryId::One),
@@ -37,12 +37,11 @@ impl TryFrom<i32> for RecoveryId {
3737
_ => Err(Error::InvalidRecoveryId),
3838
}
3939
}
40-
}
4140

42-
impl From<RecoveryId> for i32 {
41+
/// Allows library users to convert recovery IDs to i32.
4342
#[inline]
44-
fn from(val: RecoveryId) -> Self {
45-
match val {
43+
pub fn to_i32(self) -> i32 {
44+
match self {
4645
RecoveryId::Zero => 0,
4746
RecoveryId::One => 1,
4847
RecoveryId::Two => 2,
@@ -51,6 +50,17 @@ impl From<RecoveryId> for i32 {
5150
}
5251
}
5352

53+
impl TryFrom<i32> for RecoveryId {
54+
type Error = Error;
55+
#[inline]
56+
fn try_from(id: i32) -> Result<RecoveryId, Error> { Self::from_i32(id) }
57+
}
58+
59+
impl From<RecoveryId> for i32 {
60+
#[inline]
61+
fn from(val: RecoveryId) -> Self { val.to_i32() }
62+
}
63+
5464
/// An ECDSA signature with a recovery ID for pubkey recovery.
5565
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
5666
pub struct RecoverableSignature(ffi::RecoverableSignature);

0 commit comments

Comments
 (0)