@@ -25,10 +25,10 @@ pub enum RecoveryId {
25
25
Three ,
26
26
}
27
27
28
- impl TryFrom < i32 > for RecoveryId {
29
- type Error = Error ;
28
+ impl RecoveryId {
29
+ /// Allows library users to create valid recovery IDs from i32.
30
30
#[ inline]
31
- fn try_from ( id : i32 ) -> Result < RecoveryId , Error > {
31
+ pub fn from_i32 ( id : i32 ) -> Result < Self , Error > {
32
32
match id {
33
33
0 => Ok ( RecoveryId :: Zero ) ,
34
34
1 => Ok ( RecoveryId :: One ) ,
@@ -37,12 +37,11 @@ impl TryFrom<i32> for RecoveryId {
37
37
_ => Err ( Error :: InvalidRecoveryId ) ,
38
38
}
39
39
}
40
- }
41
40
42
- impl From < RecoveryId > for i32 {
41
+ /// Allows library users to convert recovery IDs to i32.
43
42
#[ inline]
44
- fn from ( val : RecoveryId ) -> Self {
45
- match val {
43
+ pub fn to_i32 ( self ) -> i32 {
44
+ match self {
46
45
RecoveryId :: Zero => 0 ,
47
46
RecoveryId :: One => 1 ,
48
47
RecoveryId :: Two => 2 ,
@@ -51,6 +50,17 @@ impl From<RecoveryId> for i32 {
51
50
}
52
51
}
53
52
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
+
54
64
/// An ECDSA signature with a recovery ID for pubkey recovery.
55
65
#[ derive( Copy , Clone , PartialEq , Eq , Debug , Hash , Ord , PartialOrd ) ]
56
66
pub struct RecoverableSignature ( ffi:: RecoverableSignature ) ;
0 commit comments