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