diff --git a/crates/bitwarden-crypto/src/keys/encryptable.rs b/crates/bitwarden-crypto/src/keys/encryptable.rs index 5b51f25e6..66762a641 100644 --- a/crates/bitwarden-crypto/src/keys/encryptable.rs +++ b/crates/bitwarden-crypto/src/keys/encryptable.rs @@ -1,63 +1,12 @@ use super::key_ref::{AsymmetricKeyRef, KeyRef, SymmetricKeyRef}; use crate::{service::CryptoServiceContext, AsymmetricEncString, CryptoError, EncString}; -// Just like LocateKey but this time we're not locating anything, just returning a ref - +/// This trait should be implemented by any struct capable of knowing which key it needs +/// to encrypt or decrypt itself. pub trait UsesKey { fn uses_key(&self) -> Key; } -// This extension trait allows any type to be wrapped with `UsingKey` -// to make it easy to encrypt/decrypt it with the desired key, -// this way we don't need to have a separate `encrypt_with_key` function -pub trait UsingKeyExt: Sized { - fn using_key(self, key: Key) -> UsingKey { - UsingKey { key, value: self } - } -} -impl UsingKeyExt for T {} -pub struct UsingKey { - key: Key, - value: T, -} -impl UsesKey for UsingKey { - fn uses_key(&self) -> Key { - self.key - } -} -impl< - SymmKeyRef: SymmetricKeyRef, - AsymmKeyRef: AsymmetricKeyRef, - Key: KeyRef, - T: Encryptable, - Output, - > Encryptable for UsingKey -{ - fn encrypt( - &self, - ctx: &mut CryptoServiceContext, - _key: Key, - ) -> Result { - self.value.encrypt(ctx, self.key) - } -} -impl< - SymmKeyRef: SymmetricKeyRef, - AsymmKeyRef: AsymmetricKeyRef, - Key: KeyRef, - T: Decryptable, - Output, - > Decryptable for UsingKey -{ - fn decrypt( - &self, - ctx: &mut CryptoServiceContext, - _key: Key, - ) -> Result { - self.value.decrypt(ctx, self.key) - } -} - pub trait Encryptable< SymmKeyRef: SymmetricKeyRef, AsymmKeyRef: AsymmetricKeyRef, diff --git a/crates/bitwarden-crypto/src/keys/mod.rs b/crates/bitwarden-crypto/src/keys/mod.rs index 1267fd4fb..a75d9dba0 100644 --- a/crates/bitwarden-crypto/src/keys/mod.rs +++ b/crates/bitwarden-crypto/src/keys/mod.rs @@ -1,7 +1,7 @@ mod key_encryptable; pub use key_encryptable::{CryptoKey, KeyContainer, KeyDecryptable, KeyEncryptable, LocateKey}; mod encryptable; -pub use encryptable::{Decryptable, Encryptable, UsesKey, UsingKey, UsingKeyExt}; +pub use encryptable::{Decryptable, Encryptable, UsesKey}; pub mod key_ref; pub(crate) use key_ref::KeyRef; pub use key_ref::{AsymmetricKeyRef, SymmetricKeyRef};