concrete_core/specification/engines/
lwe_ciphertext_loading.rs1use super::engine_error;
2use crate::specification::engines::AbstractEngine;
3use crate::specification::entities::{LweCiphertextEntity, LweCiphertextVectorEntity};
4use concrete_commons::parameters::LweCiphertextIndex;
5
6engine_error! {
7 LweCiphertextLoadingError for LweCiphertextLoadingEngine @
8 IndexTooLarge => "The index must not exceed the size of the vector."
9}
10
11impl<EngineError: std::error::Error> LweCiphertextLoadingError<EngineError> {
12 pub fn perform_generic_checks<Ciphertext, CiphertextVector>(
14 vector: &CiphertextVector,
15 i: LweCiphertextIndex,
16 ) -> Result<(), Self>
17 where
18 Ciphertext: LweCiphertextEntity,
19 CiphertextVector: LweCiphertextVectorEntity<KeyDistribution = Ciphertext::KeyDistribution>,
20 {
21 if i.0 >= vector.lwe_ciphertext_count().0 {
22 return Err(Self::IndexTooLarge);
23 }
24 Ok(())
25 }
26}
27
28pub trait LweCiphertextLoadingEngine<CiphertextVector, Ciphertext>: AbstractEngine
37where
38 Ciphertext: LweCiphertextEntity,
39 CiphertextVector: LweCiphertextVectorEntity<KeyDistribution = Ciphertext::KeyDistribution>,
40{
41 fn load_lwe_ciphertext(
43 &mut self,
44 vector: &CiphertextVector,
45 i: LweCiphertextIndex,
46 ) -> Result<Ciphertext, LweCiphertextLoadingError<Self::EngineError>>;
47
48 unsafe fn load_lwe_ciphertext_unchecked(
55 &mut self,
56 vector: &CiphertextVector,
57 i: LweCiphertextIndex,
58 ) -> Ciphertext;
59}