diff --git a/Changelog.md b/Changelog.md index 254c44bc..4065dd5d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,12 +4,25 @@ Breaking +* Encoding of `x509::Time` values changed since in some cases it needs to + encode as either UTCTime or GeneralizedTime depending on the year. Thus, + there is no simple `encode` method anymore but rather, there now is + `encode_utc_time`, `encode_generalized_time`, or `encode_varied` to make + the choice explicit. [(#84)] + New Bug Fixes +* Stop refusing to make IPv6-only ROAs (this wasn’t on purpose, honest). + [(#82)] +* Empty `IpBlocks` and `AsBlocks` where equal to everything. [(#83)] + Dependencies +[(#82)]: https://github.com/NLnetLabs/rpki-rs/pull/82 +[(#83)]: https://github.com/NLnetLabs/rpki-rs/pull/83 +[(#84)]: https://github.com/NLnetLabs/rpki-rs/pull/84 # 0.7.0 diff --git a/src/crl.rs b/src/crl.rs index 08aae277..dddd1ddc 100644 --- a/src/crl.rs +++ b/src/crl.rs @@ -423,8 +423,8 @@ impl TbsCertList { 1.encode(), // version self.signature.x509_encode(), self.issuer.encode_ref(), - self.this_update.encode(), - self.next_update.encode(), + self.this_update.encode_varied(), + self.next_update.encode_varied(), self.revoked_certs.encode_ref(), encode::sequence_as(Tag::CTX_0, encode::sequence(( @@ -597,7 +597,7 @@ impl CrlEntry { pub fn encode(self) -> impl encode::Values { encode::sequence(( self.user_certificate.encode(), - self.revocation_date.encode(), + self.revocation_date.encode_varied(), )) } } diff --git a/src/manifest.rs b/src/manifest.rs index 4a1aa073..a39fce4d 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -343,8 +343,8 @@ impl ManifestContent { pub fn encode_ref<'a>(&'a self) -> impl encode::Values + 'a { encode::sequence(( self.manifest_number.encode(), - self.this_update.encode(), - self.next_update.encode(), + self.this_update.encode_generalized_time(), + self.next_update.encode_generalized_time(), self.file_hash_alg.encode_oid(), encode::sequence( &self.file_list diff --git a/src/sigobj.rs b/src/sigobj.rs index faa0aef2..5abb0f3a 100644 --- a/src/sigobj.rs +++ b/src/sigobj.rs @@ -307,7 +307,7 @@ impl SignedAttrs { encode::sequence(( oid::SIGNING_TIME.encode(), encode::set( - time.encode(), + time.encode_varied(), ) )) }), diff --git a/src/x509.rs b/src/x509.rs index dc4a08ba..3e643325 100644 --- a/src/x509.rs +++ b/src/x509.rs @@ -683,6 +683,23 @@ impl Time { Ok(()) } } + + pub fn encode_utc_time(self) -> impl encode::Values { + UtcTime(self).encode() + } + + pub fn encode_generalized_time(self) -> impl encode::Values { + GeneralizedTime(self).encode() + } + + pub fn encode_varied(self) -> impl encode::Values { + if self.year() < 1950 || self.year() > 2049 { + (None, Some(self.encode_generalized_time())) + } + else { + (Some(self.encode_utc_time()), None) + } + } } @@ -794,9 +811,34 @@ fn read_four_char(source: &mut S) -> Result { } -//--- PrimitiveContent +//------------ AsUtcTime ----------------------------------------------------- + +pub struct UtcTime(Time); + +impl PrimitiveContent for UtcTime { + const TAG: Tag = Tag::UTC_TIME; + + fn encoded_len(&self, _: Mode) -> usize { + 13 // yyMMddhhmmssZ + } + + fn write_encoded( + &self, _: Mode, target: &mut W + ) -> Result<(), io::Error> { + write!( + target, "{:02}{:02}{:02}{:02}{:02}{:02}Z", + self.0.year() % 100, self.0.month(), self.0.day(), + self.0.hour(), self.0.minute(), self.0.second() + ) + } +} + + +//------------ AsGeneralizedTime --------------------------------------------- + +pub struct GeneralizedTime(Time); -impl PrimitiveContent for Time { +impl PrimitiveContent for GeneralizedTime { const TAG: Tag = Tag::GENERALIZED_TIME; fn encoded_len(&self, _: Mode) -> usize { @@ -881,8 +923,8 @@ impl Validity { pub fn encode(self) -> impl encode::Values { encode::sequence(( - self.not_before.encode(), - self.not_after.encode(), + self.not_before.encode_varied(), + self.not_after.encode_varied(), )) } }