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