use super::engine_error;
use crate::prelude::LweCiphertextIndex;
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{LweCiphertextEntity, LweCiphertextVectorEntity};
engine_error! {
LweCiphertextLoadingError for LweCiphertextLoadingEngine @
IndexTooLarge => "The index must not exceed the size of the vector."
}
impl<EngineError: std::error::Error> LweCiphertextLoadingError<EngineError> {
pub fn perform_generic_checks<Ciphertext, CiphertextVector>(
vector: &CiphertextVector,
i: LweCiphertextIndex,
) -> Result<(), Self>
where
Ciphertext: LweCiphertextEntity,
CiphertextVector: LweCiphertextVectorEntity,
{
if i.0 >= vector.lwe_ciphertext_count().0 {
return Err(Self::IndexTooLarge);
}
Ok(())
}
}
pub trait LweCiphertextLoadingEngine<CiphertextVector, Ciphertext>: AbstractEngine
where
Ciphertext: LweCiphertextEntity,
CiphertextVector: LweCiphertextVectorEntity,
{
fn load_lwe_ciphertext(
&mut self,
vector: &CiphertextVector,
i: LweCiphertextIndex,
) -> Result<Ciphertext, LweCiphertextLoadingError<Self::EngineError>>;
unsafe fn load_lwe_ciphertext_unchecked(
&mut self,
vector: &CiphertextVector,
i: LweCiphertextIndex,
) -> Ciphertext;
}