X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Finbound_payment.rs;h=2d15876bf95ccad75fb90233b135ffd0fabd17ad;hb=29b9eb3936fa9de3cafffe05506e537d44d2a862;hp=e6668a33cee2d12cf2710a0cab4088523e156ab9;hpb=1cad430e14108710c826adebbfab2a5ea64a6a5a;p=rust-lightning diff --git a/lightning/src/ln/inbound_payment.rs b/lightning/src/ln/inbound_payment.rs index e6668a33..2d15876b 100644 --- a/lightning/src/ln/inbound_payment.rs +++ b/lightning/src/ln/inbound_payment.rs @@ -23,7 +23,7 @@ use crate::util::crypto::hkdf_extract_expand_4x; use crate::util::errors::APIError; use crate::util::logger::Logger; -use core::convert::TryInto; +use core::convert::{TryFrom, TryInto}; use core::ops::Deref; pub(crate) const IV_LEN: usize = 16; @@ -89,8 +89,8 @@ impl ExpandedKey { /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata /// [`Offer::signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey #[allow(unused)] -#[derive(Clone, Copy)] -pub(crate) struct Nonce([u8; Self::LENGTH]); +#[derive(Clone, Copy, Debug, PartialEq)] +pub(crate) struct Nonce(pub(crate) [u8; Self::LENGTH]); impl Nonce { /// Number of bytes in the nonce. @@ -114,6 +114,21 @@ impl Nonce { } } +impl TryFrom<&[u8]> for Nonce { + type Error = (); + + fn try_from(bytes: &[u8]) -> Result { + if bytes.len() != Self::LENGTH { + return Err(()); + } + + let mut copied_bytes = [0u8; Self::LENGTH]; + copied_bytes.copy_from_slice(bytes); + + Ok(Self(copied_bytes)) + } +} + enum Method { LdkPaymentHash = 0, UserPaymentHash = 1,