From d41d40e206e002efec9fe96afd89b2dbd9ffdebf Mon Sep 17 00:00:00 2001 From: Jozef Gajdos Date: Tue, 2 Aug 2022 10:39:55 +0200 Subject: Optimize constructors for Org.BouncyCastle.Asn1.X509.Time and Org.BouncyCastle.Asn1.Cms.Time. --- crypto/src/asn1/cms/Time.cs | 8 +++----- crypto/src/asn1/x509/Time.cs | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/crypto/src/asn1/cms/Time.cs b/crypto/src/asn1/cms/Time.cs index 52fb4f937..47e284e69 100644 --- a/crypto/src/asn1/cms/Time.cs +++ b/crypto/src/asn1/cms/Time.cs @@ -36,17 +36,15 @@ namespace Org.BouncyCastle.Asn1.Cms public Time( DateTime date) { - string d = date.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"; + DateTime d = date.ToUniversalTime(); - int year = int.Parse(d.Substring(0, 4)); - - if (year < 1950 || year > 2049) + if (d.Year < 1950 || d.Year > 2049) { time = new DerGeneralizedTime(d); } else { - time = new DerUtcTime(d.Substring(2)); + time = new DerUtcTime(d); } } diff --git a/crypto/src/asn1/x509/Time.cs b/crypto/src/asn1/x509/Time.cs index efdf63850..26c972904 100644 --- a/crypto/src/asn1/x509/Time.cs +++ b/crypto/src/asn1/x509/Time.cs @@ -35,17 +35,15 @@ namespace Org.BouncyCastle.Asn1.X509 */ public Time(DateTime date) { - string d = date.ToUniversalTime().ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"; + DateTime d = date.ToUniversalTime(); - int year = int.Parse(d.Substring(0, 4)); - - if (year < 1950 || year > 2049) + if (d.Year < 1950 || d.Year > 2049) { time = new DerGeneralizedTime(d); } else { - time = new DerUtcTime(d.Substring(2)); + time = new DerUtcTime(d); } } -- cgit 1.4.1