Skip to content

Commit 4a93699

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 7b5e94a commit 4a93699

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
@@ -847,7 +847,7 @@ impl Bolt12Invoice {
847847
(&refund.payer.0, REFUND_IV_BYTES_WITH_METADATA)
848848
},
849849
};
850-
self.contents.verify(TlvStream::new(&self.bytes), metadata, key, iv_bytes, secp_ctx)
850+
self.contents.verify(&self.bytes, metadata, key, iv_bytes, secp_ctx)
851851
}
852852

853853
/// Verifies that the invoice was for a request or refund created using the given key by
@@ -861,7 +861,8 @@ impl Bolt12Invoice {
861861
InvoiceContents::ForOffer { .. } => INVOICE_REQUEST_IV_BYTES,
862862
InvoiceContents::ForRefund { .. } => REFUND_IV_BYTES_WITHOUT_METADATA,
863863
};
864-
self.contents.verify(TlvStream::new(&self.bytes), &metadata, key, iv_bytes, secp_ctx)
864+
self.contents
865+
.verify(&self.bytes, &metadata, key, iv_bytes, secp_ctx)
865866
.and_then(|extracted_payment_id| (payment_id == extracted_payment_id)
866867
.then(|| payment_id)
867868
.ok_or(())
@@ -1105,11 +1106,11 @@ impl InvoiceContents {
11051106
}
11061107

11071108
fn verify<T: secp256k1::Signing>(
1108-
&self, tlv_stream: TlvStream<'_>, metadata: &Metadata, key: &ExpandedKey,
1109-
iv_bytes: &[u8; IV_LEN], secp_ctx: &Secp256k1<T>
1109+
&self, bytes: &[u8], metadata: &Metadata, key: &ExpandedKey, iv_bytes: &[u8; IV_LEN],
1110+
secp_ctx: &Secp256k1<T>
11101111
) -> Result<PaymentId, ()> {
1111-
let offer_records = tlv_stream.clone().range(OFFER_TYPES);
1112-
let invreq_records = tlv_stream.range(INVOICE_REQUEST_TYPES).filter(|record| {
1112+
let offer_records = TlvStream::new(bytes).range(OFFER_TYPES);
1113+
let invreq_records = TlvStream::new(bytes).range(INVOICE_REQUEST_TYPES).filter(|record| {
11131114
match record.r#type {
11141115
PAYER_METADATA_TYPE => false, // Should be outside range
11151116
INVOICE_REQUEST_PAYER_ID_TYPE => !metadata.derives_payer_keys(),

0 commit comments

Comments
 (0)