From 4d353ca4d930cb985b474aabb498c0c0e88b515c Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 19 Feb 2014 13:56:35 +0700 Subject: [BMA-87] Fix for UTC-type GeneralizedTime instances --- crypto/src/asn1/DerGeneralizedTime.cs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'crypto/src') 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; } -- cgit 1.5.1