pub struct MacKey { /* private fields */ }Expand description
A MAC key: an unforgeable capability, bound to one algorithm at creation.
sign and verify are one-shot and stateless per call, mirroring
crypto.subtle.sign/verify. The byte stream is the only
ingestion path; the result is chunking-invariant.
Security:
- A closed input stream carries no verdict: an operation computes
correctly over whatever prefix a failed producer delivered. See
README.md, “Streaming contract” (truncating producers).
Callers with several operations in flight must feed and drain them
concurrently, or they can deadlock; see README.md, “Streaming
contract” (making progress, returned streams).
For the meaning of extractable and the getter conventions, see
README.md, “Extractability” and “Getter conventions”.
Implementations§
Source§impl MacKey
impl MacKey
Sourcepub async fn verify(
&self,
data: StreamReader<u8>,
tag: Vec<u8>,
) -> Result<(), Error>
pub async fn verify( &self, data: StreamReader<u8>, tag: Vec<u8>, ) -> Result<(), Error>
Verify tag against the tag computed over an entire byte stream
keyed by this key, in constant time. Both verdicts — ok and
error.authentication-failed — are computed over the entire
stream and resolve only after it is fully drained.
Fails with error.authentication-failed if the tag does not
verify. Returns a result, not a bool: an ignored boolean
fails open, a dropped result does not.
Source§impl MacKey
impl MacKey
Sourcepub fn algorithm_name(&self) -> String
pub fn algorithm_name(&self) -> String
The registry name of the algorithm family this key is bound to,
e.g. "HMAC" (WebCrypto’s KeyAlgorithm.name). The algorithm’s
parameters are separate getters (algorithm-hash,
algorithm-length), so future parameters are new getters rather
than changes to a shared type.
Source§impl MacKey
impl MacKey
Sourcepub fn algorithm_hash(&self) -> Option<String>
pub fn algorithm_hash(&self) -> Option<String>
The registry name of the digest this key’s algorithm is
parameterized over, if any: e.g. "SHA-256" for HMAC-SHA-256
(WebCrypto’s HmacKeyAlgorithm.hash). none for MAC algorithms
not built on a digest.
Source§impl MacKey
impl MacKey
Sourcepub fn algorithm_length(&self) -> u32
pub fn algorithm_length(&self) -> u32
The key length in bits (WebCrypto’s HmacKeyAlgorithm.length).
Source§impl MacKey
impl MacKey
Sourcepub fn can_verify(&self) -> bool
pub fn can_verify(&self) -> bool
Whether this key permits verify. See can-sign.
Source§impl MacKey
impl MacKey
Sourcepub async fn export_key_jwk(&self) -> Result<String, Error>
pub async fn export_key_jwk(&self) -> Result<String, Error>
The key as an RFC 7517 JSON Web Key, behind the same
extractability gate as export-key-raw. See README.md,
“JWK contract”.