Struct crypto_wasi::Decipheriv

source ·
pub struct Decipheriv { /* private fields */ }
Expand description

Equivalent to crypto.Decipheriv

Example:

let mut d = Decipheriv::create(alg, key, iv)?;
d.set_aad(aad)?; // optional
d.set_auth_tag(auth_tag)?;
let src = d.decrypt(msg)?;

Implementations§

source§

impl Decipheriv

source

pub fn create( alg: &str, key: impl AsRef<[u8]>, iv: impl AsRef<[u8]> ) -> Result<Self, CryptoErrno>

Equivalent to createDecipheriv

For AES-128-GCM key should be 16 bytes and iv should be 12 bytes. For AES-256-GCM key should be 32 bytes and iv should be 12 bytes. For CHACHA20-POLY1305 key should be 32 bytes and iv should be 12 bytes.

source

pub fn set_aad(&mut self, data: impl AsRef<[u8]>) -> Result<(), CryptoErrno>

Sets the value used for the additional authenticated data (AAD) input parameter. The set_add method must be called before update.

source

pub fn update(&mut self, data: impl AsRef<[u8]>) -> Result<(), CryptoErrno>

In WasmEdge implementation of wasi-crypto, decrypt can’t be called multiple times, multiple call decrypt is also not equivalent to multiple call update. so we store all message and concat it, then decrypt one-time on final

source

pub fn fin(&mut self) -> Result<Vec<u8>, CryptoErrno>

final is reserved keyword, fin looks better than r#final

source

pub fn decrypt( &mut self, data: impl AsRef<[u8]> ) -> Result<Vec<u8>, CryptoErrno>

Equivalent to update(data) then fin, but no need to restore data in struct internal.

source

pub fn set_auth_tag( &mut self, data: impl AsRef<[u8]> ) -> Result<(), CryptoErrno>

When using an authenticated encryption mode (GCM are currently supported), the set_auth_tag method is used to pass in the received authentication tag. The set_auth_tag method must be called before fin for GCM modes.

Trait Implementations§

source§

impl Drop for Decipheriv

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.

source§

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

§

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>,

§

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.