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
impl Hmac
sourcepub fn create<T>(alg: &str, key: T) -> Result<Self, CryptoErrno>
pub fn create<T>(alg: &str, key: T) -> Result<Self, CryptoErrno>
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
.
sourcepub fn update(&mut self, data: impl AsRef<[u8]>) -> Result<(), CryptoErrno>
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.
sourcepub fn digest(&mut self) -> Result<Vec<u8>, CryptoErrno>
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.
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