diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-10-14 23:22:50 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-10-14 23:22:50 +0700 |
commit | 321df9e67ef892f0f3ac4d8bb8740c64e4ad59fb (patch) | |
tree | f2f9bfe30f26283143778ca6a2495e9f5218a5a6 | |
parent | Initial pass at EncodedLength methods (diff) | |
download | BouncyCastle.NET-ed25519-321df9e67ef892f0f3ac4d8bb8740c64e4ad59fb.tar.xz |
SEQUENCE/SET can't contain java null values
-rw-r--r-- | crypto/src/asn1/util/Asn1Dump.cs | 110 |
1 files changed, 37 insertions, 73 deletions
diff --git a/crypto/src/asn1/util/Asn1Dump.cs b/crypto/src/asn1/util/Asn1Dump.cs index 019041789..511bc30af 100644 --- a/crypto/src/asn1/util/Asn1Dump.cs +++ b/crypto/src/asn1/util/Asn1Dump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.IO; using System.Text; @@ -30,9 +29,14 @@ namespace Org.BouncyCastle.Asn1.Utilities Asn1Object obj, StringBuilder buf) { - if (obj is Asn1Sequence) + if (obj is Asn1Null) + { + buf.Append(indent); + buf.Append("NULL"); + buf.Append(NewLine); + } + else if (obj is Asn1Sequence) { - string tab = indent + Tab; buf.Append(indent); if (obj is BerSequence) { @@ -46,21 +50,39 @@ namespace Org.BouncyCastle.Asn1.Utilities { buf.Append("Sequence"); } + buf.Append(NewLine); + Asn1Sequence sequence = (Asn1Sequence)obj; + string elementsIndent = indent + Tab; + + for (int i = 0, count = sequence.Count; i < count; ++i) + { + AsString(elementsIndent, verbose, sequence[i].ToAsn1Object(), buf); + } + } + else if (obj is Asn1Set) + { + buf.Append(indent); + if (obj is BerSet) + { + buf.Append("BER Set"); + } + else if (obj is DerSet) + { + buf.Append("DER Set"); + } + else + { + buf.Append("Set"); + } buf.Append(NewLine); - foreach (Asn1Encodable o in ((Asn1Sequence)obj)) + Asn1Set set = (Asn1Set)obj; + string elementsIndent = indent + Tab; + + for (int i = 0, count = set.Count; i < count; ++i) { - if (o == null || o is Asn1Null) - { - buf.Append(tab); - buf.Append("NULL"); - buf.Append(NewLine); - } - else - { - AsString(tab, verbose, o.ToAsn1Object(), buf); - } + AsString(elementsIndent, verbose, set[i].ToAsn1Object(), buf); } } else if (obj is Asn1TaggedObject) @@ -78,7 +100,7 @@ namespace Org.BouncyCastle.Asn1.Utilities Asn1TaggedObject o = (Asn1TaggedObject)obj; - buf.Append(((int)o.TagNo).ToString()); + buf.Append(o.TagNo.ToString()); buf.Append(']'); if (!o.IsExplicit()) @@ -99,50 +121,6 @@ namespace Org.BouncyCastle.Asn1.Utilities AsString(tab, verbose, o.GetObject(), buf); } } - else if (obj is BerSet) - { - string tab = indent + Tab; - - buf.Append(indent); - buf.Append("BER Set"); - buf.Append(NewLine); - - foreach (Asn1Encodable o in ((Asn1Set)obj)) - { - if (o == null) - { - buf.Append(tab); - buf.Append("NULL"); - buf.Append(NewLine); - } - else - { - AsString(tab, verbose, o.ToAsn1Object(), buf); - } - } - } - else if (obj is DerSet) - { - string tab = indent + Tab; - - buf.Append(indent); - buf.Append("DER Set"); - buf.Append(NewLine); - - foreach (Asn1Encodable o in ((Asn1Set)obj)) - { - if (o == null) - { - buf.Append(tab); - buf.Append("NULL"); - buf.Append(NewLine); - } - else - { - AsString(tab, verbose, o.ToAsn1Object(), buf); - } - } - } else if (obj is DerObjectIdentifier) { buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); @@ -284,20 +262,6 @@ namespace Org.BouncyCastle.Asn1.Utilities + Hex.ToHexString(app.GetContents()) + ")" + NewLine; } - [Obsolete("Use version accepting Asn1Encodable")] - public static string DumpAsString( - object obj) - { - if (obj is Asn1Encodable) - { - StringBuilder buf = new StringBuilder(); - AsString("", false, ((Asn1Encodable)obj).ToAsn1Object(), buf); - return buf.ToString(); - } - - return "unknown object type " + obj.ToString(); - } - /** * dump out a DER object as a formatted string, in non-verbose mode * |