@@ -43,6 +43,9 @@ pub(super) enum Metadata {
43
43
/// Metadata as parsed, supplied by the user, or derived from the message contents.
44
44
Bytes ( Vec < u8 > ) ,
45
45
46
+ /// Metadata for deriving keys included as recipient data in a blinded path.
47
+ Nonce ( Nonce ) ,
48
+
46
49
/// Metadata to be derived from message contents and given material.
47
50
Derived ( MetadataMaterial ) ,
48
51
@@ -54,6 +57,7 @@ impl Metadata {
54
57
pub fn as_bytes ( & self ) -> Option < & Vec < u8 > > {
55
58
match self {
56
59
Metadata :: Bytes ( bytes) => Some ( bytes) ,
60
+ Metadata :: Nonce ( _) => None ,
57
61
Metadata :: Derived ( _) => None ,
58
62
Metadata :: DerivedSigningPubkey ( _) => None ,
59
63
}
@@ -62,6 +66,7 @@ impl Metadata {
62
66
pub fn has_derivation_material ( & self ) -> bool {
63
67
match self {
64
68
Metadata :: Bytes ( _) => false ,
69
+ Metadata :: Nonce ( _) => false ,
65
70
Metadata :: Derived ( _) => true ,
66
71
Metadata :: DerivedSigningPubkey ( _) => true ,
67
72
}
@@ -75,6 +80,7 @@ impl Metadata {
75
80
// derived, as wouldn't be the case if a Metadata::Bytes with length PaymentId::LENGTH +
76
81
// Nonce::LENGTH had been set explicitly.
77
82
Metadata :: Bytes ( bytes) => bytes. len ( ) == PaymentId :: LENGTH + Nonce :: LENGTH ,
83
+ Metadata :: Nonce ( _) => false ,
78
84
Metadata :: Derived ( _) => false ,
79
85
Metadata :: DerivedSigningPubkey ( _) => true ,
80
86
}
@@ -88,6 +94,7 @@ impl Metadata {
88
94
// derived, as wouldn't be the case if a Metadata::Bytes with length Nonce::LENGTH had
89
95
// been set explicitly.
90
96
Metadata :: Bytes ( bytes) => bytes. len ( ) == Nonce :: LENGTH ,
97
+ Metadata :: Nonce ( _) => true ,
91
98
Metadata :: Derived ( _) => false ,
92
99
Metadata :: DerivedSigningPubkey ( _) => true ,
93
100
}
@@ -96,6 +103,7 @@ impl Metadata {
96
103
pub fn without_keys ( self ) -> Self {
97
104
match self {
98
105
Metadata :: Bytes ( _) => self ,
106
+ Metadata :: Nonce ( _) => self ,
99
107
Metadata :: Derived ( _) => self ,
100
108
Metadata :: DerivedSigningPubkey ( material) => Metadata :: Derived ( material) ,
101
109
}
@@ -106,6 +114,7 @@ impl Metadata {
106
114
) -> ( Self , Option < Keypair > ) {
107
115
match self {
108
116
Metadata :: Bytes ( _) => ( self , None ) ,
117
+ Metadata :: Nonce ( _) => ( self , None ) ,
109
118
Metadata :: Derived ( mut metadata_material) => {
110
119
tlv_stream. write ( & mut metadata_material. hmac ) . unwrap ( ) ;
111
120
( Metadata :: Bytes ( metadata_material. derive_metadata ( ) ) , None )
@@ -126,10 +135,22 @@ impl Default for Metadata {
126
135
}
127
136
}
128
137
138
+ impl AsRef < [ u8 ] > for Metadata {
139
+ fn as_ref ( & self ) -> & [ u8 ] {
140
+ match self {
141
+ Metadata :: Bytes ( bytes) => & bytes,
142
+ Metadata :: Nonce ( nonce) => & nonce. 0 ,
143
+ Metadata :: Derived ( _) => & [ ] ,
144
+ Metadata :: DerivedSigningPubkey ( _) => & [ ] ,
145
+ }
146
+ }
147
+ }
148
+
129
149
impl fmt:: Debug for Metadata {
130
150
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
131
151
match self {
132
152
Metadata :: Bytes ( bytes) => bytes. fmt ( f) ,
153
+ Metadata :: Nonce ( Nonce ( bytes) ) => bytes. fmt ( f) ,
133
154
Metadata :: Derived ( _) => f. write_str ( "Derived" ) ,
134
155
Metadata :: DerivedSigningPubkey ( _) => f. write_str ( "DerivedSigningPubkey" ) ,
135
156
}
@@ -145,6 +166,7 @@ impl PartialEq for Metadata {
145
166
} else {
146
167
false
147
168
} ,
169
+ Metadata :: Nonce ( _) => false ,
148
170
Metadata :: Derived ( _) => false ,
149
171
Metadata :: DerivedSigningPubkey ( _) => false ,
150
172
}
0 commit comments