diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-25 23:32:48 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-25 23:32:48 +0700 |
commit | 5cfc4eae7e78d0299f5ebf47b45109805221a2d6 (patch) | |
tree | 91ae5b56a4ab011b38433066fba923e4a53ec3ae /crypto/src/asn1/cms | |
parent | Refactor Pqc test configs (diff) | |
download | BouncyCastle.NET-ed25519-5cfc4eae7e78d0299f5ebf47b45109805221a2d6.tar.xz |
Add Asn1UtcTime and use
Diffstat (limited to 'crypto/src/asn1/cms')
-rw-r--r-- | crypto/src/asn1/cms/Time.cs | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/crypto/src/asn1/cms/Time.cs b/crypto/src/asn1/cms/Time.cs index e8a6905ad..89f1e4dae 100644 --- a/crypto/src/asn1/cms/Time.cs +++ b/crypto/src/asn1/cms/Time.cs @@ -22,7 +22,7 @@ namespace Org.BouncyCastle.Asn1.Cms { if (time == null) throw new ArgumentNullException("time"); - if (!(time is DerUtcTime) && !(time is Asn1GeneralizedTime)) + if (!(time is Asn1UtcTime) && !(time is Asn1GeneralizedTime)) throw new ArgumentException("unknown object passed to Time"); this.time = time; @@ -49,15 +49,16 @@ namespace Org.BouncyCastle.Asn1.Cms } } - public static Time GetInstance( - object obj) + public static Time GetInstance(object obj) { - if (obj == null || obj is Time) - return (Time)obj; - if (obj is DerUtcTime) - return new Time((DerUtcTime)obj); - if (obj is Asn1GeneralizedTime) - return new Time((Asn1GeneralizedTime)obj); + if (obj == null) + return null; + if (obj is Time time) + return time; + if (obj is Asn1UtcTime utcTime) + return new Time(utcTime); + if (obj is Asn1GeneralizedTime generalizedTime) + return new Time(generalizedTime); throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj"); } @@ -66,14 +67,10 @@ namespace Org.BouncyCastle.Asn1.Cms { get { - if (time is DerUtcTime) - { - return ((DerUtcTime)time).AdjustedTimeString; - } - else - { - return ((Asn1GeneralizedTime)time).GetTime(); - } + if (time is Asn1UtcTime utcTime) + return utcTime.AdjustedTimeString; + + return ((Asn1GeneralizedTime)time).GetTime(); } } @@ -83,10 +80,8 @@ namespace Org.BouncyCastle.Asn1.Cms { try { - if (time is DerUtcTime) - { - return ((DerUtcTime)time).ToAdjustedDateTime(); - } + if (time is Asn1UtcTime utcTime) + return utcTime.ToAdjustedDateTime(); return ((Asn1GeneralizedTime)time).ToDateTime(); } |