1#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types, unused_qualifications)]
7
8extern crate base64;
9#[macro_use]
10extern crate lazy_static;
11#[macro_use]
12extern crate log;
13#[macro_use]
14extern crate serde_derive;
15
16#[cfg(any(feature = "client"))]
17#[macro_use]
18extern crate hyper;
19#[cfg(any(feature = "client"))]
20#[macro_use]
21extern crate url;
22
23
24extern crate mime;
25extern crate serde;
26extern crate serde_json;
27
28extern crate futures;
29extern crate chrono;
30extern crate uuid;
31
32use futures::Stream;
33use std::error;
34use std::fmt;
35use std::io::Error;
36
37#[allow(unused_imports)]
38use std::collections::HashMap;
39
40#[cfg(feature = "client")]
41mod mimetypes;
42
43#[deprecated(note = "Import futures directly")]
44pub use futures::Future;
45
46pub const BASE_PATH: &'static str = "/v1";
47pub const API_VERSION: &'static str = "1.0.0";
48
49pub trait Api {
52 type Error;
53
54
55 fn get_issue_certificate_response(&self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error>;
57
58 fn issue_certificate(&self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error>;
60
61
62
63 fn get_fortanix_attestation(&self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error>;
65
66 fn get_target_info(&self) -> Result<models::TargetInfo, Self::Error>;
68
69
70
71 fn get_agent_version(&self) -> Result<models::VersionResponse, Self::Error>;
73
74
75}
76
77pub trait ApiMut {
78 type Error;
79
80
81 fn get_issue_certificate_response(&mut self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error>;
83
84 fn issue_certificate(&mut self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error>;
86
87
88
89 fn get_fortanix_attestation(&mut self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error>;
91
92 fn get_target_info(&mut self) -> Result<models::TargetInfo, Self::Error>;
94
95
96
97 fn get_agent_version(&mut self) -> Result<models::VersionResponse, Self::Error>;
99
100
101}
102
103impl<T, E> Api for T
104where
105T: CertificateApi<Error = E> + EnclaveApi<Error = E> + SystemApi<Error = E> +
106{
107type Error = E;
108
109 fn get_issue_certificate_response(&self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error> {
110 self.get_issue_certificate_response(task_id, )
111 }
112
113 fn issue_certificate(&self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error> {
114 self.issue_certificate(body, )
115 }
116
117
118
119 fn get_fortanix_attestation(&self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error> {
120 self.get_fortanix_attestation(body, )
121 }
122
123 fn get_target_info(&self) -> Result<models::TargetInfo, Self::Error> {
124 self.get_target_info()
125 }
126
127
128
129 fn get_agent_version(&self) -> Result<models::VersionResponse, Self::Error> {
130 self.get_agent_version()
131 }
132
133
134}
135
136impl<T, E> ApiMut for T
137where
138 T: CertificateApiMut<Error = E> + EnclaveApiMut<Error = E> + SystemApiMut<Error = E> +
139{
140 type Error = E;
141
142
143
144
145 fn get_issue_certificate_response(&mut self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error> {
146 self.get_issue_certificate_response(task_id, )
147 }
148
149 fn issue_certificate(&mut self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error> {
150 self.issue_certificate(body, )
151 }
152
153
154
155 fn get_fortanix_attestation(&mut self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error> {
156 self.get_fortanix_attestation(body, )
157 }
158
159 fn get_target_info(&mut self) -> Result<models::TargetInfo, Self::Error> {
160 self.get_target_info()
161 }
162
163
164
165 fn get_agent_version(&mut self) -> Result<models::VersionResponse, Self::Error> {
166 self.get_agent_version()
167 }
168
169
170}
171
172impl<T, E> Api for std::cell::RefCell<T>
173where
174 T: ApiMut<Error = E>,
175{
176 type Error = E;
177
178
179
180 fn get_issue_certificate_response(&self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error> {
181 self.borrow_mut().get_issue_certificate_response(task_id, )
182 }
183
184 fn issue_certificate(&self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error> {
185 self.borrow_mut().issue_certificate(body, )
186 }
187
188
189
190 fn get_fortanix_attestation(&self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error> {
191 self.borrow_mut().get_fortanix_attestation(body, )
192 }
193
194 fn get_target_info(&self) -> Result<models::TargetInfo, Self::Error> {
195 self.borrow_mut().get_target_info()
196 }
197
198
199
200 fn get_agent_version(&self) -> Result<models::VersionResponse, Self::Error> {
201 self.borrow_mut().get_agent_version()
202 }
203
204
205}
206
207pub trait CertificateApi {
208 type Error;
209
210
211 fn get_issue_certificate_response(&self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error>;
213
214 fn issue_certificate(&self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error>;
216
217}
218
219pub trait CertificateApiMut {
220 type Error;
221
222
223 fn get_issue_certificate_response(&mut self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error>;
225
226 fn issue_certificate(&mut self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error>;
228
229}
230
231impl<T, E> CertificateApiMut for T
232where
233 T: CertificateApi<Error = E>,
234{
235 type Error = E;
236
237 fn get_issue_certificate_response(&mut self, task_id: uuid::Uuid) -> Result<models::IssueCertificateResponse, Self::Error> {
238 <T as CertificateApi>::get_issue_certificate_response(self, task_id, )
239 }
240
241 fn issue_certificate(&mut self, body: models::IssueCertificateRequest) -> Result<models::IssueCertificateResponse, Self::Error> {
242 <T as CertificateApi>::issue_certificate(self, body, )
243 }
244
245}
246
247
248pub trait EnclaveApi {
249 type Error;
250
251
252 fn get_fortanix_attestation(&self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error>;
254
255 fn get_target_info(&self) -> Result<models::TargetInfo, Self::Error>;
257
258}
259
260pub trait EnclaveApiMut {
261 type Error;
262
263
264 fn get_fortanix_attestation(&mut self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error>;
266
267 fn get_target_info(&mut self) -> Result<models::TargetInfo, Self::Error>;
269
270}
271
272impl<T, E> EnclaveApiMut for T
273where
274 T: EnclaveApi<Error = E>,
275{
276 type Error = E;
277
278 fn get_fortanix_attestation(&mut self, body: models::GetFortanixAttestationRequest) -> Result<models::GetFortanixAttestationResponse, Self::Error> {
279 <T as EnclaveApi>::get_fortanix_attestation(self, body, )
280 }
281
282 fn get_target_info(&mut self) -> Result<models::TargetInfo, Self::Error> {
283 <T as EnclaveApi>::get_target_info(self, )
284 }
285
286}
287
288
289pub trait SystemApi {
290 type Error;
291
292
293 fn get_agent_version(&self) -> Result<models::VersionResponse, Self::Error>;
295
296}
297
298pub trait SystemApiMut {
299 type Error;
300
301
302 fn get_agent_version(&mut self) -> Result<models::VersionResponse, Self::Error>;
304
305}
306
307impl<T, E> SystemApiMut for T
308where
309 T: SystemApi<Error = E>,
310{
311 type Error = E;
312
313 fn get_agent_version(&mut self) -> Result<models::VersionResponse, Self::Error> {
314 <T as SystemApi>::get_agent_version(self, )
315 }
316
317}
318
319
320
321#[cfg(feature = "client")]
322pub mod client;
323
324#[cfg(feature = "client")]
326pub use self::client::Client;
327
328pub mod models;
329
330pub mod base64_format {
331 use base64::{decode, encode};
334 use serde::de::{Deserialize, Deserializer, Error};
335 use serde::ser::{Serialize, Serializer};
336 use std::ops::{Deref, DerefMut};
337
338 #[derive(Debug, Clone, PartialEq, PartialOrd)]
339 pub struct ByteArray(pub Vec<u8>);
341
342 impl Serialize for ByteArray {
343 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
344 where
345 S: Serializer,
346 {
347 serializer.serialize_str(&encode(&self.0))
348 }
349 }
350
351 impl<'de> Deserialize<'de> for ByteArray {
352 fn deserialize<D>(deserializer: D) -> Result<ByteArray, D::Error>
353 where
354 D: Deserializer<'de>,
355 {
356 let s = String::deserialize(deserializer)?;
357 match decode(&s) {
358 Ok(bin) => Ok(ByteArray(bin)),
359 _ => Err(D::Error::custom("invalid base64")),
360 }
361 }
362 }
363
364 impl Deref for ByteArray {
365 type Target = Vec<u8>;
366 fn deref(&self) -> &Vec<u8> {
367 &self.0
368 }
369 }
370
371 impl DerefMut for ByteArray {
372 fn deref_mut(&mut self) -> &mut Vec<u8> {
373 &mut self.0
374 }
375 }
376
377 impl AsRef<[u8]> for ByteArray {
378 fn as_ref(&self) -> &[u8] {
379 &self.0
380 }
381 }
382}
383pub use base64_format::ByteArray;
384
385
386#[derive(Clone, Debug)]
392pub struct ApiError(pub String);
393
394impl fmt::Display for ApiError {
395 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
396 let debug: &dyn fmt::Debug = self;
397 debug.fmt(f)
398 }
399}
400
401impl error::Error for ApiError {
402 fn description(&self) -> &str {
403 "Failed to produce a valid response."
404 }
405}
406
407impl<'a> From<&'a str> for ApiError {
408 fn from(e: &str) -> Self {
409 ApiError(e.to_string())
410 }
411}
412
413impl From<String> for ApiError {
414 fn from(e: String) -> Self {
415 ApiError(e)
416 }
417}
418
419impl From<serde_json::Error> for ApiError {
420 fn from(e: serde_json::Error) -> Self {
421 ApiError(format!("Response body did not match the schema: {}", e))
422 }
423}