use super::engine_error;
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{
CleartextVectorEntity, EncoderVectorEntity, PlaintextVectorEntity,
};
engine_error! {
CleartextVectorEncodingError for CleartextVectorEncodingEngine @
EncoderCountMismatch => "The encoder count and cleartext count must be the same."
}
impl<EngineError: std::error::Error> CleartextVectorEncodingError<EngineError> {
pub fn perform_generic_checks<EncoderVector, CleartextVector>(
encoder_vector: &EncoderVector,
cleartext_vector: &CleartextVector,
) -> Result<(), Self>
where
EncoderVector: EncoderVectorEntity,
CleartextVector: CleartextVectorEntity,
{
if encoder_vector.encoder_count().0 != cleartext_vector.cleartext_count().0 {
return Err(Self::EncoderCountMismatch);
}
Ok(())
}
}
pub trait CleartextVectorEncodingEngine<EncoderVector, CleartextVector, PlaintextVector>:
AbstractEngine
where
EncoderVector: EncoderVectorEntity,
CleartextVector: CleartextVectorEntity,
PlaintextVector: PlaintextVectorEntity,
{
fn encode_cleartext_vector(
&mut self,
encoder_vector: &EncoderVector,
cleartext_vector: &CleartextVector,
) -> Result<PlaintextVector, CleartextVectorEncodingError<Self::EngineError>>;
unsafe fn encode_cleartext_vector_unchecked(
&mut self,
encoder_vector: &EncoderVector,
cleartext_vector: &CleartextVector,
) -> PlaintextVector;
}