diff --git a/src/ecdsa/recovery.rs b/src/ecdsa/recovery.rs index 04aaf3690..0d9a61b4d 100644 --- a/src/ecdsa/recovery.rs +++ b/src/ecdsa/recovery.rs @@ -25,10 +25,10 @@ pub enum RecoveryId { Three, } -impl TryFrom for RecoveryId { - type Error = Error; +impl RecoveryId { + /// Allows library users to create valid recovery IDs from i32. #[inline] - fn try_from(id: i32) -> Result { + pub fn from_i32(id: i32) -> Result { match id { 0 => Ok(RecoveryId::Zero), 1 => Ok(RecoveryId::One), @@ -37,12 +37,11 @@ impl TryFrom for RecoveryId { _ => Err(Error::InvalidRecoveryId), } } -} -impl From 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, @@ -51,6 +50,17 @@ impl From for i32 { } } +impl TryFrom for RecoveryId { + type Error = Error; + #[inline] + fn try_from(id: i32) -> Result { Self::from_i32(id) } +} + +impl From 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);