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

source

pub fn create(alg: &str) -> Result<Self, CryptoErrno>

Equivalent to createHash

source

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.

source

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.

source

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.

source

pub fn digest_into(&mut self, buf: impl AsMut<[u8]>) -> Result<(), CryptoErrno>

As same as digest but directly write result to buf

Trait Implementations§

source§

impl Clone for Hash

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Drop for Hash

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.