diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-08 13:18:17 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-11-08 13:18:17 +0700 |
commit | 879bb29bb0058a0723326de6edebb201e4cbc0b8 (patch) | |
tree | 089e7769c2342a99dfa7549c57290522f72c451b /crypto/src/asn1/Asn1UtcTime.cs | |
parent | removed unused SecureRandom (diff) | |
download | BouncyCastle.NET-ed25519-879bb29bb0058a0723326de6edebb201e4cbc0b8.tar.xz |
Overhaul GeneralizedTime classes
Diffstat (limited to 'crypto/src/asn1/Asn1UtcTime.cs')
-rw-r--r-- | crypto/src/asn1/Asn1UtcTime.cs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/crypto/src/asn1/Asn1UtcTime.cs b/crypto/src/asn1/Asn1UtcTime.cs index 478b5c485..bd06a3258 100644 --- a/crypto/src/asn1/Asn1UtcTime.cs +++ b/crypto/src/asn1/Asn1UtcTime.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text; using Org.BouncyCastle.Utilities; +using Org.BouncyCastle.Utilities.Date; namespace Org.BouncyCastle.Asn1 { @@ -69,10 +70,7 @@ namespace Org.BouncyCastle.Asn1 public Asn1UtcTime(string timeString) { - if (timeString == null) - throw new ArgumentNullException(nameof(timeString)); - - m_timeString = timeString; + m_timeString = timeString ?? throw new ArgumentNullException(nameof(timeString)); try { @@ -88,8 +86,7 @@ namespace Org.BouncyCastle.Asn1 [Obsolete("Use `Asn1UtcTime(DateTime, int)' instead")] public Asn1UtcTime(DateTime dateTime) { - DateTime utc = dateTime.ToUniversalTime(); - dateTime = new DateTime(utc.Year, utc.Month, utc.Day, utc.Hour, utc.Minute, utc.Second, DateTimeKind.Utc); + dateTime = DateTimeUtilities.WithPrecisionSecond(dateTime.ToUniversalTime()); m_dateTime = dateTime; m_dateTimeLocked = true; @@ -98,8 +95,7 @@ namespace Org.BouncyCastle.Asn1 public Asn1UtcTime(DateTime dateTime, int twoDigitYearMax) { - DateTime utc = dateTime.ToUniversalTime(); - dateTime = new DateTime(utc.Year, utc.Month, utc.Day, utc.Hour, utc.Minute, utc.Second, DateTimeKind.Utc); + dateTime = DateTimeUtilities.WithPrecisionSecond(dateTime.ToUniversalTime()); Validate(dateTime, twoDigitYearMax); @@ -220,11 +216,9 @@ namespace Org.BouncyCastle.Asn1 return DateTime.ParseExact(s, @"yyMMddHHmmss\Z", provider, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal); case 15: - return DateTime.ParseExact(s, @"yyMMddHHmmzzz", provider, - DateTimeStyles.AdjustToUniversal); + return DateTime.ParseExact(s, @"yyMMddHHmmzzz", provider, DateTimeStyles.AdjustToUniversal); case 17: - return DateTime.ParseExact(s, @"yyMMddHHmmsszzz", provider, - DateTimeStyles.AdjustToUniversal); + return DateTime.ParseExact(s, @"yyMMddHHmmsszzz", provider, DateTimeStyles.AdjustToUniversal); default: throw new FormatException(); } |