1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! This module defines data structures for indvidual pieces of data in
//! ScrambleDB.
//!
//! A value generally consists of a handle and a data value. Handles can be
//! identifiable or pseudonymous and either form can also be blinded. Data
//! values may be in plain text or encrypted and always carry with them the
//! name of the attribute they belong to in plain text.

use oprf::coprf::coprf_online::{BlindInput, BlindOutput};

/// A type for finalized pseudonyms, i.e. those which have been hardened for
/// storage by applying a PRP.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(test, derive(Hash))]
pub struct FinalizedPseudonym(pub(crate) [u8; 64]);
/// A type for blinded identifiable handles.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct BlindedIdentifiableHandle(pub(crate) BlindInput);
/// A type for  blinded pseudonymous handles.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct BlindedPseudonymizedHandle(pub(crate) BlindOutput);

/// A plain text data value.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct DataValue {
    /// A byte string encoding the data value.
    pub(crate) value: Vec<u8>,
    /// The name of the attribute the value belongs to.
    pub(crate) attribute_name: String,
}
/// An encrypted data value.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct EncryptedDataValue {
    /// A byte string encoding the encrypted data value.
    pub(crate) value: Vec<u8>,
    /// The name of the attribute the value belongs to.
    pub(crate) attribute_name: String,
    /// The encryption level, as understood in terms of [crate::data_transformations::double_hpke].
    pub(crate) encryption_level: u8,
}

/// An identifiable piece of data.
///
/// `PartialOrd` derive:
/// When derived on structs, it will produce a lexicographic ordering based on
/// the top-to-bottom declaration order of the struct’s members.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct IdentifiableData {
    /// A plain text handle.
    /// Because `PartialOrd` is derived, the order for this struct is
    /// lexicographical on this handle.
    pub(crate) handle: String,
    /// A plain text data value.
    pub(crate) data_value: DataValue,
}

/// The blinded version of an identifiable piece of data.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct BlindedIdentifiableData {
    /// A blinded plain text handle.
    pub(crate) blinded_handle: BlindedIdentifiableHandle,
    /// An encrypted data value.
    pub(crate) encrypted_data_value: EncryptedDataValue,
}

/// The blinded version of a pseudonymized piece of data.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct BlindedPseudonymizedData {
    /// A blinded pseudonymous handle.
    pub(crate) blinded_handle: BlindedPseudonymizedHandle,
    /// An encrypted data value.
    pub(crate) encrypted_data_value: EncryptedDataValue,
}

/// A pseudonymized piece of data.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct PseudonymizedData {
    /// A pseudonymous handle.
    pub(crate) handle: FinalizedPseudonym,
    /// A plain text data value.
    pub(crate) data_value: DataValue,
}