Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize Time encoding. #84

Merged
merged 3 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/crl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ impl TbsCertList<RevokedCertificates> {
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((
Expand Down Expand Up @@ -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(),
))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sigobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl SignedAttrs {
encode::sequence((
oid::SIGNING_TIME.encode(),
encode::set(
time.encode(),
time.encode_varied(),
)
))
}),
Expand Down
50 changes: 46 additions & 4 deletions src/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}


Expand Down Expand Up @@ -794,9 +811,34 @@ fn read_four_char<S: decode::Source>(source: &mut S) -> Result<u32, S::Err> {
}


//--- 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<W: io::Write>(
&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 {
Expand Down Expand Up @@ -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(),
))
}
}
Expand Down