From 1ec8938ad4d5810c3f50957b85c7fe9a1e6a00b7 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 18 Nov 2021 16:31:12 +0700 Subject: ASN:1 tagged object parser updates from bc-java --- crypto/src/asn1/DerBitString.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'crypto/src/asn1/DerBitString.cs') diff --git a/crypto/src/asn1/DerBitString.cs b/crypto/src/asn1/DerBitString.cs index 4596fbbc8..d3836b740 100644 --- a/crypto/src/asn1/DerBitString.cs +++ b/crypto/src/asn1/DerBitString.cs @@ -9,8 +9,8 @@ using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1 { public class DerBitString - : DerStringBase - { + : DerStringBase, Asn1BitStringParser + { internal class Meta : Asn1UniversalType { internal static readonly Asn1UniversalType Instance = new Meta(); @@ -309,6 +309,25 @@ namespace Org.BouncyCastle.Asn1 return thisLastDer == thatLastDer; } + public Stream GetBitStream() + { + return new MemoryStream(contents, 1, contents.Length - 1, false); + } + + public Stream GetOctetStream() + { + int padBits = contents[0] & 0xFF; + if (0 != padBits) + throw new IOException("expected octet-aligned bitstring, but found padBits: " + padBits); + + return GetBitStream(); + } + + public Asn1BitStringParser Parser + { + get { return this; } + } + public override string GetString() { byte[] str = GetDerEncoded(); -- cgit 1.4.1