use crate::data::traits::{Encryptable, Encrypted};
use rand_core::{CryptoRng, Rng};
pub fn encrypt<M, R>(message: &M, public_key: &M::PublicKeyType, rng: &mut R) -> M::EncryptedType
where
M: Encryptable,
R: Rng + CryptoRng,
{
message.encrypt(public_key, rng)
}
#[cfg(feature = "elgamal3")]
pub fn decrypt<E>(encrypted: &E, secret_key: &E::SecretKeyType) -> Option<E::UnencryptedType>
where
E: Encrypted,
{
encrypted.decrypt(secret_key)
}
#[cfg(not(feature = "elgamal3"))]
pub fn decrypt<E>(encrypted: &E, secret_key: &E::SecretKeyType) -> E::UnencryptedType
where
E: Encrypted,
{
encrypted.decrypt(secret_key)
}
#[cfg(feature = "offline")]
pub fn encrypt_global<M, R>(
message: &M,
public_key: &M::GlobalPublicKeyType,
rng: &mut R,
) -> M::EncryptedType
where
M: Encryptable,
R: Rng + CryptoRng,
{
message.encrypt_global(public_key, rng)
}
#[cfg(all(feature = "offline", feature = "insecure", feature = "elgamal3"))]
pub fn decrypt_global<E>(
encrypted: &E,
secret_key: &E::GlobalSecretKeyType,
) -> Option<E::UnencryptedType>
where
E: Encrypted,
{
encrypted.decrypt_global(secret_key)
}
#[cfg(all(feature = "offline", feature = "insecure", not(feature = "elgamal3")))]
pub fn decrypt_global<E>(encrypted: &E, secret_key: &E::GlobalSecretKeyType) -> E::UnencryptedType
where
E: Encrypted,
{
encrypted.decrypt_global(secret_key)
}