pub struct CipherKey(/* private fields */);Expand description
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 successful decrypt is
not evidence the input is untampered. Default to Aead; use this
kind only where an existing format fixes the mode. See the WIT
cipher interface for the full contract.
Implementations§
Source§impl CipherKey
impl CipherKey
Sourcepub fn encrypt<'a>(
&'a self,
iv: impl Into<Cow<'a, [u8]>>,
counter_length: Option<u8>,
plaintext: impl Into<DataSource<'a>>,
) -> Seal<'a> ⓘ
pub fn encrypt<'a>( &'a self, iv: impl Into<Cow<'a, [u8]>>, counter_length: Option<u8>, plaintext: impl Into<DataSource<'a>>, ) -> Seal<'a> ⓘ
Encrypt plaintext under iv (for AES-CTR, the initial counter
block plus the counter width in bits; AES-CBC callers pass None).
The caller owns the IV discipline — see the minting interface’s
Security notes.
Sourcepub async fn decrypt(
&self,
iv: impl Into<Cow<'_, [u8]>>,
counter_length: Option<u8>,
ciphertext: impl Into<DataSource<'_>>,
) -> Result<StreamReader<u8>, Error>
pub async fn decrypt( &self, iv: impl Into<Cow<'_, [u8]>>, counter_length: Option<u8>, ciphertext: impl Into<DataSource<'_>>, ) -> Result<StreamReader<u8>, Error>
Decrypt ciphertext under iv. The plaintext is unauthenticated:
treat it as attacker-influenced data even on success. Malformed
input fails Error::Other, deliberately uniform across
conditions.
Sourcepub fn algorithm_name(&self) -> String
pub fn algorithm_name(&self) -> String
The name of the key’s algorithm family, e.g. "AES-CBC".
Sourcepub fn algorithm_length(&self) -> u32
pub fn algorithm_length(&self) -> u32
The key length in bits.
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_encrypt(&self) -> bool
pub fn can_encrypt(&self) -> bool
Whether the key permits encrypt.
Sourcepub fn can_decrypt(&self) -> bool
pub fn can_decrypt(&self) -> bool
Whether the key permits decrypt.
Sourcepub fn can_unwrap(&self) -> bool
pub fn can_unwrap(&self) -> bool
Sourcepub async fn wrap(
&self,
iv: impl Into<Vec<u8>>,
counter_length: Option<u8>,
input: WrapInput,
) -> Result<Vec<u8>, Error>
pub async fn wrap( &self, iv: impl Into<Vec<u8>>, counter_length: Option<u8>, input: WrapInput, ) -> Result<Vec<u8>, Error>
Encrypt serialized key material under iv, exactly as encrypt
encrypts a message (the WIT cipher-key.wrap contract; nothing
here authenticates). Consumes the WrapInput.
Sourcepub async fn unwrap(
&self,
iv: impl Into<Vec<u8>>,
counter_length: Option<u8>,
wrapped: impl Into<Vec<u8>>,
) -> Result<UnwrapInput, Error>
pub async fn unwrap( &self, iv: impl Into<Vec<u8>>, counter_length: Option<u8>, wrapped: impl Into<Vec<u8>>, ) -> Result<UnwrapInput, Error>
Decrypt wrapped key material into an UnwrapInput for a typed
unwrap mint (the WIT cipher-key.unwrap contract; the result is
unauthenticated).
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, behind the extractability gate.
Sourcepub async fn export_key_jwk(&self) -> Result<String, Error>
pub async fn export_key_jwk(&self) -> Result<String, Error>
The key as an oct JWK, behind the same gate.