Skip to content

Commit 4c26091

Browse files
committed
Add a bindings constructor for lightning-invoice's Sha256 wrapper
1 parent 63ea8ea commit 4c26091

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lightning-invoice/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,15 @@ pub enum TaggedField {
455455
pub struct Sha256(/// This is not exported to bindings users as the native hash types are not currently mapped
456456
pub sha256::Hash);
457457

458+
impl Sha256 {
459+
/// Constructs a new [`Sha256`] from the given bytes, which are assumed to be the output of a
460+
/// single sha256 hash.
461+
#[cfg(c_bindings)]
462+
pub fn from_bytes(bytes: &[u8; 32]) -> Self {
463+
Self(sha256::Hash::from_slice(bytes).expect("from_slice only fails if len is not 32"))
464+
}
465+
}
466+
458467
/// Description string
459468
///
460469
/// # Invariants

0 commit comments

Comments
 (0)