Skip to main content

devolutions_crypto/
enums.rs

1use num_enum::{IntoPrimitive, TryFromPrimitive};
2use zeroize::Zeroize;
3
4#[cfg(feature = "fuzz")]
5use arbitrary::Arbitrary;
6
7#[cfg(feature = "wbindgen")]
8use wasm_bindgen::prelude::*;
9
10/// The different data types.
11#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
12#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
13#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
14#[repr(u16)]
15#[derive(Default)]
16pub enum DataType {
17    /// No data type. Only used as a default value.
18    #[default]
19    None = 0,
20    /// A wrapped key.
21    Key = 1,
22    /// A wrapped ciphertext. Can be either symmetric or asymmetric.
23    Ciphertext = 2,
24    /// A wrapped password hash. Used to verify a password.
25    PasswordHash = 3,
26    /// A wrapped share. Used for secret sharing scheme.
27    Share = 4,
28    /// A wrapped key used to sign data.
29    SigningKey = 5,
30    /// A wrapped signature.
31    Signature = 6,
32    /// A wrapped online ciphertext that can be encrypted/decrypted chunk by chunk
33    OnlineCiphertext = 7,
34    /// Serialized key derivation parameters.
35    KeyDerivation = 8,
36    /// A wrapped payload combining key derivation parameters and ciphertext.
37    KdfEncryptedData = 9,
38}
39
40/// The versions of the encryption scheme to use.
41#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
42#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
43#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
44#[repr(u16)]
45#[derive(Default)]
46pub enum CiphertextVersion {
47    /// Uses the latest version.
48    #[default]
49    Latest = 0,
50    /// Uses version 1: AES256-CBC-HMAC-SHA2-256.
51    V1 = 1,
52    /// Uses version 2: XChaCha20-Poly1305.
53    V2 = 2,
54}
55
56/// The versions of the online encryption scheme to use.
57#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
58#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
59#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
60#[repr(u16)]
61#[derive(Default)]
62pub enum OnlineCiphertextVersion {
63    /// Uses the latest version.
64    #[default]
65    Latest = 0,
66    /// Uses version 1: XChaCha20-Poly1305 wrapped in a STREAM construction.
67    V1 = 1,
68}
69
70/// The versions of the password hashing scheme to use.
71#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
72#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
73#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
74#[repr(u16)]
75#[derive(Default)]
76pub enum PasswordHashVersion {
77    /// Uses the latest version.
78    #[default]
79    Latest = 0,
80    /// Uses version 1: PBKDF2-HMAC-SHA2-256.
81    V1 = 1,
82    /// Uses version 2: Argon2id.
83    V2 = 2,
84}
85
86/// The versions of the key scheme to use.
87#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
88#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
89#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
90#[repr(u16)]
91#[derive(Default)]
92pub enum KeyVersion {
93    /// Uses the latest version.
94    #[default]
95    Latest = 0,
96    /// Uses version 1: Curve25519 keys and x25519 key exchange.
97    V1 = 1,
98}
99
100#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
101#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
102#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
103#[repr(u16)]
104#[derive(Default)]
105pub enum SigningKeyVersion {
106    /// Uses the latest version.
107    #[default]
108    Latest = 0,
109    /// Uses version 1: Ed25519.
110    V1 = 1,
111}
112
113/// The versions of the secret sharing scheme to use.
114#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
115#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
116#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
117#[repr(u16)]
118#[derive(Default)]
119pub enum SecretSharingVersion {
120    /// Uses the latest version.
121    #[default]
122    Latest = 0,
123    /// Uses version 1: Shamir Secret Sharing over GF256.
124    V1 = 1,
125}
126
127/// The versions of the secret sharing scheme to use.
128#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
129#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
130#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
131#[repr(u16)]
132#[derive(Default)]
133pub enum SignatureVersion {
134    /// Uses the latest version.
135    #[default]
136    Latest = 0,
137    /// Uses version 1: ed25519
138    V1 = 1,
139}
140
141#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
142#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
143#[repr(u16)]
144#[derive(Default)]
145pub enum CiphertextSubtype {
146    #[default]
147    None = 0,
148    Symmetric = 1,
149    Asymmetric = 2,
150}
151
152#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
153#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
154#[repr(u16)]
155#[derive(Default)]
156pub enum KeySubtype {
157    #[default]
158    None = 0,
159    Private = 1,
160    Public = 2,
161    Pair = 3,
162    Secret = 4,
163}
164
165#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
166#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
167#[repr(u16)]
168#[derive(Default)]
169pub enum PasswordHashSubtype {
170    #[default]
171    None = 0,
172}
173
174#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
175#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
176#[repr(u16)]
177#[derive(Default)]
178pub enum ShareSubtype {
179    #[default]
180    None = 0,
181}
182
183#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
184#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
185#[repr(u16)]
186#[derive(Default)]
187pub enum SignatureSubtype {
188    #[default]
189    None = 0,
190}
191
192/// The versions of the key derivation scheme to use.
193#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
194#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
195#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
196#[repr(u16)]
197#[derive(Default)]
198pub enum KeyDerivationVersion {
199    /// Uses the latest version.
200    #[default]
201    Latest = 0,
202    /// Uses version 1: PBKDF2-HMAC-SHA256.
203    V1 = 1,
204    /// Uses version 2: Argon2id.
205    V2 = 2,
206}
207
208/// The versions of the KDF-encrypt scheme to use.
209#[cfg_attr(feature = "wbindgen", wasm_bindgen())]
210#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
211#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
212#[repr(u16)]
213#[derive(Default)]
214pub enum KdfEncryptedDataVersion {
215    /// Uses the latest version.
216    #[default]
217    Latest = 0,
218    /// Uses version 1.
219    V1 = 1,
220}
221
222#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
223#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
224#[repr(u16)]
225#[derive(Default)]
226pub enum KeyDerivationSubtype {
227    #[default]
228    None = 0,
229}
230
231#[derive(Clone, Copy, PartialEq, Eq, Zeroize, IntoPrimitive, TryFromPrimitive, Debug)]
232#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
233#[repr(u16)]
234#[derive(Default)]
235pub enum KdfEncryptedDataSubtype {
236    #[default]
237    None = 0,
238}