Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions wrapper/rust/wolfssl-wolfcrypt/src/sha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,26 @@ impl SHA256 {
}
Ok(())
}

}

#[cfg(sha256)]
impl Clone for SHA256 {
/// Clone the SHA-256 state into a new independent instance via `wc_Sha256Copy`.
///
/// Allows the same in-progress computation to be continued independently
/// from the same point, e.g. for transcript snapshotting in TLS.
///
/// # Panics
///
/// Panics if the underlying `wc_Sha256Copy` call fails (should not occur
/// under normal conditions).
fn clone(&self) -> Self {
Comment on lines +648 to +652
let mut dst: core::mem::MaybeUninit<sys::wc_Sha256> = core::mem::MaybeUninit::uninit();
let rc = unsafe { sys::wc_Sha256Copy(&self.wc_sha256 as *const _ as *mut _, dst.as_mut_ptr()) };
assert_eq!(rc, 0, "wc_Sha256Copy failed: {rc}");
SHA256 { wc_sha256: unsafe { dst.assume_init() } }
}
}

#[cfg(sha256)]
Expand Down Expand Up @@ -846,6 +866,26 @@ impl SHA384 {
}
Ok(())
}

}

#[cfg(sha384)]
impl Clone for SHA384 {
/// Clone the SHA-384 state into a new independent instance via `wc_Sha384Copy`.
///
/// Allows the same in-progress computation to be continued independently
/// from the same point, e.g. for transcript snapshotting in TLS.
///
/// # Panics
///
/// Panics if the underlying `wc_Sha384Copy` call fails (should not occur
/// under normal conditions).
fn clone(&self) -> Self {
let mut dst: core::mem::MaybeUninit<sys::wc_Sha384> = core::mem::MaybeUninit::uninit();
let rc = unsafe { sys::wc_Sha384Copy(&self.wc_sha384 as *const _ as *mut _, dst.as_mut_ptr()) };
assert_eq!(rc, 0, "wc_Sha384Copy failed: {rc}");
Comment on lines +881 to +886
SHA384 { wc_sha384: unsafe { dst.assume_init() } }
}
}

#[cfg(sha384)]
Expand Down
Loading