Struct crypto_wasi::Hmac

source ·
pub struct Hmac { /* private fields */ }
Expand description

Equivalent to crypto.Hmac

Example:

use crate::Hmac;

let mut h = Hmac::create("sha256", "key")?;
h.update("abc")?;
h.update("def")?;
let res = h.digest()?;

Supported algorithm:

  • HMAC/SHA-256
  • HMAC/SHA-512

Implementations§

source§

impl Hmac

source

pub fn create<T>(alg: &str, key: T) -> Result<Self, CryptoErrno>
where T: AsRef<[u8]>,

Equivalent to createHmac

In nodejs, the key argument can pass a KeyObject. While in nodejs, SecretKey is just store the raw key data. In wasi-crypto, SymmetricKey is equivalent to SecretKey, which is also just store the raw key data in WasmEdge’s implementation. But in wasi-crypto, each key is required to be bound to a kind of algorithms, which cause some complications when managing keys and reusing keys. So we’re not going to implement SecretKey.

source

pub fn update(&mut self, data: impl AsRef<[u8]>) -> Result<(), CryptoErrno>

Updates the Hmac content with the given data. This can be called many times with new data as it is streamed.

source

pub fn digest(&mut self) -> Result<Vec<u8>, CryptoErrno>

Calculates the HMAC digest of all of the data passed using update. The Hmac 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 Drop for Hmac

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Hmac

§

impl Send for Hmac

§

impl Sync for Hmac

§

impl Unpin for Hmac

§

impl UnwindSafe for Hmac

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, 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.