1use crate::error::Result;
9
10pub trait Identified {
12 fn identifier(&self) -> &str;
13}
14
15impl<T: Identified + ?Sized> Identified for Box<T> {
16 fn identifier(&self) -> &str {
17 (**self).identifier()
18 }
19}
20
21pub trait SymmetricCipher: Identified + Send + Sync {
23 fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>>;
24
25 fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>;
26}
27
28pub trait AsymmetricCipher: Identified + Send + Sync {
30 fn encrypt(&self, plaintext: &[u8], public_key_hex: &str) -> Result<String>;
32
33 fn decrypt(&self, ciphertext_hex: &str, private_key_hex: &str) -> Result<Vec<u8>>;
34}
35
36pub trait Hasher: Identified + Send + Sync {
38 fn digest(&self, data: &[u8]) -> Result<Vec<u8>>;
39
40 fn digest_hex(&self, data: &[u8]) -> Result<String> {
42 Ok(crate::internal::hex_encode(&self.digest(data)?))
43 }
44}
45
46pub trait KeyDerivation: Identified + Send + Sync {
48 fn derive(&self, ikm: &[u8], salt: &[u8], length: usize, info: &[u8]) -> Result<Vec<u8>>;
52}
53
54pub trait PasswordBasedKdf: Identified + Send + Sync {
56 fn derive_from_password(&self, password: &[u8], salt: &[u8], length: usize) -> Result<Vec<u8>>;
58}
59
60pub trait Signer: Identified + Send + Sync {
63 fn sign(&self, message: &[u8], private_key_hex: &str) -> Result<String>;
65
66 fn verify(&self, message: &[u8], signature_hex: &str, public_key_hex: &str) -> Result<()>;
68}
69
70pub trait KeyAgreement: Identified + Send + Sync {
72 fn agree(&self, private_key_hex: &str, peer_public_key_hex: &str) -> Result<String>;
77}
78
79pub trait KeyEncapsulation: Identified + Send + Sync {
82 fn generate(&self) -> Result<(String, String)>;
84
85 fn encapsulate(&self, public_key_hex: &str) -> Result<(String, String)>;
87
88 fn decapsulate(&self, ciphertext_hex: &str, private_key_hex: &str) -> Result<String>;
92}