Skip to main content

add_to_linker

Function add_to_linker 

Source
pub fn add_to_linker<T>(linker: &mut Linker<T>) -> Result<()>
where T: WasiWebcryptoView + 'static,
Expand description

Add the polymorph:webcrypto interfaces implemented by this crate — types, the primitive kinds (mac, aead, digest, signature), and the algorithm minting interfaces — to the provided [Linker].

The store’s data type T must implement WasiWebcryptoView. The engine’s Config must have wasm_component_model_async enabled, since the key-minting and stream-carrying functions use the component-model async ABI.

§Example

use wasmtime::component::{Linker, ResourceTable};
use wasmtime::{Engine, Result};
use polymorph_webcrypto_wasmtime::{
    add_to_linker, WasiWebcryptoCtx, WasiWebcryptoCtxView, WasiWebcryptoView,
};

struct MyState {
    webcrypto: WasiWebcryptoCtx,
    table: ResourceTable,
}

impl WasiWebcryptoView for MyState {
    fn webcrypto(&mut self) -> WasiWebcryptoCtxView<'_> {
        WasiWebcryptoCtxView {
            ctx: &mut self.webcrypto,
            table: &mut self.table,
        }
    }
}

fn wire(linker: &mut Linker<MyState>) -> Result<()> {
    add_to_linker(linker)
}

The @unstable-gated interfaces — sha1-checked, the RSA signing pair, and RSA-OAEP decryption-key minting (see wit/README.md, “Stability gates”) — are not added: a guest whose world imports them fails to instantiate against this default. Opt in with add_to_linker_with_options.