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
impl Decipheriv
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 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.
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 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
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 decrypt(
&mut self,
data: impl AsRef<[u8]>
) -> Result<Vec<u8>, CryptoErrno>
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.
sourcepub fn set_auth_tag(
&mut self,
data: impl AsRef<[u8]>
) -> Result<(), CryptoErrno>
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.