From: Matt Corallo Date: Tue, 25 Apr 2023 17:35:24 +0000 (+0000) Subject: Add a bindings constructor for `lightning-invoice`'s `Sha256` wrapper X-Git-Tag: v0.0.116-alpha1~66^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=53c48c1c8f3f2145cff01e96f0912bbf7e4e4537;p=rust-lightning Add a bindings constructor for `lightning-invoice`'s `Sha256` wrapper --- diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 0923fcc17..101051b5e 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -455,6 +455,15 @@ pub enum TaggedField { pub struct Sha256(/// This is not exported to bindings users as the native hash types are not currently mapped pub sha256::Hash); +impl Sha256 { + /// Constructs a new [`Sha256`] from the given bytes, which are assumed to be the output of a + /// single sha256 hash. + #[cfg(c_bindings)] + pub fn from_bytes(bytes: &[u8; 32]) -> Self { + Self(sha256::Hash::from_slice(bytes).expect("from_slice only fails if len is not 32")) + } +} + /// Description string /// /// # Invariants