1use super::*;
2
3#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
4pub struct CryptoSystemRequest {
5 pub cs_id: u32,
6 #[serde(flatten)]
7 pub cs_op: CryptoSystemRequestOp,
8}
9
10#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
11pub struct CryptoSystemResponse {
12 pub cs_id: u32,
13 #[serde(flatten)]
14 pub cs_op: CryptoSystemResponseOp,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
18#[serde(tag = "cs_op")]
19pub enum CryptoSystemRequestOp {
20 Release,
21 Kind,
22 CachedDh {
23 #[schemars(with = "String")]
24 key: PublicKey,
25 #[schemars(with = "String")]
26 secret: SecretKey,
27 },
28 ComputeDh {
29 #[schemars(with = "String")]
30 key: PublicKey,
31 #[schemars(with = "String")]
32 secret: SecretKey,
33 },
34 GenerateSharedSecret {
35 #[schemars(with = "String")]
36 key: PublicKey,
37 #[schemars(with = "String")]
38 secret: SecretKey,
39 #[serde(with = "as_human_base64")]
40 #[schemars(with = "String")]
41 domain: Vec<u8>,
42 },
43 RandomBytes {
44 len: u32,
45 },
46 SharedSecretLength,
47 NonceLength,
48 HashDigestLength,
49 PublicKeyLength,
50 SecretKeyLength,
51 SignatureLength,
52 DefaultSaltLength,
53 AeadOverhead,
54 CheckSharedSecret {
55 #[schemars(with = "String")]
56 secret: SharedSecret,
57 },
58 CheckNonce {
59 #[schemars(with = "String")]
60 nonce: Nonce,
61 },
62 CheckHashDigest {
63 #[schemars(with = "String")]
64 digest: HashDigest,
65 },
66 CheckPublicKey {
67 #[schemars(with = "String")]
68 key: PublicKey,
69 },
70 CheckSecretKey {
71 #[schemars(with = "String")]
72 key: SecretKey,
73 },
74 CheckSignature {
75 #[schemars(with = "String")]
76 signature: Signature,
77 },
78 HashPassword {
79 #[serde(with = "as_human_base64")]
80 #[schemars(with = "String")]
81 password: Vec<u8>,
82 #[serde(with = "as_human_base64")]
83 #[schemars(with = "String")]
84 salt: Vec<u8>,
85 },
86 VerifyPassword {
87 #[serde(with = "as_human_base64")]
88 #[schemars(with = "String")]
89 password: Vec<u8>,
90 password_hash: String,
91 },
92 DeriveSharedSecret {
93 #[serde(with = "as_human_base64")]
94 #[schemars(with = "String")]
95 password: Vec<u8>,
96 #[serde(with = "as_human_base64")]
97 #[schemars(with = "String")]
98 salt: Vec<u8>,
99 },
100 RandomNonce,
101 RandomSharedSecret,
102 GenerateKeyPair,
103 GenerateHash {
104 #[serde(with = "as_human_base64")]
105 #[schemars(with = "String")]
106 data: Vec<u8>,
107 },
108 ValidateKeyPair {
109 #[schemars(with = "String")]
110 key: PublicKey,
111 #[schemars(with = "String")]
112 secret: SecretKey,
113 },
114 ValidateHash {
115 #[serde(with = "as_human_base64")]
116 #[schemars(with = "String")]
117 data: Vec<u8>,
118 #[schemars(with = "String")]
119 hash_digest: HashDigest,
120 },
121 Sign {
122 #[schemars(with = "String")]
123 key: PublicKey,
124 #[schemars(with = "String")]
125 secret: SecretKey,
126 #[serde(with = "as_human_base64")]
127 #[schemars(with = "String")]
128 data: Vec<u8>,
129 },
130 Verify {
131 #[schemars(with = "String")]
132 key: PublicKey,
133 #[serde(with = "as_human_base64")]
134 #[schemars(with = "String")]
135 data: Vec<u8>,
136 #[schemars(with = "String")]
137 signature: Signature,
138 },
139 DecryptAead {
140 #[serde(with = "as_human_base64")]
141 #[schemars(with = "String")]
142 body: Vec<u8>,
143 #[schemars(with = "String")]
144 nonce: Nonce,
145 #[schemars(with = "String")]
146 shared_secret: SharedSecret,
147 #[serde(with = "as_human_opt_base64")]
148 #[schemars(with = "Option<String>")]
149 associated_data: Option<Vec<u8>>,
150 },
151 EncryptAead {
152 #[serde(with = "as_human_base64")]
153 #[schemars(with = "String")]
154 body: Vec<u8>,
155 #[schemars(with = "String")]
156 nonce: Nonce,
157 #[schemars(with = "String")]
158 shared_secret: SharedSecret,
159 #[serde(with = "as_human_opt_base64")]
160 #[schemars(with = "Option<String>")]
161 associated_data: Option<Vec<u8>>,
162 },
163 CryptNoAuth {
164 #[serde(with = "as_human_base64")]
165 #[schemars(with = "String")]
166 body: Vec<u8>,
167 #[schemars(with = "String")]
168 nonce: Nonce,
169 #[schemars(with = "String")]
170 shared_secret: SharedSecret,
171 },
172}
173#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
174#[serde(tag = "cs_op")]
175pub enum CryptoSystemResponseOp {
176 InvalidId,
177 Release,
178 Kind {
179 #[schemars(with = "String")]
180 value: CryptoKind,
181 },
182 CachedDh {
183 #[serde(flatten)]
184 #[schemars(with = "ApiResult<String>")]
185 result: ApiResultWithString<SharedSecret>,
186 },
187 ComputeDh {
188 #[serde(flatten)]
189 #[schemars(with = "ApiResult<String>")]
190 result: ApiResultWithString<SharedSecret>,
191 },
192 GenerateSharedSecret {
193 #[serde(flatten)]
194 #[schemars(with = "ApiResult<String>")]
195 result: ApiResultWithString<SharedSecret>,
196 },
197 RandomBytes {
198 #[serde(with = "as_human_base64")]
199 #[schemars(with = "String")]
200 value: Vec<u8>,
201 },
202 SharedSecretLength {
203 value: u32,
204 },
205 NonceLength {
206 value: u32,
207 },
208 HashDigestLength {
209 value: u32,
210 },
211 PublicKeyLength {
212 value: u32,
213 },
214 SecretKeyLength {
215 value: u32,
216 },
217 SignatureLength {
218 value: u32,
219 },
220 DefaultSaltLength {
221 value: u32,
222 },
223 AeadOverhead {
224 value: u32,
225 },
226 CheckSharedSecret {
227 #[serde(flatten)]
228 result: ApiResult<()>,
229 },
230 CheckNonce {
231 #[serde(flatten)]
232 result: ApiResult<()>,
233 },
234 CheckHashDigest {
235 #[serde(flatten)]
236 result: ApiResult<()>,
237 },
238 CheckPublicKey {
239 #[serde(flatten)]
240 result: ApiResult<()>,
241 },
242 CheckSecretKey {
243 #[serde(flatten)]
244 result: ApiResult<()>,
245 },
246 CheckSignature {
247 #[serde(flatten)]
248 result: ApiResult<()>,
249 },
250 HashPassword {
251 #[serde(flatten)]
252 result: ApiResult<String>,
253 },
254 VerifyPassword {
255 #[serde(flatten)]
256 result: ApiResult<bool>,
257 },
258 DeriveSharedSecret {
259 #[serde(flatten)]
260 #[schemars(with = "ApiResult<String>")]
261 result: ApiResultWithString<SharedSecret>,
262 },
263 RandomNonce {
264 #[schemars(with = "String")]
265 value: Nonce,
266 },
267 RandomSharedSecret {
268 #[schemars(with = "String")]
269 value: SharedSecret,
270 },
271 GenerateKeyPair {
272 #[schemars(with = "String")]
273 value: KeyPair,
274 },
275 GenerateHash {
276 #[schemars(with = "String")]
277 value: HashDigest,
278 },
279 ValidateKeyPair {
280 #[serde(flatten)]
281 result: ApiResult<bool>,
282 },
283 ValidateHash {
284 #[serde(flatten)]
285 result: ApiResult<bool>,
286 },
287 Sign {
288 #[serde(flatten)]
289 #[schemars(with = "ApiResult<String>")]
290 result: ApiResultWithString<Signature>,
291 },
292 Verify {
293 #[serde(flatten)]
294 result: ApiResult<bool>,
295 },
296 DecryptAead {
297 #[serde(flatten)]
298 #[schemars(with = "ApiResult<String>")]
299 result: ApiResultWithVecU8,
300 },
301 EncryptAead {
302 #[serde(flatten)]
303 #[schemars(with = "ApiResult<String>")]
304 result: ApiResultWithVecU8,
305 },
306 CryptNoAuth {
307 #[serde(flatten)]
308 #[schemars(with = "ApiResult<String>")]
309 result: ApiResultWithVecU8,
310 },
311}