From 4af2753c154c2f5cab5a48093a666b275ad81339 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sun, 4 Aug 2019 17:58:40 +0700 Subject: Misc. ASN.1 updates --- crypto/src/asn1/ASN1StreamParser.cs | 26 ++++++++++++---------- crypto/src/asn1/pkcs/SignedData.cs | 4 ++-- crypto/src/asn1/tsp/Accuracy.cs | 4 ++-- crypto/src/asn1/util/Asn1Dump.cs | 4 ++-- crypto/src/asn1/x509/TBSCertList.cs | 4 ++-- crypto/src/asn1/x509/TBSCertificateStructure.cs | 2 +- .../src/asn1/test/DeclarationOfMajorityUnitTest.cs | 20 +++++++---------- 7 files changed, 31 insertions(+), 33 deletions(-) diff --git a/crypto/src/asn1/ASN1StreamParser.cs b/crypto/src/asn1/ASN1StreamParser.cs index 0c6b4413a..3eaaadaee 100644 --- a/crypto/src/asn1/ASN1StreamParser.cs +++ b/crypto/src/asn1/ASN1StreamParser.cs @@ -218,17 +218,19 @@ namespace Org.BouncyCastle.Asn1 } } - internal Asn1EncodableVector ReadVector() - { - Asn1EncodableVector v = new Asn1EncodableVector(); - - IAsn1Convertible obj; - while ((obj = ReadObject()) != null) - { - v.Add(obj.ToAsn1Object()); - } - - return v; - } + internal Asn1EncodableVector ReadVector() + { + IAsn1Convertible obj = ReadObject(); + if (null == obj) + return new Asn1EncodableVector(0); + + Asn1EncodableVector v = new Asn1EncodableVector(); + do + { + v.Add(obj.ToAsn1Object()); + } + while ((obj = ReadObject()) != null); + return v; + } } } diff --git a/crypto/src/asn1/pkcs/SignedData.cs b/crypto/src/asn1/pkcs/SignedData.cs index 3442e671c..ae335103c 100644 --- a/crypto/src/asn1/pkcs/SignedData.cs +++ b/crypto/src/asn1/pkcs/SignedData.cs @@ -66,9 +66,9 @@ namespace Org.BouncyCastle.Asn1.Pkcs // an interesting feature of SignedData is that there appear to be varying implementations... // for the moment we ignore anything which doesn't fit. // - if (o is DerTaggedObject) + if (o is Asn1TaggedObject) { - DerTaggedObject tagged = (DerTaggedObject) o; + Asn1TaggedObject tagged = (Asn1TaggedObject)o; switch (tagged.TagNo) { diff --git a/crypto/src/asn1/tsp/Accuracy.cs b/crypto/src/asn1/tsp/Accuracy.cs index c5a5ca119..9da8f1d68 100644 --- a/crypto/src/asn1/tsp/Accuracy.cs +++ b/crypto/src/asn1/tsp/Accuracy.cs @@ -54,9 +54,9 @@ namespace Org.BouncyCastle.Asn1.Tsp { seconds = (DerInteger) seq[i]; } - else if (seq[i] is DerTaggedObject) + else if (seq[i] is Asn1TaggedObject) { - DerTaggedObject extra = (DerTaggedObject) seq[i]; + Asn1TaggedObject extra = (Asn1TaggedObject)seq[i]; switch (extra.TagNo) { diff --git a/crypto/src/asn1/util/Asn1Dump.cs b/crypto/src/asn1/util/Asn1Dump.cs index 6a21ee2af..019041789 100644 --- a/crypto/src/asn1/util/Asn1Dump.cs +++ b/crypto/src/asn1/util/Asn1Dump.cs @@ -63,7 +63,7 @@ namespace Org.BouncyCastle.Asn1.Utilities } } } - else if (obj is DerTaggedObject) + else if (obj is Asn1TaggedObject) { string tab = indent + Tab; buf.Append(indent); @@ -76,7 +76,7 @@ namespace Org.BouncyCastle.Asn1.Utilities buf.Append("Tagged ["); } - DerTaggedObject o = (DerTaggedObject)obj; + Asn1TaggedObject o = (Asn1TaggedObject)obj; buf.Append(((int)o.TagNo).ToString()); buf.Append(']'); diff --git a/crypto/src/asn1/x509/TBSCertList.cs b/crypto/src/asn1/x509/TBSCertList.cs index 5767a7f21..2b3646052 100644 --- a/crypto/src/asn1/x509/TBSCertList.cs +++ b/crypto/src/asn1/x509/TBSCertList.cs @@ -193,13 +193,13 @@ namespace Org.BouncyCastle.Asn1.X509 } if (seqPos < seq.Count - && !(seq[seqPos] is DerTaggedObject)) + && !(seq[seqPos] is Asn1TaggedObject)) { revokedCertificates = Asn1Sequence.GetInstance(seq[seqPos++]); } if (seqPos < seq.Count - && seq[seqPos] is DerTaggedObject) + && seq[seqPos] is Asn1TaggedObject) { crlExtensions = X509Extensions.GetInstance(seq[seqPos]); } diff --git a/crypto/src/asn1/x509/TBSCertificateStructure.cs b/crypto/src/asn1/x509/TBSCertificateStructure.cs index e69e985f5..da378391e 100644 --- a/crypto/src/asn1/x509/TBSCertificateStructure.cs +++ b/crypto/src/asn1/x509/TBSCertificateStructure.cs @@ -69,7 +69,7 @@ namespace Org.BouncyCastle.Asn1.X509 // // some certficates don't include a version number - we assume v1 // - if (seq[0] is DerTaggedObject) + if (seq[0] is Asn1TaggedObject) { version = DerInteger.GetInstance((Asn1TaggedObject)seq[0], true); } diff --git a/crypto/test/src/asn1/test/DeclarationOfMajorityUnitTest.cs b/crypto/test/src/asn1/test/DeclarationOfMajorityUnitTest.cs index bd1fb5a9e..f9eef4f47 100644 --- a/crypto/test/src/asn1/test/DeclarationOfMajorityUnitTest.cs +++ b/crypto/test/src/asn1/test/DeclarationOfMajorityUnitTest.cs @@ -20,11 +20,11 @@ namespace Org.BouncyCastle.Asn1.Tests DerGeneralizedTime dateOfBirth = new DerGeneralizedTime("20070315173729Z"); DeclarationOfMajority decl = new DeclarationOfMajority(dateOfBirth); - checkConstruction(decl, DeclarationOfMajority.Choice.DateOfBirth, dateOfBirth, -1); + CheckConstruction(decl, DeclarationOfMajority.Choice.DateOfBirth, dateOfBirth, -1); decl = new DeclarationOfMajority(6); - checkConstruction(decl, DeclarationOfMajority.Choice.NotYoungerThan, null, 6); + CheckConstruction(decl, DeclarationOfMajority.Choice.NotYoungerThan, null, 6); decl = DeclarationOfMajority.GetInstance(null); @@ -45,28 +45,24 @@ namespace Org.BouncyCastle.Asn1.Tests } } - private void checkConstruction( + private void CheckConstruction( DeclarationOfMajority decl, DeclarationOfMajority.Choice type, DerGeneralizedTime dateOfBirth, int notYoungerThan) { - checkValues(decl, type, dateOfBirth, notYoungerThan); + CheckValues(decl, type, dateOfBirth, notYoungerThan); decl = DeclarationOfMajority.GetInstance(decl); - checkValues(decl, type, dateOfBirth, notYoungerThan); + CheckValues(decl, type, dateOfBirth, notYoungerThan); - Asn1InputStream aIn = new Asn1InputStream(decl.ToAsn1Object().GetEncoded()); + decl = DeclarationOfMajority.GetInstance(Asn1Object.FromByteArray(decl.GetEncoded())); - DerTaggedObject info = (DerTaggedObject) aIn.ReadObject(); - - decl = DeclarationOfMajority.GetInstance(info); - - checkValues(decl, type, dateOfBirth, notYoungerThan); + CheckValues(decl, type, dateOfBirth, notYoungerThan); } - private void checkValues( + private void CheckValues( DeclarationOfMajority decl, DeclarationOfMajority.Choice type, DerGeneralizedTime dateOfBirth, -- cgit 1.4.1