Skip to main content

HostAeadKeyWithStore

Trait HostAeadKeyWithStore 

Source
pub trait HostAeadKeyWithStore<T>: HasData + Send {
    // Required methods
    fn drop(
        accessor: &Accessor<T, Self>,
        rep: Resource<AeadKey>,
    ) -> impl Future<Output = Result<()>> + Send
       where Self: Sized;
    fn seal(
        accessor: &Accessor<T, Self>,
        self_: Resource<AeadKey>,
        nonce: Vec<u8>,
        aad: Vec<u8>,
        tag_size: Option<u8>,
        plaintext: StreamReader<u8>,
    ) -> impl Future<Output = Result<Result<StreamReader<u8>, Error>>> + Send;
    fn open(
        accessor: &Accessor<T, Self>,
        self_: Resource<AeadKey>,
        nonce: Vec<u8>,
        aad: Vec<u8>,
        tag_size: Option<u8>,
        ciphertext: StreamReader<u8>,
    ) -> impl Future<Output = Result<Result<StreamReader<u8>, Error>>> + Send;
    fn wrap(
        accessor: &Accessor<T, Self>,
        self_: Resource<AeadKey>,
        nonce: Vec<u8>,
        aad: Vec<u8>,
        tag_size: Option<u8>,
        input: Resource<WrapInput>,
    ) -> impl Future<Output = Result<Result<Vec<u8>, Error>>> + Send;
    fn unwrap(
        accessor: &Accessor<T, Self>,
        self_: Resource<AeadKey>,
        nonce: Vec<u8>,
        aad: Vec<u8>,
        tag_size: Option<u8>,
        wrapped: Vec<u8>,
    ) -> impl Future<Output = Result<Result<Resource<UnwrapInput>, Error>>> + Send;
    fn export_key_raw(
        accessor: &Accessor<T, Self>,
        self_: Resource<AeadKey>,
    ) -> impl Future<Output = Result<Result<Vec<u8>, Error>>> + Send;
    fn export_key_jwk(
        accessor: &Accessor<T, Self>,
        self_: Resource<AeadKey>,
    ) -> impl Future<Output = Result<Result<String, Error>>> + Send;
    fn to_wrap_input_raw(
        accessor: &Accessor<T, Self>,
        self_: Resource<AeadKey>,
    ) -> impl Future<Output = Result<Result<Resource<WrapInput>, Error>>> + Send;
    fn to_wrap_input_jwk(
        accessor: &Accessor<T, Self>,
        self_: Resource<AeadKey>,
    ) -> impl Future<Output = Result<Result<Resource<WrapInput>, Error>>> + Send;
}

Required Methods§

Source

fn drop( accessor: &Accessor<T, Self>, rep: Resource<AeadKey>, ) -> impl Future<Output = Result<()>> + Send
where Self: Sized,

Source

fn seal( accessor: &Accessor<T, Self>, self_: Resource<AeadKey>, nonce: Vec<u8>, aad: Vec<u8>, tag_size: Option<u8>, plaintext: StreamReader<u8>, ) -> impl Future<Output = Result<Result<StreamReader<u8>, Error>>> + Send

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

fn open( accessor: &Accessor<T, Self>, self_: Resource<AeadKey>, nonce: Vec<u8>, aad: Vec<u8>, tag_size: Option<u8>, ciphertext: StreamReader<u8>, ) -> impl Future<Output = Result<Result<StreamReader<u8>, Error>>> + Send

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

fn wrap( accessor: &Accessor<T, Self>, self_: Resource<AeadKey>, nonce: Vec<u8>, aad: Vec<u8>, tag_size: Option<u8>, input: Resource<WrapInput>, ) -> impl Future<Output = Result<Result<Vec<u8>, Error>>> + Send

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

fn unwrap( accessor: &Accessor<T, Self>, self_: Resource<AeadKey>, nonce: Vec<u8>, aad: Vec<u8>, tag_size: Option<u8>, wrapped: Vec<u8>, ) -> impl Future<Output = Result<Result<Resource<UnwrapInput>, Error>>> + Send

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

fn export_key_raw( accessor: &Accessor<T, Self>, self_: Resource<AeadKey>, ) -> impl Future<Output = Result<Result<Vec<u8>, Error>>> + Send

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

Source

fn export_key_jwk( accessor: &Accessor<T, Self>, self_: Resource<AeadKey>, ) -> impl Future<Output = Result<Result<String, Error>>> + Send

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

fn to_wrap_input_raw( accessor: &Accessor<T, Self>, self_: Resource<AeadKey>, ) -> impl Future<Output = Result<Result<Resource<WrapInput>, Error>>> + Send

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

fn to_wrap_input_jwk( accessor: &Accessor<T, Self>, self_: Resource<AeadKey>, ) -> impl Future<Output = Result<Result<Resource<WrapInput>, Error>>> + Send

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§