pub async fn generate_key(
variant: Sha2Variant,
length: Option<u32>,
options: MacKeyOptions,
) -> Result<MacKey, Error>Expand description
Generate a fresh random HMAC key over the declared SHA-2 variant.
length is the key length in bits (WebCrypto’s
HmacKeyGenParams.length, reported back by
mac-key.algorithm-length). none means the underlying hash’s
block size (WebCrypto’s generateKey default: 512 bits for
SHA-256, 1024 for SHA-384/512).
Failure cases:
- a zero
lengthfailserror.invalid-key; - implementations MAY decline lengths that are not a multiple of 8
with
error.unsupported(none of this package’s implementations serve sub-byte lengths); - implementations MAY apply the same policy bounds as
import-key-raw; - an unserved variant fails
error.unsupported.