diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-19 13:56:35 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-19 13:56:35 +0700 |
commit | 4d353ca4d930cb985b474aabb498c0c0e88b515c (patch) | |
tree | cde3085bed6c263bf1faaff136ae1a40231aa1a0 /crypto/src/asn1/DerGeneralizedTime.cs | |
parent | Tabs -> spaces (diff) | |
download | BouncyCastle.NET-ed25519-4d353ca4d930cb985b474aabb498c0c0e88b515c.tar.xz |
[BMA-87]
Fix for UTC-type GeneralizedTime instances
Diffstat (limited to 'crypto/src/asn1/DerGeneralizedTime.cs')
-rw-r--r-- | crypto/src/asn1/DerGeneralizedTime.cs | 27 |
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; } |