@@ -28,21 +28,6 @@ enum AccountKeyInner {
28
28
}
29
29
30
30
impl AccountKey {
31
- pub fn new ( key : & PKeyRef < Private > ) -> Result < Self , AccountKeyError > {
32
- let inner = match key. id ( ) {
33
- Id :: EC => key. try_into ( ) . map ( AccountKeyInner :: ShaWithEcdsa ) ,
34
- Id :: RSA => key. try_into ( ) . map ( AccountKeyInner :: ShaWithRsa ) ,
35
- id => Err ( NewKeyError :: Algorithm ( id) ) ,
36
- } ?;
37
-
38
- let thumbprint = match inner {
39
- AccountKeyInner :: ShaWithEcdsa ( ref key) => key. thumbprint ( ) ,
40
- AccountKeyInner :: ShaWithRsa ( ref key) => key. thumbprint ( ) ,
41
- } ?;
42
-
43
- Ok ( Self { inner, thumbprint } )
44
- }
45
-
46
31
pub fn thumbprint ( & self ) -> & [ u8 ] {
47
32
self . thumbprint . as_bytes ( )
48
33
}
@@ -77,3 +62,22 @@ impl Serialize for AccountKey {
77
62
}
78
63
}
79
64
}
65
+
66
+ impl TryFrom < & PKeyRef < Private > > for AccountKey {
67
+ type Error = AccountKeyError ;
68
+
69
+ fn try_from ( value : & PKeyRef < Private > ) -> Result < Self , Self :: Error > {
70
+ let inner = match value. id ( ) {
71
+ Id :: EC => value. try_into ( ) . map ( AccountKeyInner :: ShaWithEcdsa ) ,
72
+ Id :: RSA => value. try_into ( ) . map ( AccountKeyInner :: ShaWithRsa ) ,
73
+ id => Err ( NewKeyError :: Algorithm ( id) ) ,
74
+ } ?;
75
+
76
+ let thumbprint = match inner {
77
+ AccountKeyInner :: ShaWithEcdsa ( ref key) => key. thumbprint ( ) ,
78
+ AccountKeyInner :: ShaWithRsa ( ref key) => key. thumbprint ( ) ,
79
+ } ?;
80
+
81
+ Ok ( Self { inner, thumbprint } )
82
+ }
83
+ }
0 commit comments