Struct crypto_wasi::Hash
source · pub struct Hash { /* private fields */ }
Expand description
Equivalent to crypto.Hash
Example:
use crate::Hash;
let mut h = Hash::create("sha256")?;
h.update("abc")?;
h.update("def")?;
let res = h.digest()?;
Supported algorithm:
- SHA-256
- SHA-512
- SHA-512/256
Implementations§
source§impl Hash
impl Hash
sourcepub fn create(alg: &str) -> Result<Self, CryptoErrno>
pub fn create(alg: &str) -> Result<Self, CryptoErrno>
Equivalent to createHash
sourcepub fn update(&mut self, data: impl AsRef<[u8]>) -> Result<(), CryptoErrno>
pub fn update(&mut self, data: impl AsRef<[u8]>) -> Result<(), CryptoErrno>
Updates the Hash
content with the given data
.
This can be called many times with new data as it is streamed.
sourcepub fn copy(&self) -> Result<Self, CryptoErrno>
pub fn copy(&self) -> Result<Self, CryptoErrno>
Creates a new Hash
object that contains a deep copy of the internal state of the current Hash
object.
sourcepub fn digest(&mut self) -> Result<Vec<u8>, CryptoErrno>
pub fn digest(&mut self) -> Result<Vec<u8>, CryptoErrno>
Calculates the HASH digest of all of the data passed using update
.
The Hash
object SHOULD NOT be used again after digest
has been called.
Unlike nodejs, you can still call update
to append content and digest
to compute for all content actually in WasmEdge’s implementation,
but it’s NOT RECOMMENDED.
sourcepub fn digest_into(&mut self, buf: impl AsMut<[u8]>) -> Result<(), CryptoErrno>
pub fn digest_into(&mut self, buf: impl AsMut<[u8]>) -> Result<(), CryptoErrno>
As same as digest
but directly write result to buf
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Hash
impl Send for Hash
impl Sync for Hash
impl Unpin for Hash
impl UnwindSafe for Hash
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more