From 8ed01d5f6322defa0b3dbb1e149b05736f54f832 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sat, 11 Mar 2023 23:36:32 +0700 Subject: Refactoring in Asn1 classes --- crypto/src/asn1/tsp/Accuracy.cs | 11 ++++------- crypto/src/asn1/tsp/TSTInfo.cs | 6 ++---- crypto/src/asn1/tsp/TimeStampReq.cs | 18 ++++++++---------- 3 files changed, 14 insertions(+), 21 deletions(-) (limited to 'crypto/src/asn1/tsp') diff --git a/crypto/src/asn1/tsp/Accuracy.cs b/crypto/src/asn1/tsp/Accuracy.cs index 0d64e2dd4..f9cd88014 100644 --- a/crypto/src/asn1/tsp/Accuracy.cs +++ b/crypto/src/asn1/tsp/Accuracy.cs @@ -40,20 +40,17 @@ namespace Org.BouncyCastle.Asn1.Tsp this.micros = micros; } - private Accuracy( - Asn1Sequence seq) + private Accuracy(Asn1Sequence seq) { for (int i = 0; i < seq.Count; ++i) { // seconds - if (seq[i] is DerInteger) + if (seq[i] is DerInteger derInteger) { - seconds = (DerInteger) seq[i]; + seconds = derInteger; } - else if (seq[i] is Asn1TaggedObject) + else if (seq[i] is Asn1TaggedObject extra) { - Asn1TaggedObject extra = (Asn1TaggedObject)seq[i]; - switch (extra.TagNo) { case 0: diff --git a/crypto/src/asn1/tsp/TSTInfo.cs b/crypto/src/asn1/tsp/TSTInfo.cs index c37208d3c..a8e166cbc 100644 --- a/crypto/src/asn1/tsp/TSTInfo.cs +++ b/crypto/src/asn1/tsp/TSTInfo.cs @@ -58,10 +58,8 @@ namespace Org.BouncyCastle.Asn1.Tsp { Asn1Object o = (Asn1Object) e.Current; - if (o is Asn1TaggedObject) + if (o is Asn1TaggedObject tagged) { - DerTaggedObject tagged = (DerTaggedObject) o; - switch (tagged.TagNo) { case 0: @@ -75,7 +73,7 @@ namespace Org.BouncyCastle.Asn1.Tsp } } - if (o is DerSequence) + if (o is Asn1Sequence) { accuracy = Accuracy.GetInstance(o); } diff --git a/crypto/src/asn1/tsp/TimeStampReq.cs b/crypto/src/asn1/tsp/TimeStampReq.cs index 7173172c4..027c0a45b 100644 --- a/crypto/src/asn1/tsp/TimeStampReq.cs +++ b/crypto/src/asn1/tsp/TimeStampReq.cs @@ -24,8 +24,7 @@ namespace Org.BouncyCastle.Asn1.Tsp return new TimeStampReq(Asn1Sequence.GetInstance(obj)); } - private TimeStampReq( - Asn1Sequence seq) + private TimeStampReq(Asn1Sequence seq) { int nbObjects = seq.Count; int seqStart = 0; @@ -39,24 +38,23 @@ namespace Org.BouncyCastle.Asn1.Tsp for (int opt = seqStart; opt < nbObjects; opt++) { // tsaPolicy - if (seq[opt] is DerObjectIdentifier) + if (seq[opt] is DerObjectIdentifier oid) { - tsaPolicy = DerObjectIdentifier.GetInstance(seq[opt]); + tsaPolicy = oid; } // nonce - else if (seq[opt] is DerInteger) + else if (seq[opt] is DerInteger derInteger) { - nonce = DerInteger.GetInstance(seq[opt]); + nonce = derInteger; } // certReq - else if (seq[opt] is DerBoolean) + else if (seq[opt] is DerBoolean derBoolean) { - certReq = DerBoolean.GetInstance(seq[opt]); + certReq = derBoolean; } // extensions - else if (seq[opt] is Asn1TaggedObject) + else if (seq[opt] is Asn1TaggedObject tagged) { - Asn1TaggedObject tagged = (Asn1TaggedObject) seq[opt]; if (tagged.TagNo == 0) { extensions = X509Extensions.GetInstance(tagged, false); -- cgit 1.4.1