Skip to content

Commit 4364faa

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 13e75ac commit 4364faa

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::blockdata::script::{self, ScriptBuf};
3333
use bitcoin::blockdata::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;
@@ -1021,6 +1023,21 @@ impl Readable for PartialSignatureWithNonce {
10211023
}
10221024
}
10231025

1026+
impl Writeable for Hmac<Sha256> {
1027+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
1028+
w.write_all(&self[..])
1029+
}
1030+
}
1031+
1032+
impl Readable for Hmac<Sha256> {
1033+
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
1034+
use bitcoin::hashes::Hash;
1035+
1036+
let buf: [u8; 32] = Readable::read(r)?;
1037+
Ok(Hmac::<Sha256>::from_byte_array(buf))
1038+
}
1039+
}
1040+
10241041
impl Writeable for Sha256dHash {
10251042
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
10261043
w.write_all(&self[..])

0 commit comments

Comments
 (0)