diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-10-18 13:37:35 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-10-18 13:37:35 +0700 |
commit | 460c3811712e3005f268c1d48d582cb65f6e0e78 (patch) | |
tree | 74590d7a229e6370bf7d843a5d6ec4af051d3c6b /crypto/src | |
parent | http://www.bouncycastle.org/jira/browse/BMA-128 (diff) | |
download | BouncyCastle.NET-ed25519-460c3811712e3005f268c1d48d582cb65f6e0e78.tar.xz |
http://www.bouncycastle.org/jira/browse/BMA-113
- Convert DateTime to string using InvariantCulture
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/asn1/DerUTCTime.cs | 4 | ||||
-rw-r--r-- | crypto/src/asn1/cms/Time.cs | 17 | ||||
-rw-r--r-- | crypto/src/asn1/x509/Time.cs | 18 | ||||
-rw-r--r-- | crypto/src/crypto/parameters/SkeinParameters.cs | 3 |
4 files changed, 17 insertions, 25 deletions
diff --git a/crypto/src/asn1/DerUTCTime.cs b/crypto/src/asn1/DerUTCTime.cs index 56fabeb47..ab8ca792d 100644 --- a/crypto/src/asn1/DerUTCTime.cs +++ b/crypto/src/asn1/DerUTCTime.cs @@ -86,10 +86,10 @@ namespace Org.BouncyCastle.Asn1 public DerUtcTime( DateTime time) { - this.time = time.ToString("yyMMddHHmmss") + "Z"; + this.time = time.ToString("yyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"; } - internal DerUtcTime( + internal DerUtcTime( byte[] bytes) { // diff --git a/crypto/src/asn1/cms/Time.cs b/crypto/src/asn1/cms/Time.cs index d113bfa2e..e5730245e 100644 --- a/crypto/src/asn1/cms/Time.cs +++ b/crypto/src/asn1/cms/Time.cs @@ -1,8 +1,6 @@ using System; using System.Globalization; -using Org.BouncyCastle.Asn1; - namespace Org.BouncyCastle.Asn1.Cms { public class Time @@ -20,13 +18,12 @@ namespace Org.BouncyCastle.Asn1.Cms public Time( Asn1Object time) { - if (!(time is DerUtcTime) - && !(time is DerGeneralizedTime)) - { + if (time == null) + throw new ArgumentNullException("time"); + if (!(time is DerUtcTime) && !(time is DerGeneralizedTime)) throw new ArgumentException("unknown object passed to Time"); - } - this.time = time; + this.time = time; } /** @@ -37,7 +34,7 @@ namespace Org.BouncyCastle.Asn1.Cms public Time( DateTime date) { - string d = date.ToString("yyyyMMddHHmmss") + "Z"; + string d = date.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"; int year = int.Parse(d.Substring(0, 4)); @@ -56,14 +53,12 @@ namespace Org.BouncyCastle.Asn1.Cms { if (obj == null || obj is Time) return (Time)obj; - if (obj is DerUtcTime) return new Time((DerUtcTime)obj); - if (obj is DerGeneralizedTime) return new Time((DerGeneralizedTime)obj); - throw new ArgumentException("unknown object in factory: " + obj.GetType().Name, "obj"); + throw new ArgumentException("unknown object in factory: " + obj.GetType().Name, "obj"); } public string TimeString diff --git a/crypto/src/asn1/x509/Time.cs b/crypto/src/asn1/x509/Time.cs index 0f2511e6d..8350339bb 100644 --- a/crypto/src/asn1/x509/Time.cs +++ b/crypto/src/asn1/x509/Time.cs @@ -1,11 +1,12 @@ using System; +using System.Globalization; namespace Org.BouncyCastle.Asn1.X509 { public class Time : Asn1Encodable, IAsn1Choice { - internal Asn1Object time; + private readonly Asn1Object time; public static Time GetInstance( Asn1TaggedObject obj, @@ -19,11 +20,8 @@ namespace Org.BouncyCastle.Asn1.X509 { if (time == null) throw new ArgumentNullException("time"); - if (!(time is DerUtcTime) && !(time is DerGeneralizedTime)) - { throw new ArgumentException("unknown object passed to Time"); - } this.time = time; } @@ -36,9 +34,9 @@ namespace Org.BouncyCastle.Asn1.X509 public Time( DateTime date) { - string d = date.ToString("yyyyMMddHHmmss") + "Z"; + string d = date.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z"; - int year = Int32.Parse(d.Substring(0, 4)); + int year = int.Parse(d.Substring(0, 4)); if (year < 1950 || year > 2049) { @@ -54,13 +52,11 @@ namespace Org.BouncyCastle.Asn1.X509 object obj) { if (obj == null || obj is Time) - return (Time) obj; - + return (Time)obj; if (obj is DerUtcTime) - return new Time((DerUtcTime) obj); - + return new Time((DerUtcTime)obj); if (obj is DerGeneralizedTime) - return new Time((DerGeneralizedTime) obj); + return new Time((DerGeneralizedTime)obj); throw new ArgumentException("unknown object in factory: " + obj.GetType().Name, "obj"); } diff --git a/crypto/src/crypto/parameters/SkeinParameters.cs b/crypto/src/crypto/parameters/SkeinParameters.cs index a4e3e8e2a..9e621c09d 100644 --- a/crypto/src/crypto/parameters/SkeinParameters.cs +++ b/crypto/src/crypto/parameters/SkeinParameters.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Globalization; using System.IO; using Org.BouncyCastle.Utilities; @@ -234,7 +235,7 @@ namespace Org.BouncyCastle.Crypto.Parameters { MemoryStream bout = new MemoryStream(); StreamWriter outBytes = new StreamWriter(bout, System.Text.Encoding.UTF8); - outBytes.Write(date.ToString("YYYYMMDD")); + outBytes.Write(date.ToString("YYYYMMDD", CultureInfo.InvariantCulture)); outBytes.Write(" "); outBytes.Write(emailAddress); outBytes.Write(" "); |