use crate::error::Result;
pub trait Identified {
fn identifier(&self) -> &str;
}
impl<T: Identified + ?Sized> Identified for Box<T> {
fn identifier(&self) -> &str {
(**self).identifier()
}
}
pub trait SymmetricCipher: Identified + Send + Sync {
fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>>;
fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>;
}
pub trait AsymmetricCipher: Identified + Send + Sync {
fn encrypt(&self, plaintext: &[u8], public_key_hex: &str) -> Result<String>;
fn decrypt(&self, ciphertext_hex: &str, private_key_hex: &str) -> Result<Vec<u8>>;
}
pub trait Hasher: Identified + Send + Sync {
fn digest(&self, data: &[u8]) -> Result<Vec<u8>>;
fn digest_hex(&self, data: &[u8]) -> Result<String> {
Ok(crate::internal::hex_encode(&self.digest(data)?))
}
}
pub trait KeyDerivation: Identified + Send + Sync {
fn derive(&self, ikm: &[u8], salt: &[u8], length: usize, info: &[u8]) -> Result<Vec<u8>>;
}
pub trait PasswordBasedKdf: Identified + Send + Sync {
fn derive_from_password(&self, password: &[u8], salt: &[u8], length: usize) -> Result<Vec<u8>>;
}
pub trait Signer: Identified + Send + Sync {
fn sign(&self, message: &[u8], private_key_hex: &str) -> Result<String>;
fn verify(&self, message: &[u8], signature_hex: &str, public_key_hex: &str) -> Result<()>;
}
pub trait KeyAgreement: Identified + Send + Sync {
fn agree(&self, private_key_hex: &str, peer_public_key_hex: &str) -> Result<String>;
}
pub trait KeyEncapsulation: Identified + Send + Sync {
fn generate(&self) -> Result<(String, String)>;
fn encapsulate(&self, public_key_hex: &str) -> Result<(String, String)>;
fn decapsulate(&self, ciphertext_hex: &str, private_key_hex: &str) -> Result<String>;
}