Skip to main content

crypto_service_sdk/types/
meta.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2//! The service description, probes, the algorithm catalogue and the
3//! compliance documents.
4
5use std::collections::BTreeMap;
6
7use serde::{Deserialize, Serialize};
8use serde_json::{Map, Value};
9
10/// The answer of `GET /`: what the service is.
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
12#[non_exhaustive]
13pub struct ServiceInfo {
14    /// A stable identifier of the service (a UUID).
15    pub id: String,
16    /// The service's name.
17    pub title: String,
18    /// What it does.
19    pub description: String,
20    /// More about it.
21    pub details: String,
22    /// The server's version.
23    pub version: String,
24    /// The licence.
25    pub license: String,
26    /// The project's URL.
27    pub url: String,
28}
29
30/// The answer of `GET /health`.
31#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
32#[serde(rename_all = "camelCase")]
33#[non_exhaustive]
34pub struct Health {
35    /// `ok`.
36    pub status: String,
37    /// `200`.
38    pub status_code: u16,
39    /// Seconds since the process started.
40    pub uptime: f64,
41}
42
43/// The answer of `GET /live`.
44#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
45#[non_exhaustive]
46pub struct Liveness {
47    /// `alive`.
48    pub status: String,
49    /// Whole seconds since the process started.
50    pub uptime: u64,
51}
52
53/// The checks behind `GET /ready`.
54#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
55#[serde(rename_all = "camelCase")]
56#[non_exhaustive]
57pub struct ReadinessChecks {
58    /// Whether the server is accepting requests (not draining).
59    pub accepting: bool,
60    /// Whether the key store is usable.
61    pub key_store: bool,
62    /// Checks this version does not name.
63    #[serde(flatten)]
64    pub other: BTreeMap<String, bool>,
65}
66
67/// The answer of `GET /ready`. A server that is not ready answers `503`,
68/// which arrives as an [`Error::Api`](crate::Error::Api).
69#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
70#[non_exhaustive]
71pub struct Readiness {
72    /// `ready` or `not_ready`.
73    pub status: String,
74    /// The individual checks.
75    pub checks: ReadinessChecks,
76}
77
78/// The answer of `GET /v2/algorithms`: algorithm names by category.
79#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81#[non_exhaustive]
82pub struct Algorithms {
83    /// Symmetric encryption.
84    pub encryption: Vec<String>,
85    /// Hash functions.
86    pub hashing: Vec<String>,
87    /// Key derivation.
88    pub kdf: Vec<String>,
89    /// MACs.
90    pub mac: Vec<String>,
91    /// Signatures.
92    pub signing: Vec<String>,
93    /// Key exchange.
94    pub key_exchange: Vec<String>,
95    /// Post-quantum algorithms.
96    pub post_quantum: Vec<String>,
97    /// Categories this version does not name.
98    #[serde(flatten)]
99    pub other: BTreeMap<String, Vec<String>>,
100}
101
102/// One algorithm and its suggested sunset.
103#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
104#[serde(rename_all = "camelCase")]
105#[non_exhaustive]
106pub struct DeprecationEntry {
107    /// The algorithm.
108    pub algorithm: String,
109    /// `symmetric` or `asymmetric`.
110    pub category: String,
111    /// The suggested sunset date.
112    pub sunset_date: String,
113    /// What to move to.
114    pub recommended_migration: String,
115}
116
117/// One package of the cryptographic inventory.
118#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
119#[serde(rename_all = "camelCase")]
120#[non_exhaustive]
121pub struct InventoryEntry {
122    /// The package.
123    pub package: String,
124    /// Its version.
125    pub version: String,
126    /// `implemented`, `partial` or `placeholder`.
127    pub status: String,
128    /// Its FIPS status, as the server states it.
129    pub fips_compliance: String,
130}
131
132/// The answer of `GET /v2/compliance/dora`: a self-reported inventory, not
133/// a compliance assessment under Regulation (EU) 2022/2554.
134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
135#[serde(rename_all = "camelCase")]
136#[non_exhaustive]
137pub struct DoraCompliance {
138    /// `DORA (EU 2022/2554)`.
139    pub standard: String,
140    /// `Article 9 & Article 13`.
141    pub article: String,
142    /// The server's own summary.
143    pub status: String,
144    /// What the document is and is not.
145    pub disclaimer: String,
146    /// When it was produced (RFC 3339).
147    pub timestamp: String,
148    /// Primitives in use.
149    pub active_primitives_count: u64,
150    /// Post-quantum primitives in use.
151    pub post_quantum_primitives_count: u64,
152    /// The post-quantum share of the primitives.
153    pub quantum_resistance_ratio: f64,
154    /// The packages.
155    pub cryptographic_inventory: Vec<InventoryEntry>,
156    /// Suggested sunsets.
157    pub algorithm_deprecation_schedule: Vec<DeprecationEntry>,
158}
159
160/// A name and value pair of a CBOM component.
161#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
162#[non_exhaustive]
163pub struct CbomProperty {
164    /// The property name.
165    pub name: String,
166    /// Its value.
167    pub value: String,
168}
169
170/// One component of the CBOM.
171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
172#[non_exhaustive]
173pub struct CbomComponent {
174    /// The component type, for example `cryptographic-asset`.
175    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
176    pub kind: Option<String>,
177    /// The component's name.
178    #[serde(default, skip_serializing_if = "Option::is_none")]
179    pub name: Option<String>,
180    /// The component's version.
181    #[serde(default, skip_serializing_if = "Option::is_none")]
182    pub version: Option<String>,
183    /// Name and value pairs.
184    #[serde(default, skip_serializing_if = "Option::is_none")]
185    pub properties: Option<Vec<CbomProperty>>,
186    /// The rest of the CycloneDX component.
187    #[serde(flatten)]
188    pub other: Map<String, Value>,
189}
190
191/// The answer of `GET /v2/compliance/cbom`: a CycloneDX 1.6 cryptographic
192/// bill of materials (`application/vnd.cyclonedx+json`), not wrapped in
193/// `data`. Informational input for CRA and DORA work.
194#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
195#[serde(rename_all = "camelCase")]
196#[non_exhaustive]
197pub struct Cbom {
198    /// `CycloneDX`.
199    pub bom_format: String,
200    /// `1.6`.
201    pub spec_version: String,
202    /// `urn:uuid:...`.
203    pub serial_number: String,
204    /// The BOM version.
205    pub version: u64,
206    /// The CycloneDX metadata object.
207    pub metadata: Map<String, Value>,
208    /// The components.
209    pub components: Vec<CbomComponent>,
210    /// The rest of the CycloneDX document.
211    #[serde(flatten)]
212    pub other: Map<String, Value>,
213}