Skip to main content

HostWithStore

Trait HostWithStore 

Source
pub trait HostWithStore<T>: HasData + Send {
    // Required methods
    fn import_key_raw(
        accessor: &Accessor<T, Self>,
        variant: Sha2Variant,
        raw: Vec<u8>,
        options: Resource<MacKeyOptions>,
    ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send;
    fn import_key_jwk(
        accessor: &Accessor<T, Self>,
        variant: Sha2Variant,
        jwk: String,
        options: Resource<MacKeyOptions>,
    ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send;
    fn generate_key(
        accessor: &Accessor<T, Self>,
        variant: Sha2Variant,
        length: Option<u32>,
        options: Resource<MacKeyOptions>,
    ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send;
    fn derive_key(
        accessor: &Accessor<T, Self>,
        variant: Sha2Variant,
        input: Resource<DeriveInput>,
        length: Option<u32>,
        options: Resource<MacKeyOptions>,
    ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send;
    fn unwrap_key_raw(
        accessor: &Accessor<T, Self>,
        variant: Sha2Variant,
        input: Resource<UnwrapInput>,
        options: Resource<MacKeyOptions>,
    ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send;
    fn unwrap_key_jwk(
        accessor: &Accessor<T, Self>,
        variant: Sha2Variant,
        input: Resource<UnwrapInput>,
        options: Resource<MacKeyOptions>,
    ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send;
}

Required Methods§

Source

fn import_key_raw( accessor: &Accessor<T, Self>, variant: Sha2Variant, raw: Vec<u8>, options: Resource<MacKeyOptions>, ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send

Import raw key material as an HMAC key over the declared SHA-2 variant.

Empty keys fail error.invalid-key. Implementations generally accept any non-empty length (per RFC 2104; keys longer than the block size are hashed first), but an implementation enforcing a security policy (for example FIPS 140-3 approved mode, which requires keys of at least 112 bits) MAY reject shorter keys with error.invalid-key. An implementation not serving the variant fails with error.unsupported.

Source

fn import_key_jwk( accessor: &Accessor<T, Self>, variant: Sha2Variant, jwk: String, options: Resource<MacKeyOptions>, ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send

Import an RFC 7517 JSON Web Key as an HMAC key over the declared SHA-2 variant.

jwk is the JWK as JSON text; the implementation owns the parse (see README.md, “JWK contract”). The key must be an oct key whose alg, if present, names the declared variant ("HS256"/"HS384"/"HS512"), with ext validated against the options’ extractability; the decoded material is then subject to import-key-raw’s contract.

Source

fn generate_key( accessor: &Accessor<T, Self>, variant: Sha2Variant, length: Option<u32>, options: Resource<MacKeyOptions>, ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send

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 length fails error.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.
Source

fn derive_key( accessor: &Accessor<T, Self>, variant: Sha2Variant, input: Resource<DeriveInput>, length: Option<u32>, options: Resource<MacKeyOptions>, ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send

Mint a key from a parameterized derivation: the derivation runs at length bits and the result is subject to import-key-raw’s contract.

length follows generate-key’s contract exactly (WebCrypto’s deriveKey computes the derived length by the same get key length step generateKey uses).

Requires can-derive-key on the input, else error.not-permitted; requesting an extractable key additionally requires can-derive-bits (see aes-gcm.derive-key).

Source

fn unwrap_key_raw( accessor: &Accessor<T, Self>, variant: Sha2Variant, input: Resource<UnwrapInput>, options: Resource<MacKeyOptions>, ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send

Mint a key from unwrapped key material (see the wrapping interface): input’s bytes are read as raw key material, subject to import-key-raw’s contract. input is consumed.

The minted key’s usages and extractability come from options alone (the W3C Web Cryptography API’s unwrapKey model).

Source

fn unwrap_key_jwk( accessor: &Accessor<T, Self>, variant: Sha2Variant, input: Resource<UnwrapInput>, options: Resource<MacKeyOptions>, ) -> impl Future<Output = Result<Result<Resource<MacKey>, Error>>> + Send

Mint a key from unwrapped key material read as an RFC 7517 JSON Web Key, subject to import-key-jwk’s contract plus the unwrap-path use/key_ops checks (see README.md, “JWK contract”). input is consumed; see unwrap-key-raw for the options model.

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§