From 2272efd347811a60a08182b723aec528ad6382d0 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Mon, 24 Apr 2023 15:05:20 -0700 Subject: [PATCH] der: adds support for `DateTime::INFINITY` When certificates are burned in hardware, the expiration date could be set to infinity. For example with IDevID when burned to TPM: https://trustedcomputinggroup.org/wp-content/uploads/TPM-2p0-Keys-for-Device-Identity-and-Attestation_v1_r12_pub10082021.pdf#page=55 --- der/src/asn1/generalized_time.rs | 2 +- der/src/datetime.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/der/src/asn1/generalized_time.rs b/der/src/asn1/generalized_time.rs index f7b6f180f..8837917c3 100644 --- a/der/src/asn1/generalized_time.rs +++ b/der/src/asn1/generalized_time.rs @@ -37,7 +37,7 @@ impl GeneralizedTime { const LENGTH: usize = 15; /// Create a [`GeneralizedTime`] from a [`DateTime`]. - pub fn from_date_time(datetime: DateTime) -> Self { + pub const fn from_date_time(datetime: DateTime) -> Self { Self(datetime) } diff --git a/der/src/datetime.rs b/der/src/datetime.rs index de28d53bb..fd09b6855 100644 --- a/der/src/datetime.rs +++ b/der/src/datetime.rs @@ -56,6 +56,18 @@ pub struct DateTime { } impl DateTime { + /// This is the maximum date represented by the [`DateTime`] + /// This corresponds to: 9999-12-31T23:59:59Z + pub const INFINITY: DateTime = DateTime { + year: 9999, + month: 12, + day: 31, + hour: 23, + minutes: 59, + seconds: 59, + unix_duration: MAX_UNIX_DURATION, + }; + /// Create a new [`DateTime`] from the given UTC time components. // TODO(tarcieri): checked arithmetic #[allow(clippy::integer_arithmetic)]