#[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 recoverableerror.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
impl WasiWebcryptoCtx
Sourcepub fn set_per_call_buffer_limit(&mut self, limit: Option<u64>)
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.
Sourcepub fn set_total_buffer_limit(&mut self, limit: Option<u64>)
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.
Sourcepub fn set_retention_limit(&mut self, limit: Option<u64>)
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.
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§impl Debug for WasiWebcryptoCtx
impl Debug for WasiWebcryptoCtx
Source§impl Default for WasiWebcryptoCtx
impl Default for WasiWebcryptoCtx
Source§fn default() -> WasiWebcryptoCtx
fn default() -> WasiWebcryptoCtx
Auto Trait Implementations§
impl !Freeze for WasiWebcryptoCtx
impl RefUnwindSafe for WasiWebcryptoCtx
impl Send for WasiWebcryptoCtx
impl Sync for WasiWebcryptoCtx
impl Unpin for WasiWebcryptoCtx
impl UnsafeUnpin for WasiWebcryptoCtx
impl UnwindSafe for WasiWebcryptoCtx
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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