pub struct Aead(/* private fields */);Expand description
An aead.aead-key: caller-nonce authenticated encryption with
associated data.
Nonce reuse under one key is catastrophic, and this type’s
seal leaves nonce uniqueness entirely to you: use a
deterministic per-key uniqueness scheme (such as a counter).
Implementations§
Source§impl Aead
impl Aead
Sourcepub fn seal<'a>(
&'a self,
nonce: impl Into<Cow<'a, [u8]>>,
aad: impl Into<Cow<'a, [u8]>>,
plaintext: impl Into<DataSource<'a>>,
) -> Seal<'a> ⓘ
pub fn seal<'a>( &'a self, nonce: impl Into<Cow<'a, [u8]>>, aad: impl Into<Cow<'a, [u8]>>, plaintext: impl Into<DataSource<'a>>, ) -> Seal<'a> ⓘ
Encrypt and authenticate plaintext under nonce and aad,
yielding the ciphertext followed by the authentication tag.
Returns a Seal, which starts the operation when awaited.
The caller is responsible for nonce uniqueness per key. Reusing a nonce under one key defeats the algorithm’s confidentiality and authenticity guarantees.
Sourcepub fn seal_with_tag_size<'a>(
&'a self,
nonce: impl Into<Cow<'a, [u8]>>,
aad: impl Into<Cow<'a, [u8]>>,
tag_size: u8,
plaintext: impl Into<DataSource<'a>>,
) -> Seal<'a> ⓘ
pub fn seal_with_tag_size<'a>( &'a self, nonce: impl Into<Cow<'a, [u8]>>, aad: impl Into<Cow<'a, [u8]>>, tag_size: u8, plaintext: impl Into<DataSource<'a>>, ) -> Seal<'a> ⓘ
Sourcepub async fn open(
&self,
nonce: impl Into<Cow<'_, [u8]>>,
aad: impl Into<Cow<'_, [u8]>>,
ciphertext: impl Into<DataSource<'_>>,
) -> Result<StreamReader<u8>, Error>
pub async fn open( &self, nonce: impl Into<Cow<'_, [u8]>>, aad: impl Into<Cow<'_, [u8]>>, ciphertext: impl Into<DataSource<'_>>, ) -> Result<StreamReader<u8>, Error>
Decrypt and verify ciphertext (ciphertext followed by tag, as
produced by seal) under nonce and aad.
The stream is handed back only after the whole input is consumed and
the tag verified: Ok is the authentication statement, and
unverified plaintext is never observable. Fails closed with
Error::AuthenticationFailed if verification fails.
Sourcepub async fn open_with_tag_size(
&self,
nonce: impl Into<Cow<'_, [u8]>>,
aad: impl Into<Cow<'_, [u8]>>,
tag_size: u8,
ciphertext: impl Into<DataSource<'_>>,
) -> Result<StreamReader<u8>, Error>
pub async fn open_with_tag_size( &self, nonce: impl Into<Cow<'_, [u8]>>, aad: impl Into<Cow<'_, [u8]>>, tag_size: u8, ciphertext: impl Into<DataSource<'_>>, ) -> Result<StreamReader<u8>, Error>
open with an explicit tag size in bytes (the size
the message was sealed with — see
seal_with_tag_size).
Sourcepub fn algorithm_name(&self) -> String
pub fn algorithm_name(&self) -> String
The name of the key’s algorithm family, e.g. "AES-GCM" —
WebCrypto’s KeyAlgorithm.name, spelled as the W3C Web Cryptography
API algorithm registry
spells it.
Sourcepub fn algorithm_length(&self) -> u32
pub fn algorithm_length(&self) -> u32
The key length in bits, e.g. 256 for AES-256-GCM (WebCrypto’s
AesKeyAlgorithm.length).
Sourcepub fn nonce_size(&self) -> u32
pub fn nonce_size(&self) -> u32
Sourcepub fn tag_size(&self) -> u32
pub fn tag_size(&self) -> u32
The size in bytes of the tag trailing the ciphertext, e.g. 16 —
for framing arithmetic (sealed length = plaintext length +
tag_size).
Sourcepub fn extractable(&self) -> bool
pub fn extractable(&self) -> bool
Whether export_key_raw may return the key material
(see Mac::extractable).
Sourcepub fn can_seal(&self) -> bool
pub fn can_seal(&self) -> bool
Whether the key permits seal — the usage recorded
at mint. A refused operation fails Error::NotPermitted.
Sourcepub fn can_unwrap(&self) -> bool
pub fn can_unwrap(&self) -> bool
Sourcepub async fn wrap(
&self,
nonce: impl Into<Vec<u8>>,
aad: impl Into<Vec<u8>>,
tag_size: Option<u8>,
input: WrapInput,
) -> Result<Vec<u8>, Error>
pub async fn wrap( &self, nonce: impl Into<Vec<u8>>, aad: impl Into<Vec<u8>>, tag_size: Option<u8>, input: WrapInput, ) -> Result<Vec<u8>, Error>
Encrypt and authenticate serialized key material under nonce
with aad, exactly as seal encrypts a message (the WIT
aead-key.wrap contract). Consumes the WrapInput.
Sourcepub async fn unwrap(
&self,
nonce: impl Into<Vec<u8>>,
aad: impl Into<Vec<u8>>,
tag_size: Option<u8>,
wrapped: impl Into<Vec<u8>>,
) -> Result<UnwrapInput, Error>
pub async fn unwrap( &self, nonce: impl Into<Vec<u8>>, aad: impl Into<Vec<u8>>, tag_size: Option<u8>, wrapped: impl Into<Vec<u8>>, ) -> Result<UnwrapInput, Error>
Decrypt and verify wrapped key material into an UnwrapInput
for a typed unwrap mint (the WIT aead-key.unwrap contract).
Sourcepub async fn to_wrap_input_raw(&self) -> Result<WrapInput, Error>
pub async fn to_wrap_input_raw(&self) -> Result<WrapInput, Error>
This key’s raw material as a WrapInput, behind the same
extractability gate as export_key_raw.
Sourcepub async fn to_wrap_input_jwk(&self) -> Result<WrapInput, Error>
pub async fn to_wrap_input_jwk(&self) -> Result<WrapInput, Error>
The JWK serialization as a WrapInput, behind the same gate.
Sourcepub async fn export_key_raw(&self) -> Result<Vec<u8>, Error>
pub async fn export_key_raw(&self) -> Result<Vec<u8>, Error>
The raw key material; fails with Error::NotExtractable unless the
key was minted extractable (an API property, not a physical one —
see Mac::export_key_raw).
Sourcepub async fn export_key_jwk(&self) -> Result<String, Error>
pub async fn export_key_jwk(&self) -> Result<String, Error>
The key as an RFC 7517 oct JSON Web Key (JSON text), behind the
same extractability gate as export_key_raw.
Algorithms with no registered JWK form fail Error::Unsupported.