use super::ClientKey;
use crate::RadixCiphertext;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct RadixClientKey {
key: ClientKey,
num_blocks: usize,
}
impl AsRef<ClientKey> for RadixClientKey {
fn as_ref(&self) -> &ClientKey {
&self.key
}
}
impl RadixClientKey {
pub fn new(parameters: concrete_shortint::Parameters, num_blocks: usize) -> Self {
Self {
key: ClientKey::new(parameters),
num_blocks,
}
}
pub fn encrypt(&self, message: u64) -> RadixCiphertext {
self.key.encrypt_radix(message, self.num_blocks)
}
pub fn decrypt(&self, ciphertext: &RadixCiphertext) -> u64 {
self.key.decrypt_radix(ciphertext)
}
pub fn parameters(&self) -> concrete_shortint::Parameters {
self.key.parameters()
}
pub fn encrypt_one_block(&self, message: u64) -> concrete_shortint::Ciphertext {
self.key.encrypt_one_block(message)
}
pub fn decrypt_one_block(&self, ct: &concrete_shortint::Ciphertext) -> u64 {
self.key.decrypt_one_block(ct)
}
}
impl From<(ClientKey, usize)> for RadixClientKey {
fn from((key, num_blocks): (ClientKey, usize)) -> Self {
Self { key, num_blocks }
}
}