use super::ClientKey;
use crate::CrtCiphertext;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct CrtClientKey {
key: ClientKey,
moduli: Vec<u64>,
}
impl AsRef<ClientKey> for CrtClientKey {
fn as_ref(&self) -> &ClientKey {
&self.key
}
}
impl CrtClientKey {
pub fn new(parameters: concrete_shortint::Parameters, moduli: Vec<u64>) -> Self {
Self {
key: ClientKey::new(parameters),
moduli,
}
}
pub fn encrypt(&self, message: u64) -> CrtCiphertext {
self.key.encrypt_crt(message, self.moduli.clone())
}
pub fn decrypt(&self, ciphertext: &CrtCiphertext) -> u64 {
self.key.decrypt_crt(ciphertext)
}
pub fn parameters(&self) -> concrete_shortint::Parameters {
self.key.parameters()
}
}
impl From<(ClientKey, Vec<u64>)> for CrtClientKey {
fn from((key, moduli): (ClientKey, Vec<u64>)) -> Self {
Self { key, moduli }
}
}