]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Use `[u8; 32]` rather than `Hmac<Sha256>` for simplicity
authorMatt Corallo <git@bluematt.me>
Mon, 26 Aug 2024 18:28:50 +0000 (18:28 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 3 Sep 2024 14:00:24 +0000 (14:00 +0000)
Mapping an `Hmac<Sha256>` would require somewhat custom logic as
we'd have to behave differently based on generic parameters, so its
simplest to just swap it to a `[u8; 32]` instead.

lightning/src/blinded_path/message.rs
lightning/src/ln/channelmanager.rs

index e3899b50edbb822ce66b17c82626d84b219c1c55..0651877750c732591ec994e79c08def1acdb365e 100644 (file)
@@ -334,7 +334,7 @@ pub enum OffersContext {
                /// used with an [`InvoiceError`].
                ///
                /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
-               hmac: Option<Hmac<Sha256>>,
+               hmac: Option<[u8; 32]>,
        },
        /// Context used by a [`BlindedMessagePath`] as a reply path for a [`Bolt12Invoice`].
        ///
index eccffa5d39b2c59824d0449859601d1f0ef07ab5..cc84185e14c75ce09545d95161a6ffc21a427a05 100644 (file)
@@ -9081,7 +9081,7 @@ where
                let invoice_request = builder.build_and_sign()?;
 
                let hmac = payment_id.hmac_for_offer_payment(nonce, expanded_key);
-               let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) };
+               let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac.to_byte_array()) };
                let reply_paths = self.create_blinded_paths(context)
                        .map_err(|_| Bolt12SemanticError::MissingPaths)?;
 
@@ -10956,7 +10956,7 @@ where
 
                                match context {
                                        Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
-                                               if let Ok(()) = payment_id.verify(hmac, nonce, expanded_key) {
+                                               if let Ok(()) = payment_id.verify(bitcoin::hashes::hmac::Hmac::from_byte_array(hmac), nonce, expanded_key) {
                                                        self.abandon_payment_with_reason(
                                                                payment_id, PaymentFailureReason::InvoiceRequestRejected,
                                                        );