concrete_core/specification/engines/cleartext_encoding.rs
1use super::engine_error;
2use crate::specification::engines::AbstractEngine;
3use crate::specification::entities::{CleartextEntity, EncoderEntity, PlaintextEntity};
4
5engine_error! {
6    CleartextEncodingError for CleartextEncodingEngine @
7}
8
9/// A trait for engines encoding cleartexts.
10///
11/// # Semantics
12///
13/// This [pure](super#operation-semantics) operation generates a plaintext containing the encoding
14/// of the `cleartext` cleartext, under the `encoder` encoder.
15///
16/// # Formal Definition
17pub trait CleartextEncodingEngine<Encoder, Cleartext, Plaintext>: AbstractEngine
18where
19    Encoder: EncoderEntity,
20    Cleartext: CleartextEntity,
21    Plaintext: PlaintextEntity,
22{
23    /// Encodes a cleartext into a plaintext.
24    fn encode_cleartext(
25        &mut self,
26        encoder: &Encoder,
27        cleartext: &Cleartext,
28    ) -> Result<Plaintext, CleartextEncodingError<Self::EngineError>>;
29
30    /// Unsafely encodes a cleartext into a plaintext.
31    ///
32    /// # Safety
33    /// For the _general_ safety concerns regarding this operation, refer to the different variants
34    /// of [`CleartextEncodingError`]. For safety concerns _specific_ to an
35    /// engine, refer to the implementer safety section.
36    unsafe fn encode_cleartext_unchecked(
37        &mut self,
38        encoder: &Encoder,
39        cleartext: &Cleartext,
40    ) -> Plaintext;
41}