use super::engine_error;
use crate::prelude::LweCiphertextIndex;
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{LweCiphertextEntity, LweCiphertextVectorEntity};
engine_error! {
LweCiphertextDiscardingLoadingError for LweCiphertextDiscardingLoadingEngine @
LweDimensionMismatch => "The output and input LWE dimension must be the same.",
IndexTooLarge => "The index must not exceed the size of the vector."
}
impl<EngineError: std::error::Error> LweCiphertextDiscardingLoadingError<EngineError> {
pub fn perform_generic_checks<CiphertextVector, Ciphertext>(
ciphertext: &Ciphertext,
vector: &CiphertextVector,
i: LweCiphertextIndex,
) -> Result<(), Self>
where
Ciphertext: LweCiphertextEntity,
CiphertextVector: LweCiphertextVectorEntity,
{
if ciphertext.lwe_dimension() != vector.lwe_dimension() {
return Err(Self::LweDimensionMismatch);
}
if i.0 >= vector.lwe_ciphertext_count().0 {
return Err(Self::IndexTooLarge);
}
Ok(())
}
}
pub trait LweCiphertextDiscardingLoadingEngine<CiphertextVector, Ciphertext>:
AbstractEngine
where
Ciphertext: LweCiphertextEntity,
CiphertextVector: LweCiphertextVectorEntity,
{
fn discard_load_lwe_ciphertext(
&mut self,
ciphertext: &mut Ciphertext,
vector: &CiphertextVector,
i: LweCiphertextIndex,
) -> Result<(), LweCiphertextDiscardingLoadingError<Self::EngineError>>;
unsafe fn discard_load_lwe_ciphertext_unchecked(
&mut self,
ciphertext: &mut Ciphertext,
vector: &CiphertextVector,
i: LweCiphertextIndex,
);
}