summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-05 20:17:54 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-05 20:17:54 +0700
commitd1b9e0282d9c11f98f983d42ec7f8ef367da0546 (patch)
tree07b086ed2cf38400f6b44205f299c91a8d0152f6 /crypto
parentCleanup RevokedStatus (diff)
parentOptimize constructors for Org.BouncyCastle.Asn1.X509.Time and Org.BouncyCastl... (diff)
downloadBouncyCastle.NET-ed25519-d1b9e0282d9c11f98f983d42ec7f8ef367da0546.tar.xz
Merge branch 'Optimize-structures' of github.com:harrison314/bc-csharp
Diffstat (limited to '')
-rw-r--r--crypto/src/asn1/cms/Time.cs8
-rw-r--r--crypto/src/asn1/x509/Time.cs8
2 files changed, 6 insertions, 10 deletions
diff --git a/crypto/src/asn1/cms/Time.cs b/crypto/src/asn1/cms/Time.cs
index 89f1e4dae..67c73285b 100644
--- a/crypto/src/asn1/cms/Time.cs
+++ b/crypto/src/asn1/cms/Time.cs
@@ -35,17 +35,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 1a6ac15c0..8260043aa 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);
             }
         }