Skip to content

Commit 3e9d966

Browse files
committed
f use real fields in resposne
1 parent 5d1a197 commit 3e9d966

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

fuzz/src/invoice_request_deser.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,26 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
8585
let expanded_key = ExpandedKey::new([42; 32]);
8686
let entropy_source = Randomness {};
8787
let nonce = Nonce::from_entropy_source(&entropy_source);
88+
89+
let invoice_request_fields =
90+
if let Ok(ver) = invoice_request.clone().verify_using_metadata(&expanded_key, secp_ctx) {
91+
// Previously we had a panic where we'd truncate the payer note possibly cutting a
92+
// Unicode character in two here, so try to fetch fields if we can validate.
93+
ver.fields()
94+
} else {
95+
InvoiceRequestFields {
96+
payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
97+
quantity: invoice_request.quantity(),
98+
payer_note_truncated: invoice_request
99+
.payer_note()
100+
.map(|s| UntrustedString(s.to_string())),
101+
human_readable_name: None,
102+
}
103+
};
104+
88105
let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
89106
offer_id: OfferId([42; 32]),
90-
invoice_request: InvoiceRequestFields {
91-
payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
92-
quantity: invoice_request.quantity(),
93-
payer_note_truncated: invoice_request
94-
.payer_note()
95-
.map(|s| UntrustedString(s.to_string())),
96-
human_readable_name: None,
97-
},
107+
invoice_request: invoice_request_fields,
98108
});
99109
let payee_tlvs = UnauthenticatedReceiveTlvs {
100110
payment_secret: PaymentSecret([42; 32]),
@@ -134,12 +144,6 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
134144
)
135145
.unwrap();
136146

137-
if let Ok(verified) = invoice_request.clone().verify_using_metadata(&expanded_key, secp_ctx) {
138-
// Previously we had a panic where we'd truncate the payer note possibly cutting a Unicode
139-
// character in two here, so try to fetch fields if we can validate.
140-
let _ = verified.fields();
141-
}
142-
143147
let payment_hash = PaymentHash([42; 32]);
144148
invoice_request.respond_with(vec![payment_path], payment_hash)?.build()
145149
}

0 commit comments

Comments
 (0)