#[derive(Debug, Clone, serde::Deserialize)]
pub struct SigningKeyResource {
pub id: String,
#[serde(rename = "type")]
pub resource_type: String,
pub attributes: SigningKeyAttributes,
}
#[derive(Debug, Clone, serde::Deserialize)]
pub struct SigningKeyAttributes {
pub algorithm: String,
#[serde(rename = "publicKey")]
pub public_key: String,
pub status: String,
pub created: chrono::DateTime<chrono::Utc>,
#[serde(default)]
pub retired: Option<chrono::DateTime<chrono::Utc>>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn deserializes_a_retired_key() {
let json = serde_json::json!({
"type": "signing-keys",
"id": "51643eac9777b63a",
"attributes": {
"algorithm": "ed25519",
"publicKey": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"status": "retired",
"created": "2026-01-01T00:00:00Z",
"retired": "2026-06-01T00:00:00Z",
}
});
let key: SigningKeyResource = serde_json::from_value(json).unwrap();
assert_eq!(key.resource_type, "signing-keys");
assert_eq!(key.id, "51643eac9777b63a");
assert_eq!(key.attributes.status, "retired");
assert!(key.attributes.retired.is_some());
}
#[test]
fn an_active_key_omits_retired_entirely_rather_than_nulling_it() {
let json = serde_json::json!({
"type": "signing-keys",
"id": "51643eac9777b63a",
"attributes": {
"algorithm": "ed25519",
"publicKey": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"status": "active",
"created": "2026-01-01T00:00:00Z",
}
});
let key: SigningKeyResource = serde_json::from_value(json).unwrap();
assert_eq!(key.attributes.retired, None);
}
#[test]
fn the_public_key_field_is_camel_case_on_the_wire() {
let json = serde_json::json!({
"type": "signing-keys",
"id": "51643eac9777b63a",
"attributes": {
"algorithm": "ed25519",
"public_key": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"status": "active",
"created": "2026-01-01T00:00:00Z",
}
});
assert!(serde_json::from_value::<SigningKeyResource>(json).is_err());
}
#[test]
fn an_unknown_algorithm_or_status_still_decodes() {
let json = serde_json::json!({
"type": "signing-keys",
"id": "0011223344556677",
"attributes": {
"algorithm": "ml-dsa-44",
"publicKey": "AAAA",
"status": "compromised",
"created": "2026-01-01T00:00:00Z",
}
});
let key: SigningKeyResource = serde_json::from_value(json).unwrap();
assert_eq!(key.attributes.algorithm, "ml-dsa-44");
assert_eq!(key.attributes.status, "compromised");
}
}