Skip to main content

concrete_core/specification/
key_kinds.rs

1//! This module contains types to manage the different kinds of secret keys.
2#[cfg(feature = "__commons_serialization")]
3use serde::{Deserialize, Serialize};
4
5/// This type is a marker for keys using binary elements as scalar.
6#[derive(Clone, Debug, PartialEq, Eq)]
7#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
8pub struct BinaryKeyKind;
9/// This type is a marker for keys using ternary elements as scalar.
10#[derive(Clone, Debug, PartialEq, Eq)]
11#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
12pub struct TernaryKeyKind;
13/// This type is a marker for keys using normaly sampled elements as scalar.
14#[derive(Clone, Debug, PartialEq, Eq)]
15#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
16pub struct GaussianKeyKind;
17/// This type is a marker for keys using uniformly sampled elements as scalar.
18#[derive(Clone, Debug, PartialEq, Eq)]
19#[cfg_attr(feature = "__commons_serialization", derive(Serialize, Deserialize))]
20pub struct UniformKeyKind;
21
22#[derive(Clone)]
23/// This type is a marker for keys filled with zeros (used for testing)
24pub struct ZeroKeyKind;
25
26/// In concrete, secret keys can be based on different kinds of scalar values (put aside the
27/// data type eventually used to store it in memory). This trait is implemented by marker types,
28/// which are used to specify in the type system, what kind of keys we are currently using.
29pub trait KeyKind: seal::SealedKeyKind + Sync + Clone {}
30
31impl KeyKind for BinaryKeyKind {}
32impl KeyKind for TernaryKeyKind {}
33impl KeyKind for GaussianKeyKind {}
34impl KeyKind for UniformKeyKind {}
35impl KeyKind for ZeroKeyKind {}
36
37mod seal {
38    pub trait SealedKeyKind {}
39    impl SealedKeyKind for super::BinaryKeyKind {}
40    impl SealedKeyKind for super::TernaryKeyKind {}
41    impl SealedKeyKind for super::GaussianKeyKind {}
42    impl SealedKeyKind for super::UniformKeyKind {}
43    impl SealedKeyKind for super::ZeroKeyKind {}
44}