Skip to content

Commit 8119fbf

Browse files
committed
Add Sha256 HMAC (de)serialization
An HMAC needs to be included in OffersContext::OutboundPayment to authenticate the included PaymentId. Implement Readable and Writeable to allow for this.
1 parent f52bd0b commit 8119fbf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lightning/src/util/ser.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ use bitcoin::script::{self, ScriptBuf};
3333
use bitcoin::transaction::{OutPoint, Transaction, TxOut};
3434
use bitcoin::{consensus, Witness};
3535
use bitcoin::consensus::Encodable;
36+
use bitcoin::hashes::hmac::Hmac;
3637
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
38+
use bitcoin::hashes::sha256::Hash as Sha256;
3739
use bitcoin::hash_types::{Txid, BlockHash};
3840
use core::time::Duration;
3941
use crate::chain::ClaimId;
@@ -1033,6 +1035,21 @@ impl Readable for PartialSignatureWithNonce {
10331035
}
10341036
}
10351037

1038+
impl Writeable for Hmac<Sha256> {
1039+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
1040+
w.write_all(&self[..])
1041+
}
1042+
}
1043+
1044+
impl Readable for Hmac<Sha256> {
1045+
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
1046+
use bitcoin::hashes::Hash;
1047+
1048+
let buf: [u8; 32] = Readable::read(r)?;
1049+
Ok(Hmac::<Sha256>::from_byte_array(buf))
1050+
}
1051+
}
1052+
10361053
impl Writeable for Sha256dHash {
10371054
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
10381055
w.write_all(&self[..])

0 commit comments

Comments
 (0)