diff --git a/src/commons/api/admin.rs b/src/commons/api/admin.rs index faa702d4..e4da6041 100644 --- a/src/commons/api/admin.rs +++ b/src/commons/api/admin.rs @@ -314,6 +314,7 @@ impl RepositoryUpdate { #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[allow(clippy::large_enum_variant)] +#[serde(tag = "t", content = "c")] pub enum RepositoryContact { Embedded(RepoInfo), Rfc8181(rfc8183::RepositoryResponse), @@ -432,6 +433,7 @@ impl Eq for TaCertDetails {} /// for resource provisioning requests (RFC6492). #[derive(Clone, Debug, Deserialize, Display, Eq, PartialEq, Serialize)] #[allow(clippy::large_enum_variant)] +#[serde(tag = "t", content = "c")] pub enum ParentCaContact { #[display(fmt = "This CA is a TA")] Ta(TaCertDetails), diff --git a/src/commons/api/ca.rs b/src/commons/api/ca.rs index 0c74b973..2a35f3d0 100644 --- a/src/commons/api/ca.rs +++ b/src/commons/api/ca.rs @@ -216,10 +216,10 @@ impl From<&IssuedCert> for ReplacedObject { } } -impl From<&Roa> for ReplacedObject { - fn from(r: &Roa) -> Self { - let revocation = Revocation::from(r); - let hash = HexEncodedHash::from_content(r.to_captured().as_slice()); +impl From<&CurrentObject> for ReplacedObject { + fn from(current: &CurrentObject) -> Self { + let revocation = Revocation::from(current); + let hash = current.to_hex_hash(); ReplacedObject { revocation, hash } } } diff --git a/src/commons/api/mod.rs b/src/commons/api/mod.rs index c3864aff..ac9833d9 100644 --- a/src/commons/api/mod.rs +++ b/src/commons/api/mod.rs @@ -59,6 +59,10 @@ impl Base64 { pub fn size(&self) -> usize { self.0.len() } + + pub fn as_bytes(&self) -> &[u8] { + self.0.as_ref() + } } impl AsRef for Base64 { diff --git a/src/commons/api/provisioning.rs b/src/commons/api/provisioning.rs index ff88cd49..9628846d 100644 --- a/src/commons/api/provisioning.rs +++ b/src/commons/api/provisioning.rs @@ -368,6 +368,10 @@ impl IssuanceResponse { /// See: https://tools.ietf.org/html/rfc6492#section-3.4.1 #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] pub struct RequestResourceLimit { + #[serde( + deserialize_with = "ext_serde::de_as_blocks_opt", + serialize_with = "ext_serde::ser_as_blocks_opt" + )] asn: Option, #[serde( diff --git a/src/commons/remote/rfc8183.rs b/src/commons/remote/rfc8183.rs index f4a82447..f3fa97bd 100644 --- a/src/commons/remote/rfc8183.rs +++ b/src/commons/remote/rfc8183.rs @@ -11,6 +11,7 @@ use std::{fmt, io}; use base64::DecodeError; use bcder::decode; use bytes::Bytes; +use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use rpki::uri; use rpki::x509; @@ -628,7 +629,7 @@ impl RepositoryResponse { //------------ ServiceUri ---------------------------------------------------- /// The service URI where a child or publisher needs to send its -#[derive(Clone, Debug, Deserialize, Eq, Serialize, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub enum ServiceUri { Https(uri::Https), Http(String), @@ -638,8 +639,7 @@ impl TryFrom for ServiceUri { type Error = Error; fn try_from(value: String) -> Result { - if value.starts_with("http://") { - // TODO: Check a bit better? It will blow up when the uri is used.. + if value.to_lowercase().starts_with("http://") { Ok(ServiceUri::Http(value)) } else { Ok(ServiceUri::Https(uri::Https::from_str(&value)?)) @@ -656,6 +656,25 @@ impl fmt::Display for ServiceUri { } } +impl Serialize for ServiceUri { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + self.to_string().serialize(serializer) + } +} + +impl<'de> Deserialize<'de> for ServiceUri { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let string = String::deserialize(deserializer)?; + ServiceUri::try_from(string).map_err(de::Error::custom) + } +} + //------------ Error --------------------------------------------------------- #[derive(Debug, Display)] diff --git a/src/commons/util/ext_serde.rs b/src/commons/util/ext_serde.rs index 2486e4f0..fbca496c 100644 --- a/src/commons/util/ext_serde.rs +++ b/src/commons/util/ext_serde.rs @@ -2,7 +2,7 @@ use base64; use bytes::Bytes; use log::LevelFilter; -use rpki::resources::IpBlocks; +use rpki::resources::{AsBlocks, IpBlocks}; use serde::de; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::str::FromStr; @@ -26,6 +26,31 @@ where base64::encode(b).serialize(s) } +//------------ AsBlocks ------------------------------------------------------ + +pub fn ser_as_blocks_opt(blocks: &Option, s: S) -> Result +where + S: Serializer, +{ + match blocks { + None => "none".serialize(s), + Some(blocks) => blocks.to_string().serialize(s), + } +} + +pub fn de_as_blocks_opt<'de, D>(d: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let string = String::deserialize(d)?; + if string.as_str() == "none" { + return Ok(None); + } + let blocks = AsBlocks::from_str(string.as_str()).map_err(de::Error::custom)?; + + Ok(Some(blocks)) +} + //------------ IpBlocks ------------------------------------------------------ pub fn de_ip_blocks_4<'de, D>(d: D) -> Result diff --git a/src/daemon/ca/certauth.rs b/src/daemon/ca/certauth.rs index 44688596..f48b14e1 100644 --- a/src/daemon/ca/certauth.rs +++ b/src/daemon/ca/certauth.rs @@ -188,11 +188,11 @@ impl Aggregate for CertAuth { self.children.get_mut(&child).unwrap().set_id_cert(cert) } - EvtDet::ChildUpdatedResources(child, resources, grace) => self + EvtDet::ChildUpdatedResources(child, resources) => self .children .get_mut(&child) .unwrap() - .set_resources(resources, grace), + .set_resources(resources), EvtDet::ChildRemoved(child) => { self.children.remove(&child); diff --git a/src/daemon/ca/child.rs b/src/daemon/ca/child.rs index d56faa8e..f2d9c419 100644 --- a/src/daemon/ca/child.rs +++ b/src/daemon/ca/child.rs @@ -29,7 +29,6 @@ impl LastResponse {} pub struct ChildDetails { id_cert: Option, resources: ResourceSet, - shrink_pending: Option