Skip to main content

WasiWebcryptoCtx

Struct WasiWebcryptoCtx 

Source
#[non_exhaustive]
pub struct WasiWebcryptoCtx { /* private fields */ }
Expand description

Configuration and per-store state for the WebCrypto host.

This is intentionally minimal (mirroring wasmtime_wasi_http’s WasiHttpCtx); it exists so hosts have a stable place to grow configuration without changing the WasiWebcryptoView shape.

§Input-buffering limits

Every stream-taking operation buffers its whole input host-side (the single-message contract), and the component-model async ABI lets a guest run many calls concurrently — so without limits a guest could make the host retain unbounded memory. Two limits bound that retention (wasmtime’s per-call lift budget, Store::set_hostcall_fuel, bounds each stream delivery; these bound what operations accumulate):

  • Per call (set_per_call_buffer_limit): the most one operation may buffer. Inputs beyond it are drained and discarded (this host drains to completion rather than exercising the streaming contract’s early-close-on-error permission) and the operation fails with a recoverable error.other. Defaults to ¼ of the store’s hostcall fuel at admission time.
  • Total (set_total_buffer_limit): the admission pool. Each operation reserves its per-call bound before draining and waits (FIFO) for capacity when the pool is full, releasing when its buffers are gone — including the returned output stream. Defaults to 1× the store’s hostcall fuel, so untouched configurations retain at most the embedder’s one configured number, at a default concurrency of four operations.

Admission shares one pool per context, so an operation may wait on unrelated operations’ completion. The package states the caller’s side of this as the making-progress rule (see the mac-key docs): feed each in-flight operation’s input, and drain each returned stream as it becomes available, without waiting on another operation. A caller that defers either can deadlock against the bound, and no implementation can rescue it.

§Minted-resource retention

Minted resources — keys, IKM, passwords, derivations, options, digests — live in the store’s table until the guest drops them, so unbounded minting is unbounded host retention even with every operation bounded. A third limit bounds it:

  • Retention (set_retention_limit): the retention pool. Every mint charges a fixed per-resource floor (which bounds resource count) plus its variable-length material bytes, holds the charge for the resource’s lifetime, and releases it when the resource drops. Defaults to 16 MiB.

Retention admission is fail-fast, never waiting: its capacity frees only when the guest drops a resource, which may never happen. A mint past the budget fails with a recoverable error.other — drop resources and retry. The *-options.new constructors, whose WIT signatures carry no error channel, trap instead, the same class as a table-push failure.

What is bounded is what this host accumulates: the stream buffers, the output stream until its bytes are read or dropped, and minted resources. What is not bounded is the list<u8> parameters — aad, nonce, and the minting interfaces’ raw — which the canonical ABI lifts before the host function runs, so they are already in host memory when admission is reached. Bounding those needs a hold before the call starts, which the component model provides to a component callee (backpressure.{inc,dec}) and does not expose to a host import. (The in-guest provider, which could use it, deliberately does not: it has essentially one caller, so its instance memory limit is its bound — see polymorph-webcrypto-guest-provider’s buffer module.) Also outside the pools: each operation’s transient working set — in seal/open the buffered input and the constructed output coexist until the input drops, so peak use briefly reaches about twice the reservation plus the tag, and derive-bits builds its full output before the ABI lifts it.

Each pool’s budget is resolved once, at its first use, and belongs to the pool from then on (see limits.rs for why the budget is the pool’s, not each acquirer’s). Configure the limits before the first crypto call; changing them afterwards retunes the per-call limit but not the pools.

Cloning the context gives the clone its own pools, since the pools are parameterized by the budgets the context carries.

Implementations§

Source§

impl WasiWebcryptoCtx

Source

pub fn new() -> Self

Create a new, default context.

Source

pub fn set_per_call_buffer_limit(&mut self, limit: Option<u64>)

Set the most one operation may buffer, in bytes. None (the default) derives ¼ of the store’s hostcall fuel at admission time.

Source

pub fn set_total_buffer_limit(&mut self, limit: Option<u64>)

Set the total input-buffering admission pool, in bytes. None (the default) derives the store’s hostcall fuel at admission time.

Source

pub fn set_retention_limit(&mut self, limit: Option<u64>)

Set the minted-resource retention pool, in bytes: the most the guest’s live resources (keys, derivations, options, …) may retain host-side, charged per mint and released per drop. None (the default) is 16 MiB. A limit below the per-resource floor admits no mint at all.

Trait Implementations§

Source§

impl Clone for WasiWebcryptoCtx

Cloning a context gives the clone its own pools.

The pools bound aggregate retention against ceilings that each context carries separately, so sharing one pool between contexts configured differently would let the larger ceiling admit against the smaller context’s accounting — exceeding the bound it was asked to enforce. Independent pools keep each context’s limit meaning what it says; a single bound across several contexts is not something this type can express.

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WasiWebcryptoCtx

Source§

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

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

impl Default for WasiWebcryptoCtx

Source§

fn default() -> WasiWebcryptoCtx

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,