pub struct AeadKey { /* private fields */ }Expand description
An AEAD key: an unforgeable capability, bound to one algorithm at
creation. The streaming, extractability, and getter contracts in
README.md apply.
Implementations§
Source§impl AeadKey
impl AeadKey
Sourcepub async fn seal(
&self,
nonce: Vec<u8>,
aad: Vec<u8>,
tag_size: Option<u8>,
plaintext: StreamReader<u8>,
) -> Result<StreamReader<u8>, Error>
pub async fn seal( &self, nonce: Vec<u8>, aad: Vec<u8>, tag_size: Option<u8>, plaintext: StreamReader<u8>, ) -> Result<StreamReader<u8>, Error>
Encrypt and authenticate plaintext under nonce with the
associated data aad. The returned stream carries the
ciphertext followed by the authentication tag (the
crypto.subtle.encrypt wire format).
Security:
- The caller owns nonce uniqueness per key. Nonce reuse defeats the algorithm’s guarantees.
- Short tags weaken the forgery bound. They are opt-in: a
tag-sizeofnoneselects the algorithm’s default (thetag-sizegetter). - The streamed output is not atomic: a producer that fails
after the stream is returned ends it early, and a closed
stream carries no verdict. A consumer that cannot bound the
expected length from its own knowledge of the plaintext must
convey completeness in-band. See
README.md, “Streaming contract”.
The algorithm defines which nonce lengths and tag sizes it
accepts; its minting interface documents both, and the getters’
values are always accepted. A nonce of an unaccepted length
fails error.invalid-nonce; a tag size outside the algorithm’s
set, or one an implementation’s security policy declines, fails
error.unsupported. Callers wanting the standard behavior pass
the getters’ sizes and none, and never need to match on
algorithm-name.
Implementations may produce the output incrementally (tag last)
or buffer and emit it whole. Drain the returned stream
concurrently with feeding plaintext: an incremental producer
may block on unread output before it has taken the whole input.
Source§impl AeadKey
impl AeadKey
Sourcepub async fn open(
&self,
nonce: Vec<u8>,
aad: Vec<u8>,
tag_size: Option<u8>,
ciphertext: StreamReader<u8>,
) -> Result<StreamReader<u8>, Error>
pub async fn open( &self, nonce: Vec<u8>, aad: Vec<u8>, tag_size: Option<u8>, ciphertext: StreamReader<u8>, ) -> Result<StreamReader<u8>, Error>
Decrypt and verify ciphertext (ciphertext followed by a
tag-size-byte tag, as produced by seal) under nonce and
aad. See seal for the nonce and tag-size contracts.
Security:
ok(stream)resolves only after the ciphertext stream is fully drained and the tag verified: it is the authentication statement, and unverified plaintext is never observable.- Fails with
error.authentication-failedif verification fails.
Source§impl AeadKey
impl AeadKey
Sourcepub async fn wrap(
&self,
nonce: Vec<u8>,
aad: Vec<u8>,
tag_size: Option<u8>,
input: WrapInput,
) -> Result<Vec<u8>, Error>
pub async fn wrap( &self, nonce: Vec<u8>, aad: Vec<u8>, tag_size: Option<u8>, input: WrapInput, ) -> Result<Vec<u8>, Error>
Encrypt and authenticate serialized key material under nonce
with the associated data aad, exactly as seal encrypts a
message: the result is ciphertext followed by tag — for
raw-format material, byte-identical to sealing the exported
bytes (the W3C Web Cryptography API’s wrapKey). See seal
for the nonce and tag-size contracts; see the wrapping
interface for the model.
Security:
- The caller owns nonce uniqueness across
sealandwrapalike: both draw on the same key’s nonce space.
input is consumed. Requires can-wrap, else
error.not-permitted.
Source§impl AeadKey
impl AeadKey
Sourcepub async fn unwrap(
&self,
nonce: Vec<u8>,
aad: Vec<u8>,
tag_size: Option<u8>,
wrapped: Vec<u8>,
) -> Result<UnwrapInput, Error>
pub async fn unwrap( &self, nonce: Vec<u8>, aad: Vec<u8>, tag_size: Option<u8>, wrapped: Vec<u8>, ) -> Result<UnwrapInput, Error>
Decrypt and verify wrapped key material, as produced by wrap
(or by seal over the same serialization) under nonce and
aad. See seal for the nonce and tag-size contracts.
The result awaits an unwrap mint (see unwrap-input,
including the verification-timing latitude); the material
never reaches the caller.
Security:
- Verification fails with
error.authentication-failed— here, or at the consuming mint when deferred; no mint succeeds on an unverified input.
Requires can-unwrap, else error.not-permitted.
Source§impl AeadKey
impl AeadKey
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. "AES-GCM" (WebCrypto’s KeyAlgorithm.name). Parameters
are separate getters, as for mac-key.algorithm-name.
Source§impl AeadKey
impl AeadKey
Sourcepub fn algorithm_length(&self) -> u32
pub fn algorithm_length(&self) -> u32
The key length in bits, e.g. 256 for AES-256-GCM (WebCrypto’s
AesKeyAlgorithm.length).
Source§impl AeadKey
impl AeadKey
Sourcepub fn nonce_size(&self) -> u32
pub fn nonce_size(&self) -> u32
The algorithm’s standard nonce size in bytes, e.g. 12 for
AES-GCM. This key’s seal/open always accept it, so a
component granted only the key handle can construct nonces
without matching on algorithm-name. Whether other lengths
are accepted is the algorithm’s contract, documented by its
minting interface.
Source§impl AeadKey
impl AeadKey
Sourcepub fn can_unwrap(&self) -> bool
pub fn can_unwrap(&self) -> bool
Whether this key permits unwrap. See can-wrap.
Source§impl AeadKey
impl AeadKey
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”. Algorithms with no registered JWK form
fail error.unsupported.