Skip to main content

AeadKey

Struct AeadKey 

Source
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

Source

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-size of none selects the algorithm’s default (the tag-size getter).
  • 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

Source

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-failed if verification fails.
Source§

impl AeadKey

Source

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 seal and wrap alike: both draw on the same key’s nonce space.

input is consumed. Requires can-wrap, else error.not-permitted.

Source§

impl AeadKey

Source

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

Source

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

Source

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

Source

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

Source

pub fn tag_size(&self) -> u32

The algorithm’s default tag size in bytes, e.g. 16: what a tag-size of none selects, and the framing arithmetic for default-tag messages (sealed length = plaintext length + tag-size).

Source§

impl AeadKey

Source

pub fn extractable(&self) -> bool

Whether the key material may be exported.

Source§

impl AeadKey

Source

pub fn can_seal(&self) -> bool

Whether this key permits seal. A refused operation fails error.not-permitted.

Source§

impl AeadKey

Source

pub fn can_open(&self) -> bool

Whether this key permits open. See can-seal.

Source§

impl AeadKey

Source

pub fn can_wrap(&self) -> bool

Whether this key permits wrap. A refused operation fails error.not-permitted.

Source§

impl AeadKey

Source

pub fn can_unwrap(&self) -> bool

Whether this key permits unwrap. See can-wrap.

Source§

impl AeadKey

Source

pub async fn export_key_raw(&self) -> Result<Vec<u8>, Error>

The raw key material. Fails with error.not-extractable unless the key was created with extractable true.

Source§

impl AeadKey

Source

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.

Source§

impl AeadKey

Source

pub async fn to_wrap_input_raw(&self) -> Result<WrapInput, Error>

This key’s raw material as a wrap-input, for wrapping under another key (see the wrapping interface). Behind the same extractability gate as export-key-raw; the material itself never reaches the caller.

Source§

impl AeadKey

Source

pub async fn to_wrap_input_jwk(&self) -> Result<WrapInput, Error>

The JWK serialization as a wrap-input, behind the same gate; algorithms with no registered JWK form fail error.unsupported, as on export-key-jwk.

Trait Implementations§

Source§

impl Debug for AeadKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<AeadKey> for Aead

Source§

fn from(raw: AeadKey) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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.

§

impl<T> Resource for T
where T: 'static,

§

type Rep = Option<T>

The type which is actually stored in-memory for this resource. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.