@@ -43,6 +43,9 @@ pub(super) enum Metadata {
4343 /// Metadata as parsed, supplied by the user, or derived from the message contents.
4444 Bytes ( Vec < u8 > ) ,
4545
46+ /// Metadata for deriving keys included as recipient data in a blinded path.
47+ Nonce ( Nonce ) ,
48+
4649 /// Metadata to be derived from message contents and given material.
4750 Derived ( MetadataMaterial ) ,
4851
@@ -54,6 +57,7 @@ impl Metadata {
5457 pub fn as_bytes ( & self ) -> Option < & Vec < u8 > > {
5558 match self {
5659 Metadata :: Bytes ( bytes) => Some ( bytes) ,
60+ Metadata :: Nonce ( _) => None ,
5761 Metadata :: Derived ( _) => None ,
5862 Metadata :: DerivedSigningPubkey ( _) => None ,
5963 }
@@ -62,6 +66,7 @@ impl Metadata {
6266 pub fn has_derivation_material ( & self ) -> bool {
6367 match self {
6468 Metadata :: Bytes ( _) => false ,
69+ Metadata :: Nonce ( _) => false ,
6570 Metadata :: Derived ( _) => true ,
6671 Metadata :: DerivedSigningPubkey ( _) => true ,
6772 }
@@ -75,6 +80,7 @@ impl Metadata {
7580 // derived, as wouldn't be the case if a Metadata::Bytes with length PaymentId::LENGTH +
7681 // Nonce::LENGTH had been set explicitly.
7782 Metadata :: Bytes ( bytes) => bytes. len ( ) == PaymentId :: LENGTH + Nonce :: LENGTH ,
83+ Metadata :: Nonce ( _) => false ,
7884 Metadata :: Derived ( _) => false ,
7985 Metadata :: DerivedSigningPubkey ( _) => true ,
8086 }
@@ -88,6 +94,7 @@ impl Metadata {
8894 // derived, as wouldn't be the case if a Metadata::Bytes with length Nonce::LENGTH had
8995 // been set explicitly.
9096 Metadata :: Bytes ( bytes) => bytes. len ( ) == Nonce :: LENGTH ,
97+ Metadata :: Nonce ( _) => true ,
9198 Metadata :: Derived ( _) => false ,
9299 Metadata :: DerivedSigningPubkey ( _) => true ,
93100 }
@@ -96,6 +103,7 @@ impl Metadata {
96103 pub fn without_keys ( self ) -> Self {
97104 match self {
98105 Metadata :: Bytes ( _) => self ,
106+ Metadata :: Nonce ( _) => self ,
99107 Metadata :: Derived ( _) => self ,
100108 Metadata :: DerivedSigningPubkey ( material) => Metadata :: Derived ( material) ,
101109 }
@@ -106,6 +114,7 @@ impl Metadata {
106114 ) -> ( Self , Option < Keypair > ) {
107115 match self {
108116 Metadata :: Bytes ( _) => ( self , None ) ,
117+ Metadata :: Nonce ( _) => ( self , None ) ,
109118 Metadata :: Derived ( mut metadata_material) => {
110119 tlv_stream. write ( & mut metadata_material. hmac ) . unwrap ( ) ;
111120 ( Metadata :: Bytes ( metadata_material. derive_metadata ( ) ) , None )
@@ -126,10 +135,22 @@ impl Default for Metadata {
126135 }
127136}
128137
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+
129149impl fmt:: Debug for Metadata {
130150 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
131151 match self {
132152 Metadata :: Bytes ( bytes) => bytes. fmt ( f) ,
153+ Metadata :: Nonce ( Nonce ( bytes) ) => bytes. fmt ( f) ,
133154 Metadata :: Derived ( _) => f. write_str ( "Derived" ) ,
134155 Metadata :: DerivedSigningPubkey ( _) => f. write_str ( "DerivedSigningPubkey" ) ,
135156 }
@@ -145,6 +166,7 @@ impl PartialEq for Metadata {
145166 } else {
146167 false
147168 } ,
169+ Metadata :: Nonce ( _) => false ,
148170 Metadata :: Derived ( _) => false ,
149171 Metadata :: DerivedSigningPubkey ( _) => false ,
150172 }
0 commit comments