use crate::factors::TranscryptionInfo;
use crate::factors::{PseudonymizationInfo, RerandomizeFactor};
use rand_core::{CryptoRng, Rng};
pub trait Encryptable: Sized {
type EncryptedType: Encrypted<UnencryptedType = Self>;
type PublicKeyType;
#[cfg(feature = "offline")]
type GlobalPublicKeyType;
fn encrypt<R>(&self, public_key: &Self::PublicKeyType, rng: &mut R) -> Self::EncryptedType
where
R: Rng + CryptoRng;
#[cfg(feature = "offline")]
fn encrypt_global<R>(
&self,
public_key: &Self::GlobalPublicKeyType,
rng: &mut R,
) -> Self::EncryptedType
where
R: Rng + CryptoRng;
}
pub trait Encrypted: Sized {
type UnencryptedType: Encryptable<EncryptedType = Self>;
type SecretKeyType;
#[cfg(all(feature = "offline", feature = "insecure"))]
type GlobalSecretKeyType;
#[cfg(feature = "elgamal3")]
fn decrypt(&self, secret_key: &Self::SecretKeyType) -> Option<Self::UnencryptedType>;
#[cfg(not(feature = "elgamal3"))]
fn decrypt(&self, secret_key: &Self::SecretKeyType) -> Self::UnencryptedType;
#[cfg(all(feature = "offline", feature = "insecure", feature = "elgamal3"))]
fn decrypt_global(
&self,
secret_key: &Self::GlobalSecretKeyType,
) -> Option<Self::UnencryptedType>;
#[cfg(all(feature = "offline", feature = "insecure", not(feature = "elgamal3")))]
fn decrypt_global(&self, secret_key: &Self::GlobalSecretKeyType) -> Self::UnencryptedType;
#[cfg(feature = "elgamal3")]
fn rerandomize<R>(&self, rng: &mut R) -> Self
where
R: Rng + CryptoRng;
#[cfg(not(feature = "elgamal3"))]
fn rerandomize<R>(
&self,
public_key: &<Self::UnencryptedType as Encryptable>::PublicKeyType,
rng: &mut R,
) -> Self
where
R: Rng + CryptoRng;
#[cfg(feature = "elgamal3")]
fn rerandomize_known(&self, factor: &RerandomizeFactor) -> Self;
#[cfg(not(feature = "elgamal3"))]
fn rerandomize_known(
&self,
public_key: &<Self::UnencryptedType as Encryptable>::PublicKeyType,
factor: &RerandomizeFactor,
) -> Self;
}
pub trait Pseudonymizable: Encrypted {
fn pseudonymize(&self, info: &PseudonymizationInfo) -> Self;
}
pub trait Rekeyable: Encrypted {
type RekeyInfo;
fn rekey(&self, info: &Self::RekeyInfo) -> Self;
}
pub trait Transcryptable: Encrypted {
fn transcrypt(&self, info: &TranscryptionInfo) -> Self;
}
#[cfg(feature = "batch")]
pub trait HasStructure {
type Structure: PartialEq + std::fmt::Debug;
fn structure(&self) -> Self::Structure;
}
#[cfg(feature = "batch")]
pub trait BatchEncryptable: Encryptable + Clone {
fn preprocess_batch(
items: &[Self],
) -> Result<Vec<Self>, crate::transcryptor::batch::BatchError>;
}