Struct crypto_wasi::Cipheriv

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

Equivalent to crypto.Cipheriv

cipheriv.setAutoPadding is unsupported current.

Example:

use crate::Cipheriv;

let mut c = Cipheriv::create(alg, key, iv)?;
c.set_aad(aad)?; // optional
c.update(msg1)?;
c.update(msg2)?;
let res = c.fin()?;
let auth_tag = c.get_auth_tag()?;

Implementations§

source§

impl Cipheriv

source

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

Equivalent to createCipheriv

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 implement of wasi-crypto, encrypt can’t be called multiple times, multiple call encrypt is also not equivalent to multiple call update. so we store all message and concat it, then encrypt one-time on fin

source

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

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

source

pub fn encrypt( &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 get_auth_tag(&self) -> Result<&Vec<u8>, CryptoErrno>

The get_auth_tag method should only be called after encryption has been completed using the fin method.

source

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

As same as get_auth_tag, but get the ownership of auth_tag stored in struct internal.

Trait Implementations§

source§

impl Drop for Cipheriv

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.