Skip to content

Commit 63c687f

Browse files
committed
Pass bytes instead of TlvStream to verify
Passing bytes directly to InvoiceContents::verify improves readability as then a TlvStream for each TLV record range can be created from the bytes instead of needing to clone the TlvStream upfront. In an upcoming commit, the experimental TLV record range will utilize this.
1 parent 1eb5baa commit 63c687f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lightning/src/offers/invoice.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ impl Bolt12Invoice {
878878
(&refund.payer.0, REFUND_IV_BYTES_WITH_METADATA)
879879
},
880880
};
881-
self.contents.verify(TlvStream::new(&self.bytes), metadata, key, iv_bytes, secp_ctx)
881+
self.contents.verify(&self.bytes, metadata, key, iv_bytes, secp_ctx)
882882
}
883883

884884
/// Verifies that the invoice was for a request or refund created using the given key by
@@ -892,7 +892,8 @@ impl Bolt12Invoice {
892892
InvoiceContents::ForOffer { .. } => INVOICE_REQUEST_IV_BYTES,
893893
InvoiceContents::ForRefund { .. } => REFUND_IV_BYTES_WITHOUT_METADATA,
894894
};
895-
self.contents.verify(TlvStream::new(&self.bytes), &metadata, key, iv_bytes, secp_ctx)
895+
self.contents
896+
.verify(&self.bytes, &metadata, key, iv_bytes, secp_ctx)
896897
.and_then(|extracted_payment_id| (payment_id == extracted_payment_id)
897898
.then(|| payment_id)
898899
.ok_or(())
@@ -1143,11 +1144,11 @@ impl InvoiceContents {
11431144
}
11441145

11451146
fn verify<T: secp256k1::Signing>(
1146-
&self, tlv_stream: TlvStream<'_>, metadata: &Metadata, key: &ExpandedKey,
1147-
iv_bytes: &[u8; IV_LEN], secp_ctx: &Secp256k1<T>
1147+
&self, bytes: &[u8], metadata: &Metadata, key: &ExpandedKey, iv_bytes: &[u8; IV_LEN],
1148+
secp_ctx: &Secp256k1<T>
11481149
) -> Result<PaymentId, ()> {
1149-
let offer_records = tlv_stream.clone().range(OFFER_TYPES);
1150-
let invreq_records = tlv_stream.range(INVOICE_REQUEST_TYPES).filter(|record| {
1150+
let offer_records = TlvStream::new(bytes).range(OFFER_TYPES);
1151+
let invreq_records = TlvStream::new(bytes).range(INVOICE_REQUEST_TYPES).filter(|record| {
11511152
match record.r#type {
11521153
PAYER_METADATA_TYPE => false, // Should be outside range
11531154
INVOICE_REQUEST_PAYER_ID_TYPE => !metadata.derives_payer_keys(),

0 commit comments

Comments
 (0)