summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-02-19 13:56:35 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-02-19 13:56:35 +0700
commit4d353ca4d930cb985b474aabb498c0c0e88b515c (patch)
treecde3085bed6c263bf1faaff136ae1a40231aa1a0 /crypto/src
parentTabs -> spaces (diff)
downloadBouncyCastle.NET-ed25519-4d353ca4d930cb985b474aabb498c0c0e88b515c.tar.xz
[BMA-87]
Fix for UTC-type GeneralizedTime instances
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/asn1/DerGeneralizedTime.cs27
1 files changed, 19 insertions, 8 deletions
diff --git a/crypto/src/asn1/DerGeneralizedTime.cs b/crypto/src/asn1/DerGeneralizedTime.cs
index 54fbabbbe..548a268e1 100644
--- a/crypto/src/asn1/DerGeneralizedTime.cs
+++ b/crypto/src/asn1/DerGeneralizedTime.cs
@@ -257,15 +257,26 @@ namespace Org.BouncyCastle.Asn1
             return sb.ToString();
         }
 
-        private DateTime ParseDateString(
-            string	dateStr,
-            string	formatStr,
-            bool	makeUniversal)
+        private DateTime ParseDateString(string	s, string format, bool makeUniversal)
         {
-            DateTime dt = DateTime.ParseExact(
-                dateStr,
-                formatStr,
-                DateTimeFormatInfo.InvariantInfo);
+            /*
+             * NOTE: DateTime.Kind and DateTimeStyles.AssumeUniversal not available in .NET 1.1
+             */
+            DateTimeStyles style = DateTimeStyles.None;
+            if (format.EndsWith("Z"))
+            {
+                try
+                {
+                    style = (DateTimeStyles)Enum.Parse(typeof(DateTimeStyles), "AssumeUniversal");
+                }
+                catch (Exception)
+                {
+                }
+
+                style |= DateTimeStyles.AdjustToUniversal;
+            }
+
+            DateTime dt = DateTime.ParseExact(s, format, DateTimeFormatInfo.InvariantInfo, style);
 
             return makeUniversal ? dt.ToUniversalTime() : dt;
         }