diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-10-16 17:56:55 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-10-16 17:56:55 +0700 |
commit | 9e2f7f8885a47761055e1546066799747ff1e1d6 (patch) | |
tree | e428210c79158dbdbd5396b405fbc256de52e936 /crypto/src/asn1/Asn1InputStream.cs | |
parent | Preserve laziness in substreams (diff) | |
download | BouncyCastle.NET-ed25519-9e2f7f8885a47761055e1546066799747ff1e1d6.tar.xz |
BiString updates from bc-java
Diffstat (limited to 'crypto/src/asn1/Asn1InputStream.cs')
-rw-r--r-- | crypto/src/asn1/Asn1InputStream.cs | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/crypto/src/asn1/Asn1InputStream.cs b/crypto/src/asn1/Asn1InputStream.cs index b56d890fa..20734fd59 100644 --- a/crypto/src/asn1/Asn1InputStream.cs +++ b/crypto/src/asn1/Asn1InputStream.cs @@ -95,30 +95,18 @@ namespace Org.BouncyCastle.Asn1 if (!isConstructed) return CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers); - // TODO There are other tags that may be constructed (e.g. BitString) switch (tagNo) { + case Asn1Tags.BitString: + { + return BuildConstructedBitString(ReadVector(defIn)); + } case Asn1Tags.OctetString: { // // yes, people actually do this... // - Asn1EncodableVector v = ReadVector(defIn); - Asn1OctetString[] strings = new Asn1OctetString[v.Count]; - - for (int i = 0; i != strings.Length; i++) - { - Asn1Encodable asn1Obj = v[i]; - if (!(asn1Obj is Asn1OctetString)) - { - throw new Asn1Exception("unknown object encountered in constructed OCTET STRING: " - + Platform.GetTypeName(asn1Obj)); - } - - strings[i] = (Asn1OctetString)asn1Obj; - } - - return new BerOctetString(strings); + return BuildConstructedOctetString(ReadVector(defIn)); } case Asn1Tags.Sequence: return CreateDerSequence(defIn); @@ -227,6 +215,42 @@ namespace Org.BouncyCastle.Asn1 } } + internal virtual DerBitString BuildConstructedBitString(Asn1EncodableVector contentsElements) + { + DerBitString[] bitStrings = new DerBitString[contentsElements.Count]; + + for (int i = 0; i != bitStrings.Length; i++) + { + DerBitString bitString = contentsElements[i] as DerBitString; + if (null == bitString) + throw new Asn1Exception("unknown object encountered in constructed BIT STRING: " + + Platform.GetTypeName(contentsElements[i])); + + bitStrings[i] = bitString; + } + + // TODO Probably ought to be DLBitString + return new BerBitString(bitStrings); + } + + internal virtual Asn1OctetString BuildConstructedOctetString(Asn1EncodableVector contentsElements) + { + Asn1OctetString[] octetStrings = new Asn1OctetString[contentsElements.Count]; + + for (int i = 0; i != octetStrings.Length; i++) + { + Asn1OctetString octetString = contentsElements[i] as Asn1OctetString; + if (null == octetString) + throw new Asn1Exception("unknown object encountered in constructed OCTET STRING: " + + Platform.GetTypeName(contentsElements[i])); + + octetStrings[i] = octetString; + } + + // TODO Probably ought to be DerOctetString (no DLOctetString available) + return new BerOctetString(octetStrings); + } + internal virtual int Limit { get { return limit; } @@ -404,7 +428,7 @@ namespace Org.BouncyCastle.Asn1 switch (tagNo) { case Asn1Tags.BitString: - return DerBitString.FromAsn1Octets(bytes); + return DerBitString.CreatePrimitive(bytes); case Asn1Tags.GeneralizedTime: return new DerGeneralizedTime(bytes); case Asn1Tags.GeneralString: |