@@ -29,18 +29,9 @@ impl KeyPurpose for GenericKey {}
29
29
*
30
30
* You don't need to do any crypto, but you might need it to derive subkeys for sub-protocols.
31
31
*/
32
- #[ derive( Debug , Clone , derive_more:: Display , derive_more :: Deref ) ]
32
+ #[ derive( Debug , Clone , derive_more:: Display ) ]
33
33
#[ display( "{:?}" , _0) ]
34
- #[ deref( forward) ]
35
- pub struct Key < P : KeyPurpose > (
36
- #[ deref]
37
- #[ deprecated(
38
- since = "0.7.0" ,
39
- note = "Use the AsRef<Key> implementation to get access to the secretbox key"
40
- ) ]
41
- pub Box < secretbox:: Key > ,
42
- #[ deref( ignore) ] std:: marker:: PhantomData < P > ,
43
- ) ;
34
+ pub struct Key < P : KeyPurpose > ( Box < secretbox:: Key > , std:: marker:: PhantomData < P > ) ;
44
35
45
36
impl Key < WormholeKey > {
46
37
/**
@@ -52,11 +43,7 @@ impl Key<WormholeKey> {
52
43
* The new key is derived with the `"{appid}/transit-key"` purpose.
53
44
*/
54
45
#[ cfg( feature = "transit" ) ]
55
- #[ deprecated(
56
- since = "0.7.0" ,
57
- note = "This will be a private method in the future. Open an issue if you require access to protocol intrinsics in the future"
58
- ) ]
59
- pub fn derive_transit_key ( & self , appid : & AppID ) -> Key < crate :: transit:: TransitKey > {
46
+ pub ( crate ) fn derive_transit_key ( & self , appid : & AppID ) -> Key < crate :: transit:: TransitKey > {
60
47
let transit_purpose = format ! ( "{}/transit-key" , appid) ;
61
48
let derived_key = self . derive_subkey_from_purpose ( & transit_purpose) ;
62
49
tracing:: trace!(
@@ -77,20 +64,32 @@ impl<P: KeyPurpose> Key<P> {
77
64
78
65
/// Encode a key as a hex string
79
66
pub fn to_hex ( & self ) -> String {
80
- hex:: encode ( * * self )
67
+ hex:: encode ( * self . 0 )
81
68
}
82
69
83
70
/**
84
71
* Derive a new sub-key from this one
85
72
*/
86
73
pub fn derive_subkey_from_purpose < NewP : KeyPurpose > ( & self , purpose : & str ) -> Key < NewP > {
87
74
Key (
88
- Box :: new ( derive_key ( self , purpose. as_bytes ( ) ) ) ,
75
+ Box :: new ( derive_key ( & self . 0 , purpose. as_bytes ( ) ) ) ,
89
76
std:: marker:: PhantomData ,
90
77
)
91
78
}
92
79
}
93
80
81
+ impl < P : KeyPurpose > AsRef < secretbox:: Key > for Key < P > {
82
+ fn as_ref ( & self ) -> & secretbox:: Key {
83
+ & self . 0
84
+ }
85
+ }
86
+
87
+ impl < P : KeyPurpose > AsRef < [ u8 ] > for Key < P > {
88
+ fn as_ref ( & self ) -> & [ u8 ] {
89
+ & self . 0 . as_slice ( )
90
+ }
91
+ }
92
+
94
93
#[ derive( Serialize , Deserialize , Debug ) ]
95
94
struct PhaseMessage {
96
95
#[ serde( with = "hex::serde" ) ]
0 commit comments