diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-05-26 17:22:18 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-05-26 17:22:18 +0700 |
commit | 81718ad166d0dd458ed070e753d1f4bfcc40593d (patch) | |
tree | 6cd467fa88c23738900b2bf90de73f704fe46298 /crypto/src/asn1/x509 | |
parent | Add KemRecipientInfo (diff) | |
download | BouncyCastle.NET-ed25519-81718ad166d0dd458ed070e753d1f4bfcc40593d.tar.xz |
Auto-adjust DateTime precision for GeneralizedTime in X.509 (and OCSP)
- see https://github.com/bcgit/bc-csharp/issues/474
Diffstat (limited to 'crypto/src/asn1/x509')
-rw-r--r-- | crypto/src/asn1/x509/Rfc5280Asn1Utilities.cs | 14 | ||||
-rw-r--r-- | crypto/src/asn1/x509/Time.cs | 4 |
2 files changed, 16 insertions, 2 deletions
diff --git a/crypto/src/asn1/x509/Rfc5280Asn1Utilities.cs b/crypto/src/asn1/x509/Rfc5280Asn1Utilities.cs new file mode 100644 index 000000000..899236609 --- /dev/null +++ b/crypto/src/asn1/x509/Rfc5280Asn1Utilities.cs @@ -0,0 +1,14 @@ +using System; + +using Org.BouncyCastle.Utilities.Date; + +namespace Org.BouncyCastle.Asn1.X509 +{ + internal class Rfc5280Asn1Utilities + { + internal static DerGeneralizedTime CreateGeneralizedTime(DateTime dateTime) => + new DerGeneralizedTime(DateTimeUtilities.WithPrecisionSecond(dateTime)); + + internal static DerUtcTime CreateUtcTime(DateTime dateTime) => new DerUtcTime(dateTime, 2049); + } +} diff --git a/crypto/src/asn1/x509/Time.cs b/crypto/src/asn1/x509/Time.cs index 99d141c43..e504d0573 100644 --- a/crypto/src/asn1/x509/Time.cs +++ b/crypto/src/asn1/x509/Time.cs @@ -56,11 +56,11 @@ namespace Org.BouncyCastle.Asn1.X509 if (utc.Year < 1950 || utc.Year > 2049) { - m_timeObject = new DerGeneralizedTime(utc); + m_timeObject = Rfc5280Asn1Utilities.CreateGeneralizedTime(utc); } else { - m_timeObject = new DerUtcTime(utc, 2049); + m_timeObject = Rfc5280Asn1Utilities.CreateUtcTime(utc); } } |