Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/aead/src/decrypt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{aad::IntoAad, cipher::Unspecified, Cipher, LocalCipherText};
use vitaminc_protected::{Controlled, Protected};
use vitaminc_protected::{Controlled, Equatable, Protected};
use zeroize::Zeroize;

pub trait Decrypt: Sized {
Expand Down Expand Up @@ -97,3 +97,24 @@ where
Ok(Protected::init_from_inner(inner))
}
}

impl<T> Decrypt for Equatable<T>
where
Self: Controlled,
<Equatable<T> as Controlled>::Inner: Decrypt,
{
type Encrypted = <<Equatable<T> as Controlled>::Inner as Decrypt>::Encrypted;

fn decrypt_with_aad<'a, C, A>(
encrypted: Self::Encrypted,
cipher: &C,
aad: A,
) -> Result<Self, Unspecified>
where
C: Cipher,
A: IntoAad<'a>,
{
let inner = <Equatable<T> as Controlled>::Inner::decrypt_with_aad(encrypted, cipher, aad)?;
Ok(Equatable::init_from_inner(inner))
}
}
19 changes: 18 additions & 1 deletion packages/aead/src/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
cipher::{Cipher, Unspecified},
LocalCipherText,
};
use vitaminc_protected::{Controlled, Protected};
use vitaminc_protected::{Controlled, Equatable, Protected};
use zeroize::Zeroize;

pub trait Encrypt: Sized {
Expand Down Expand Up @@ -97,6 +97,23 @@ where
}
}

impl<T> Encrypt for Equatable<T>
where
Self: Controlled,
<Equatable<T> as Controlled>::Inner: Encrypt,
{
type Encrypted = <<Equatable<T> as Controlled>::Inner as Encrypt>::Encrypted;

fn encrypt_with_aad<'a, C, A>(self, cipher: &C, aad: A) -> Result<Self::Encrypted, Unspecified>
where
C: Cipher,
A: IntoAad<'a>,
Self: 'a,
{
self.risky_unwrap().encrypt_with_aad(cipher, aad)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down