Skip to main content

CipherKey

Struct CipherKey 

Source
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

Source

pub fn from_raw(raw: CipherKey) -> Self

Wrap a raw cipher-key resource.

Source

pub fn as_raw(&self) -> &CipherKey

Borrow the raw cipher-key resource.

Source

pub fn into_raw(self) -> CipherKey

Unwrap into the raw cipher-key resource.

Source§

impl CipherKey

Source

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.

Source

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.

Source

pub fn algorithm_name(&self) -> String

The name of the key’s algorithm family, e.g. "AES-CBC".

Source

pub fn algorithm_length(&self) -> u32

The key length in bits.

Source

pub fn iv_size(&self) -> u32

The algorithm’s IV size in bytes (16 for the AES modes).

Source

pub fn extractable(&self) -> bool

Whether export_key_raw may return the key material (see Mac::extractable).

Source

pub fn can_encrypt(&self) -> bool

Whether the key permits encrypt.

Source

pub fn can_decrypt(&self) -> bool

Whether the key permits decrypt.

Source

pub fn can_wrap(&self) -> bool

Whether the key permits wrap.

Source

pub fn can_unwrap(&self) -> bool

Whether the key permits unwrap. See can_wrap.

Source

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.

Source

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).

Source

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.

Source

pub async fn to_wrap_input_jwk(&self) -> Result<WrapInput, Error>

The JWK serialization as a WrapInput, behind the same gate.

Source

pub async fn export_key_raw(&self) -> Result<Vec<u8>, Error>

The raw key material, behind the extractability gate.

Source

pub async fn export_key_jwk(&self) -> Result<String, Error>

The key as an oct JWK, behind the same gate.

Trait Implementations§

Source§

impl Debug for CipherKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<CipherKey> for CipherKey

Source§

fn from(raw: CipherKey) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Resource for T
where T: 'static,

§

type Rep = Option<T>

The type which is actually stored in-memory for this resource. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.