use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum SealMode {
ProviderSeal,
OperatorSeal,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
#[non_exhaustive]
pub enum SealFormat {
Jades,
Pades,
Cades,
Xades,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SealCredentialRef {
pub qtsp_id: String,
pub credential_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SealRequest {
pub payload_hash: String,
pub mode: SealMode,
pub key_ref: SealCredentialRef,
pub sig_format: SealFormat,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SealedEnvelope {
pub format: SealFormat,
pub seal_value: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub signing_cert_ref: Option<String>,
pub sealed_at: DateTime<Utc>,
pub placeholder: bool,
}
#[derive(Debug, Clone)]
pub struct SealCapabilities {
pub supported_formats: Vec<SealFormat>,
pub supported_modes: Vec<SealMode>,
}
#[derive(Debug, Clone)]
pub struct SealVerification {
pub valid: bool,
pub placeholder: bool,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn seal_format_serde_round_trips() {
for fmt in [
SealFormat::Jades,
SealFormat::Pades,
SealFormat::Cades,
SealFormat::Xades,
] {
let json = serde_json::to_string(&fmt).unwrap();
let back: SealFormat = serde_json::from_str(&json).unwrap();
assert_eq!(fmt, back);
}
}
#[test]
fn seal_mode_serde_round_trips() {
for mode in [SealMode::ProviderSeal, SealMode::OperatorSeal] {
let json = serde_json::to_string(&mode).unwrap();
let back: SealMode = serde_json::from_str(&json).unwrap();
assert_eq!(mode, back);
}
}
}