scrambledb/
data_types.rs

1//! This module defines data structures for indvidual pieces of data in
2//! ScrambleDB.
3//!
4//! A value generally consists of a handle and a data value. Handles can be
5//! identifiable or pseudonymous and either form can also be blinded. Data
6//! values may be in plain text or encrypted and always carry with them the
7//! name of the attribute they belong to in plain text.
8
9use oprf::coprf::coprf_online::{BlindInput, BlindOutput};
10
11/// A type for finalized pseudonyms, i.e. those which have been hardened for
12/// storage by applying a PRP.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
14#[cfg_attr(test, derive(Hash))]
15pub struct FinalizedPseudonym(pub(crate) [u8; 64]);
16/// A type for blinded identifiable handles.
17#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
18pub struct BlindedIdentifiableHandle(pub(crate) BlindInput);
19/// A type for  blinded pseudonymous handles.
20#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
21pub struct BlindedPseudonymizedHandle(pub(crate) BlindOutput);
22
23/// A plain text data value.
24#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
25pub struct DataValue {
26    /// A byte string encoding the data value.
27    pub(crate) value: Vec<u8>,
28    /// The name of the attribute the value belongs to.
29    pub(crate) attribute_name: String,
30}
31/// An encrypted data value.
32#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
33pub struct EncryptedDataValue {
34    /// A byte string encoding the encrypted data value.
35    pub(crate) value: Vec<u8>,
36    /// The name of the attribute the value belongs to.
37    pub(crate) attribute_name: String,
38    /// The encryption level, as understood in terms of [crate::data_transformations::double_hpke].
39    pub(crate) encryption_level: u8,
40}
41
42/// An identifiable piece of data.
43///
44/// `PartialOrd` derive:
45/// When derived on structs, it will produce a lexicographic ordering based on
46/// the top-to-bottom declaration order of the struct’s members.
47#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
48pub struct IdentifiableData {
49    /// A plain text handle.
50    /// Because `PartialOrd` is derived, the order for this struct is
51    /// lexicographical on this handle.
52    pub(crate) handle: String,
53    /// A plain text data value.
54    pub(crate) data_value: DataValue,
55}
56
57/// The blinded version of an identifiable piece of data.
58#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
59pub struct BlindedIdentifiableData {
60    /// A blinded plain text handle.
61    pub(crate) blinded_handle: BlindedIdentifiableHandle,
62    /// An encrypted data value.
63    pub(crate) encrypted_data_value: EncryptedDataValue,
64}
65
66/// The blinded version of a pseudonymized piece of data.
67#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
68pub struct BlindedPseudonymizedData {
69    /// A blinded pseudonymous handle.
70    pub(crate) blinded_handle: BlindedPseudonymizedHandle,
71    /// An encrypted data value.
72    pub(crate) encrypted_data_value: EncryptedDataValue,
73}
74
75/// A pseudonymized piece of data.
76#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
77pub struct PseudonymizedData {
78    /// A pseudonymous handle.
79    pub(crate) handle: FinalizedPseudonym,
80    /// A plain text data value.
81    pub(crate) data_value: DataValue,
82}