Expand description
Guest-side bindings and ergonomic helpers for the polymorph:webcrypto
interfaces.
This crate is the intended way for Rust guest components to consume
polymorph:webcrypto: it binds the whole import surface once (the
bindings module) and wraps the key resources in newtypes whose
operations take a DataSource — a byte slice, an owned buffer, or a
component-model stream — so callers need none of the stream plumbing the
interfaces are defined in terms of.
Most consumers need no polymorph:webcrypto WIT at all: link this crate
and call it, and the componentized binary imports exactly the interfaces
it uses (unused imports are stripped). Only list the imports in your own
world — remapping them onto this crate’s bindings modules with
wit-bindgen’s with: option — if your own interfaces name these types or
external tooling validates your world’s shape. Do not bind the same
interfaces with a second generate! without that remapping: the two
expansions would produce distinct, unconvertible resource types, and the
newtypes here wrap only this crate’s generation.
§Cargo features
bytes:DataSource::from_buffeeds an operation from anybytes::Buf, chunk by chunk.futures-io:DataSource::from_readerfeeds an operation from anyfutures_io::AsyncRead; read failures surface asError::Read.
§Contract notes carried over from the WIT
- The wrappers hide streams, not the closure rule. An operation’s
input stream ends no later than the operation completes, and only a
failing operation may end it early; these helpers feed the source and
await the result concurrently, reporting the operation’s error over
the feed’s fate, so that contract is invisible here. Callers with
needs beyond
DataSourceuse thebindingsresources directly with wit-bindgen’s own stream primitives (wit_stream::new,StreamWriter::write_all, [StreamReader::collect]). - Writer drop ends the message. A stream’s producer failing midway
is indistinguishable from it finishing (the ABI carries no verdict at
end-of-stream). Buffer-backed
DataSources own their whole input, so this only concerns stream-backed sources; seeDataSource’s truncating-producer warning. - Implementations may bound input sizes. Hosts enforce buffering
limits as recoverable
Error::Othervalues (see the WITtypes.errordocs); nothing here retries or special-cases them. - Nonces are the caller’s problem on
aead.Aead::sealleaves nonce uniqueness per key entirely to you, and nonce reuse under one key defeats the algorithm’s guarantees.
Re-exports§
pub use wit_bindgen;
Modules§
- aes_cbc
aes-cbckey creation (the unauthenticated AES-CBC mode; preferaes_gcm— seeCipherKey’s warning).- aes_ctr
aes-ctrkey creation (the unauthenticated AES-CTR mode; preferaes_gcm— seeCipherKey’s warning).- aes_gcm
aes-gcmkey creation (caller-nonce — seeAead’s nonce warning).- aes_kw
aes-kwkey creation (RFC 3394 / NIST SP 800-38F KW): dedicated key-wrapping keys for thekey-wrapkind.- bindings
- The generated bindings for the full
polymorph:webcryptoimport surface. - ecdh
ecdhkey creation (SP 800-56A ECDH over the NIST prime-order curves).- ecdsa
ecdsa-verify/ecdsa-signkey creation.- ed25519
ed25519-verify/ed25519-signkey creation.- extension
- The known extension-error conditions, as (
origin,name) constants for matching againstError::Extension. - hkdf
hkdfbase-secret import (RFC 5869).- hkdf_
sha1 hkdf-sha1derivation parameterization: HKDF over SHA-1, for compatibility with existing protocols that fix it. The construction is not affected by SHA-1’s collision attacks (HKDF relies on HMAC’s PRF property), but preferhkdf_sha2where the protocol is yours to choose.- hkdf_
sha2 hkdf-sha2derivation parameterization (RFC 5869 over the SHA-2 family).- hmac_
sha1 hmac-sha1key creation: HMAC over SHA-1, for interoperability with SHA-1-committed constructions (TOTP, WPA2). HMAC’s security rests on the PRF property, which SHA-1’s collision breaks do not reach; preferhmac_sha2in new designs.- hmac_
sha2 hmac-sha2key creation.- pbkdf2
pbkdf2base-secret import (RFC 8018).- pbkdf2_
sha1 pbkdf2-sha1derivation parameterization: PBKDF2 over HMAC-SHA-1, for compatibility with existing password databases that fix it. The construction is not affected by SHA-1’s collision attacks (PBKDF2 relies on HMAC’s PRF property), but preferpbkdf2_sha2where the parameters are yours to choose.- pbkdf2_
sha2 pbkdf2-sha2derivation parameterization (RFC 8018 over HMAC-SHA-2).- rsa_
oaep rsa-oaep-encryptkey creation (RFC 8017 §7.1) — the public half of key transport — plus, behind thersa-oaep-decryptcargo feature,rsa-oaep-decrypt.- rsa_pss
rsa-pss-verifykey creation (RFC 8017 §8.1), plus — behind thersa-signcargo feature —rsa-pss-sign.- rsassa_
pkcs1_ v15 rsassa-pkcs1-v15-verifykey creation (RFC 8017 §8.2), plus — behind thersa-signcargo feature —rsassa-pkcs1-v15-sign.- sha2
sha2digest creation.- wit_
stream - x25519
x25519key creation (RFC 7748 §5, the X25519 function).
Structs§
- Aead
- An
aead.aead-key: caller-nonce authenticated encryption with associated data. - Aead
KeyOptions - Mint-time policy for an
Aeadkey. SeeMacKeyOptionsfor the options contract. - Agreement
KeyOptions - Mint-time policy for an
AgreementSecretKey. SeeMacKeyOptionsfor the options contract; the derive grants are copied onto everyDeriveInputthe keyagrees (WebCrypto’s model: derive usages live on the secret key). - Agreement
Public Key - A
key-agreement.public-key: the exchangeable half of an agreement keypair, minted byx25519’s imports andgenerate_key. Secret-free. - Agreement
Secret Key - A
key-agreement.secret-key: the private half of an agreement keypair.agreeis one-shot on the immutable key; the derivation state lives in theDeriveInputit returns. - Cipher
Key - An unauthenticated-cipher key (AES-CBC or AES-CTR), minted by
aes_cbc/aes_ctr. Nothing this key does authenticates: ciphertext is malleable and a successfuldecryptis not evidence the input is untampered. Default toAead; use this kind only where an existing format fixes the mode. See the WITcipherinterface for the full contract. - Cipher
KeyOptions - Mint-time policy for a
CipherKeykey. SeeMacKeyOptionsfor the options contract. - Data
Source - The input to a wrapped operation: anything this crate knows how to feed
into a WIT
stream<u8>. - Decryption
Key - A
public-encryption.decryption-key: the private half of asymmetric encryption.decryptandunwrapare one-shot calls on the immutable key, over whole byte buffers (seeEncryptionKeyfor why nothing streams here). - Decryption
KeyOptions - Mint-time policy for a
DecryptionKey. SeeMacKeyOptionsfor the options contract. The two grants separate disclosure from minting:decryptreturns plaintext to the caller, whileunwrapmints keys whose material the caller never sees, so a key granted onlyunwrapcannot leak what it transports. - Derive
Input - A
derivation.derive-input: a fully parameterized derivation — base secret plus every parameter, minted by thepreparefunctions (hkdf_sha2::prepare,pbkdf2_sha2::prepare, …) and byAgreementSecretKey::agree. - Derive
Options - Mint-time policy for a derivation base secret (
IkmorPassword). SeeMacKeyOptionsfor the options contract. The grants are copied onto everyDeriveInputbuilt on the secret; parameterization neither grants nor revokes. - Digest
- A
digest.digest: a reusable, algorithm-bound hash. - Encryption
Key - A
public-encryption.encryption-key: the public half of asymmetric encryption — encryption and wrapping, secret-free to hold. - Ikm
- An
hkdf.ikm: imported input keying material for HKDF, minted byhkdf::import_ikm. Never readable back through the API under any grant; the grants recorded at import are copied onto everyDeriveInputbuilt on it (viahkdf_sha2::prepareand friends). - KwKey
- A
key-wrap.kw-key: a dedicated key-wrapping key (AES-KW), bound to its algorithm at creation. - KwKey
Options - Mint-time policy for a
KwKey. SeeMacKeyOptionsfor the options contract. - Mac
- A
mac.mac-key: a message-authentication-code key, bound to one algorithm at creation. - MacKey
Options - Mint-time policy for a
Mackey: the plain-data counterpart of the WITmac.mac-key-optionsresource, which the minting functions construct from it per call. - Password
- A
pbkdf2.password: an imported password, minted bypbkdf2::import_password. Never readable back through the API under any grant; the grants recorded at import are copied onto everyDeriveInputbuilt on it (viapbkdf2_sha2::prepareand friends). - Seal
- A pending
seal, returned byAead::sealandCipherKey::encrypt. - Signing
Key - A
signature.signing-key: private-key signing. - Signing
KeyOptions - Mint-time policy for a
SigningKey. SeeMacKeyOptionsfor the options contract;signis the sole usage, so it must be enabled for a mint to succeed. - Unwrap
Input - A
wrapping.unwrap-input: decrypted key material awaiting a typed unwrap mint. Single-use, likeWrapInput. - Verifying
Key - A
signature.verifying-key: public-key signature verification. Secret-free — a component holding only this key provably cannot sign. - Wrap
Input - A
wrapping.wrap-input: one key’s serialized material awaiting encryption under a wrapping key. Single-use — the consuming wrap operation takes it by value, on failure as on success.
Enums§
- Error
- Errors surfaced by key creation and cryptographic operations.
Type Aliases§
- Stream
Reader - The component-model byte-stream reader, as returned by
Aead::sealand friends and accepted byDataSource. Represents the readable end of a Component Modelstream.