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
impl Cipheriv
sourcepub fn create(
alg: &str,
key: impl AsRef<[u8]>,
iv: impl AsRef<[u8]>
) -> Result<Self, CryptoErrno>
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.
sourcepub fn set_aad(&mut self, data: impl AsRef<[u8]>) -> Result<(), CryptoErrno>
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
.
sourcepub fn update(&mut self, data: impl AsRef<[u8]>) -> Result<(), CryptoErrno>
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
sourcepub fn fin(&mut self) -> Result<Vec<u8>, CryptoErrno>
pub fn fin(&mut self) -> Result<Vec<u8>, CryptoErrno>
final
is reserved keyword, fin
looks better than r#final
sourcepub fn encrypt(
&mut self,
data: impl AsRef<[u8]>
) -> Result<Vec<u8>, CryptoErrno>
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.
sourcepub fn get_auth_tag(&self) -> Result<&Vec<u8>, CryptoErrno>
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.
sourcepub fn take_auth_tag(&mut self) -> Result<Vec<u8>, CryptoErrno>
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.