Skip to content

Commit

Permalink
chore: add back to/from i32 fns
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Nov 20, 2024
1 parent 2bfda46 commit 9f2bbff
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/ecdsa/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ pub enum RecoveryId {
Three,
}

impl TryFrom<i32> for RecoveryId {
type Error = Error;
impl RecoveryId {
/// Allows library users to create valid recovery IDs from i32.
#[inline]
fn try_from(id: i32) -> Result<RecoveryId, Error> {
pub fn from_i32(id: i32) -> Result<Self, Error> {
match id {
0 => Ok(RecoveryId::Zero),
1 => Ok(RecoveryId::One),
Expand All @@ -37,12 +37,11 @@ impl TryFrom<i32> for RecoveryId {
_ => Err(Error::InvalidRecoveryId),
}
}
}

impl From<RecoveryId> for i32 {
/// Allows library users to convert recovery IDs to i32.
#[inline]
fn from(val: RecoveryId) -> Self {
match val {
pub fn to_i32(self) -> i32 {
match self {
RecoveryId::Zero => 0,
RecoveryId::One => 1,
RecoveryId::Two => 2,
Expand All @@ -51,6 +50,17 @@ impl From<RecoveryId> for i32 {
}
}

impl TryFrom<i32> for RecoveryId {
type Error = Error;
#[inline]
fn try_from(id: i32) -> Result<RecoveryId, Error> { Self::from_i32(id) }
}

impl From<RecoveryId> for i32 {
#[inline]
fn from(val: RecoveryId) -> Self { val.to_i32() }
}

/// An ECDSA signature with a recovery ID for pubkey recovery.
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
pub struct RecoverableSignature(ffi::RecoverableSignature);
Expand Down

0 comments on commit 9f2bbff

Please sign in to comment.