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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use crate::prelude::*;

pub use holochain_integrity_types::x_salsa20_poly1305::*;

#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, SerializedBytes)]
pub struct XSalsa20Poly1305SharedSecretExport {
    pub sender: X25519PubKey,
    pub recipient: X25519PubKey,
    pub key_ref: crate::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef,
}

impl XSalsa20Poly1305SharedSecretExport {
    pub fn new(
        sender: X25519PubKey,
        recipient: X25519PubKey,
        key_ref: crate::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef,
    ) -> Self {
        Self {
            sender,
            recipient,
            key_ref,
        }
    }

    pub fn as_sender_ref(&self) -> &X25519PubKey {
        &self.sender
    }

    pub fn as_recipient_ref(&self) -> &X25519PubKey {
        &self.recipient
    }

    pub fn as_key_ref_ref(&self) -> &crate::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef {
        &self.key_ref
    }
}

#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, SerializedBytes)]
pub struct XSalsa20Poly1305SharedSecretIngest {
    pub recipient: X25519PubKey,
    pub sender: X25519PubKey,
    pub encrypted_data: crate::x_salsa20_poly1305::encrypted_data::XSalsa20Poly1305EncryptedData,
    pub key_ref: Option<crate::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef>,
}

impl XSalsa20Poly1305SharedSecretIngest {
    pub fn new(
        recipient: X25519PubKey,
        sender: X25519PubKey,
        encrypted_data: crate::x_salsa20_poly1305::encrypted_data::XSalsa20Poly1305EncryptedData,
        key_ref: Option<crate::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef>,
    ) -> Self {
        Self {
            recipient,
            sender,
            encrypted_data,
            key_ref,
        }
    }

    pub fn as_recipient_ref(&self) -> &X25519PubKey {
        &self.recipient
    }

    pub fn as_sender_ref(&self) -> &X25519PubKey {
        &self.sender
    }

    pub fn as_encrypted_data_ref(
        &self,
    ) -> &crate::x_salsa20_poly1305::encrypted_data::XSalsa20Poly1305EncryptedData {
        &self.encrypted_data
    }

    pub fn as_key_ref_ref(
        &self,
    ) -> &Option<crate::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef> {
        &self.key_ref
    }
}

#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, SerializedBytes)]
pub struct XSalsa20Poly1305Encrypt {
    pub key_ref: crate::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef,
    pub data: crate::x_salsa20_poly1305::data::XSalsa20Poly1305Data,
}

impl XSalsa20Poly1305Encrypt {
    pub fn new(
        key_ref: crate::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef,
        data: crate::x_salsa20_poly1305::data::XSalsa20Poly1305Data,
    ) -> Self {
        Self { key_ref, data }
    }

    pub fn as_key_ref_ref(&self) -> &crate::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef {
        &self.key_ref
    }

    pub fn as_data_ref(&self) -> &crate::x_salsa20_poly1305::data::XSalsa20Poly1305Data {
        &self.data
    }
}

#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, SerializedBytes)]
pub struct X25519XSalsa20Poly1305Encrypt {
    pub sender: X25519PubKey,
    pub recipient: X25519PubKey,
    pub data: crate::x_salsa20_poly1305::data::XSalsa20Poly1305Data,
}

impl X25519XSalsa20Poly1305Encrypt {
    pub fn new(
        sender: X25519PubKey,
        recipient: X25519PubKey,
        data: crate::x_salsa20_poly1305::data::XSalsa20Poly1305Data,
    ) -> Self {
        Self {
            sender,
            recipient,
            data,
        }
    }

    pub fn as_sender_ref(&self) -> &X25519PubKey {
        &self.sender
    }

    pub fn as_recipient_ref(&self) -> &X25519PubKey {
        &self.recipient
    }

    pub fn as_data_ref(&self) -> &XSalsa20Poly1305Data {
        &self.data
    }
}