ASN1C C# Runtime Library  7.4
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Properties | List of all members
Asn1BitString Class Reference
Inheritance diagram for Asn1BitString:
Asn1Type Asn1TypeIF

Public Types

enum  StringFormat
 

Public Member Functions

 Asn1BitString ()
 
 Asn1BitString (int numbits_, byte[] data)
 
 Asn1BitString (byte[] data)
 
 Asn1BitString (bool[] bitValues)
 
 Asn1BitString (System.String value_)
 
 Asn1BitString (System.Collections.BitArray bitArray)
 
void BaseDecode (Asn1PerDecodeBuffer buffer, long lower, long upper)
 
virtual void Clear (int bitno)
 
override void Decode (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 
override void Decode (Asn1PerDecodeBuffer buffer)
 
virtual void Decode (Asn1PerDecodeBuffer buffer, long lower, long upper)
 
virtual void DecodeXER (System.String buffer, System.String attrs)
 
override void DecodeXML (System.String buffer, System.String attrs)
 
override int Encode (Asn1BerEncodeBuffer buffer, bool explicitTagging)
 
override void Encode (Asn1PerEncodeBuffer buffer)
 
virtual void Encode (Asn1PerEncodeBuffer buffer, long lower, long upper)
 
override void Encode (Asn1XerEncoder buffer, System.String elemName)
 
virtual void Encode (Asn1XerEncoder buffer, System.String elemName, System.String[] namedbits, int[] namedbitindex)
 
virtual void Encode (Asn1XmlEncoder buffer, System.String elemName, System.String nsPrefix, System.String[] namedbits, int[] namedbitindex)
 
override void Encode (Asn1XmlEncoder buffer, System.String elemName, System.String nsPrefix)
 
override void Encode (Asn1BerOutputStream outs, bool explicitTagging)
 
override void Encode (Asn1PerOutputStream outs)
 
virtual void Encode (Asn1PerOutputStream outs, long lower, long upper)
 
virtual bool Equals (int nbits, byte[] value)
 
override bool Equals (System.Object value)
 
virtual bool Get (int bitno)
 
override int GetHashCode ()
 
virtual bool IsNamedBitStr (System.String buffer)
 
virtual void Set (int bitno, bool value)
 
virtual void Set (int bitno)
 
virtual bool [] ToBoolArray ()
 
virtual System.String ToHexString ()
 
virtual System.IO.Stream toInputStream ()
 
override System.String ToString ()
 
- Public Member Functions inherited from Asn1Type
void _SetKey (byte[] rtkey)
 
virtual void Decode (Asn1BerDecodeBuffer buffer)
 
virtual void Decode (System.Object reader, System.String xmlURI)
 
virtual void Decode (System.Object reader, System.IO.Stream byteStream)
 
virtual void DecodeXML (String buffer, String attrs)
 
virtual int Encode (Asn1BerEncodeBuffer buffer)
 
virtual void Encode (Asn1XerEncoder buffer)
 
virtual void Encode (Asn1XmlEncoder buffer)
 
virtual void Encode (Asn1CerOutputStream outs, bool explicitTagging)
 
virtual void EncodeAttribute (Asn1XmlEncoder buffer, System.String attrName)
 
virtual bool Equals (Asn1Type obj)
 
String GetNonParameterizedTypeName ()
 
virtual void Indent (System.IO.TextWriter outs, int level)
 
virtual bool IsOpenType ()
 
virtual bool MatchTypeName (System.String typeName)
 
virtual void Pdiag (System.String s)
 
virtual void Print (System.IO.TextWriter outs, System.String varName, int level)
 
virtual void Print (System.String varName)
 
void SetNonParameterizedTypeName (String value)
 
virtual void SetOpenType ()
 

Public Attributes

byte [] mValue
 
int numbits
 
bool trimZeroBits
 
- Public Attributes inherited from Asn1Type
const short BIT_STRING = 3
 
const short BMPString = 30
 
const short BOOLEAN = 1
 
const short DATE = 31
 
const short ENUMERATED = 10
 
const short EOC = 0
 
const short EXTERNAL = 8
 
const short GeneralString = 27
 
const short GeneralTime = 24
 
const short GraphicString = 25
 
const short IA5String = 22
 
const short INTEGER = 2
 
const short NULL = 5
 
const short NumericString = 18
 
const short OBJECT_IDENTIFIER = 6
 
const short ObjectDescriptor = 7
 
const short OCTET_STRING = 4
 
const short OpenType = 99
 
const short PrintableString = 19
 
const short REAL = 9
 
const short RELATIVE_OID_IRI = 36
 
const short RelativeOID = 13
 
const short SEQUENCE = 16
 
const short SET = 17
 
const short T61String = TeletexString
 
const short TeletexString = 20
 
const short TIME = 14
 
const short UniversalString = 28
 
const short UTCTime = 23
 
const short UTF8String = 12
 
const short VideotexString = 21
 
const short VisibleString = 26
 

Static Public Attributes

static new readonly Asn1Tag _TAG
 
static StringFormat mStringFormat = StringFormat.HEXBIN
 
- Static Public Attributes inherited from Asn1Type
static readonly Asn1Tag _TAG
 

Protected Member Functions

void BaseDecode (Asn1PerDecodeBuffer buffer)
 
void BaseEncode (Asn1PerEncodeBuffer buffer, long minEncLen)
 
void BaseEncode (Asn1PerEncodeBuffer buffer, long lower, long upper)
 
virtual int GetOerEffectiveMin ()
 

Properties

override int Length [get]
 
virtual bool this[int bitno] [get, set]
 
- Properties inherited from Asn1Type
virtual String AsnTypeName [get]
 
virtual int Length [get]
 

Additional Inherited Members

- Static Public Member Functions inherited from Asn1Type
static void _SetKey2 (byte[] rtkey)
 
static void _SetLicLocation (String path)
 
static Asn1Type Decode (Asn1BerDecodeBuffer buffer, Asn1OpenTypeField openTypeField, bool explicitTag, int implicitLength)
 
static Asn1Type Decode (Asn1PerDecodeBuffer buffer, Asn1OpenTypeField openTypeField)
 
static System.String GetTypeName (short typeCode)
 

Detailed Description

This is a container class for holding the components of an ASN.1 bit string value.

Member Enumeration Documentation

◆ StringFormat

enum StringFormat
strong

Defines possible string fomrats.

The HEX constant describes the string format as hex digit value (e.g. 0123456789ABCDEF).

The BITS constant describes the string format as binary digit value (e.g. only 0 and 1 digits).

The ASN1VALUE constant describes the string format as hex or binary digit value. The binary string value will end with letter 'B' and hex string value will end with letter 'H' (e.g. '0101'B or '11'H ). If the number of bits is less than or equal to 16, than it will be printed as Binary digits, else as Hex digits.

Constructor & Destructor Documentation

◆ Asn1BitString() [1/6]

This constructor creates an empty bit string that can be used in a Decode method call to receive a bit string value.

◆ Asn1BitString() [2/6]

Asn1BitString ( int  numbits_,
byte []  data 
)

This constructor initializes a bit string with the given number of bits and data.

Parameters
numbits_Number of bits
dataBinary bit string contents

◆ Asn1BitString() [3/6]

Asn1BitString ( byte []  data)

This constructor initializes a bit string with the given bytes, using all 8 bits of each byte.

Parameters
dataBinary bit string contents

◆ Asn1BitString() [4/6]

Asn1BitString ( bool []  bitValues)

This constructor initializes a bit string from the given boolean array. Each array position corresponds to a bit in the bit string.

Parameters
bitValuesThe boolean array

◆ Asn1BitString() [5/6]

Asn1BitString ( System.String  value_)

This constructor parses the given ASN.1 value text (either a binary or hex data string) and assigns the values to the internal bit string.

Examples of valid value formats are as follows:

Binary string: '11010010111001'B

Hex string: '0fa56920014abc'H

Parameters
value_The ASN.1 value specification text

References IntHolder.mValue, and Asn1Value.ParseString().

◆ Asn1BitString() [6/6]

Asn1BitString ( System.Collections.BitArray  bitArray)

This constructor initializes a bit string from the given BitSet object.

Parameters
bitArrayC# BitArray object

Member Function Documentation

◆ BaseDecode() [1/2]

void BaseDecode ( Asn1PerDecodeBuffer  buffer)
protected

This method decodes an ASN.1 bit string value using the packed encoding rules (PER). The string is assumed to not contain a size constraint.

This method is guaranteed non-reentrant.

Parameters
bufferDecode message buffer object

References Asn1Type.BIT_STRING, Asn1PerDecodeBuffer.ByteAlign(), Asn1PerDecodeBuffer.DecodeBitsToOctetArray(), Asn1PerDecodeBuffer.DecodeLength(), Diag.Prtln(), and Asn1MessageBufferBase.TypeCode.

◆ BaseDecode() [2/2]

void BaseDecode ( Asn1PerDecodeBuffer  buffer,
long  lower,
long  upper 
)

This method decodes a sized ASN.1 bit string value using the packed encoding rules (PER).

This method is guaranteed non-reentrant.

Parameters
bufferDecode message buffer object
lowerLower bound (inclusive) of size constraint
upperUpper bound (inclusive) of size constraint

References Asn1Type.BIT_STRING, Asn1PerDecodeBuffer.ByteAlign(), Asn1PerDecodeBuffer.DecodeBitsToOctetArray(), Asn1PerDecodeBuffer.DecodeLength(), and Asn1MessageBufferBase.TypeCode.

◆ BaseEncode() [1/2]

void BaseEncode ( Asn1PerEncodeBuffer  buffer,
long  minEncLen 
)
protected

This method encodes the bit string as an unconstrained ASN.1 bit string value using the packed encoding rules (PER). The value to be encoded is stored in the 'numbits' and 'mValue' public member variables within this class. It does not trim trailing zeros. It will add trailing zeros if necessary, in accordance with minEncLen.

This method is guaranteed non-reentrant.

Parameters
bufferEncode message buffer object
minEncLenMinimum number of bits to encode. Trailing zero bits are added, if necessary. Pass 0 if no trailing zero bits should ever be added.

References Asn1PerEncodeBuffer.ByteAlign(), Asn1PerEncodeBuffer.EncodeBits(), Asn1PerEncodeBuffer.EncodeLength(), and Asn1PerEncodeBuffer.EncodeLengthEOM().

◆ BaseEncode() [2/2]

void BaseEncode ( Asn1PerEncodeBuffer  buffer,
long  lower,
long  upper 
)
protected

This method encodes a size-constrained ASN.1 bit string value using the packed encoding rules (PER). The value to be encoded is stored in the 'numbits' and 'mValue' public member variables within this class.

This method is guaranteed non-reentrant.

Parameters
bufferEncode message buffer object
lowerLower bound (inclusive) of size constraint
upperUpper bound (inclusive) of size constraint

References Asn1PerEncodeBuffer.ByteAlign(), Asn1PerEncodeBuffer.EncodeBits(), and Asn1PerEncodeBuffer.EncodeLength().

◆ Clear()

virtual void Clear ( int  bitno)
virtual

This method clears the given bit in the bit string.

Parameters
bitnoThe zero-based index of the bit to clear. The bit numbers start at zero and with the MSB of the first byte and progress from left to right.

References Asn1Type.BIT_STRING, Asn1Tag.Constructed, Asn1EncodeBuffer.Copy(), Asn1BerEncodeBuffer.EncodeTagAndLength(), Asn1Tag.EOC, Asn1BerDecodeContext.Expired(), Asn1Status.INDEFLEN, Asn1BerDecodeBuffer.LastTag, Asn1DecodeBuffer.Read(), and Asn1MessageBufferBase.TypeCode.

◆ Decode() [1/3]

override void Decode ( Asn1BerDecodeBuffer  buffer,
bool  explicitTagging,
int  implicitLength 
)
virtual

This method decodes an ASN.1 bit string value using the BER or DER encoding rules. The UNIVERSAL tag value and length are decoded if explicit tagging is specified.

Parameters
bufferDecode message buffer object
explicitTaggingFlag indicating element is explicitly tagged
implicitLengthLength of contents if implicit

Reimplemented from Asn1Type.

◆ Decode() [2/3]

override void Decode ( Asn1PerDecodeBuffer  buffer)
virtual

This method decodes an ASN.1 bit string value using the packed encoding rules (PER). The string is assumed to not contain a size constraint.

Parameters
bufferDecode message buffer object

Reimplemented from Asn1Type.

◆ Decode() [3/3]

virtual void Decode ( Asn1PerDecodeBuffer  buffer,
long  lower,
long  upper 
)
virtual

This method decodes a sized ASN.1 bit string value using the packed encoding rules (PER).

Parameters
bufferDecode message buffer object
lowerLower bound (inclusive) of size constraint
upperUpper bound (inclusive) of size constraint

◆ DecodeXER()

virtual void DecodeXER ( System.String  buffer,
System.String  attrs 
)
virtual

This method decodes ASN.1 bit string type using the XML encoding rules (XER).

Parameters
bufferString containing data to be decoded
attrsAttributes string from element tag

References Asn1XmlXerEncoder.Copy(), Asn1XmlXerEncoder.EncodeBinStrValue(), Asn1XmlEncoder.EncodeEmptyElement(), Asn1XmlEncoder.EncodeEndElement(), Asn1XmlXerEncoder.EncodeNamedValueElement(), Asn1XmlEncoder.EncodeStartElement(), and Asn1XmlXerEncoder.Indent().

◆ DecodeXML()

override void DecodeXML ( System.String  buffer,
System.String  attrs 
)

This method decodes ASN.1 bit string type using the XML decoding as specified in the XML Schema standard.

Parameters
bufferString containing data to be decoded
attrsAttributes string from element tag

◆ Encode() [1/10]

override int Encode ( Asn1BerEncodeBuffer  buffer,
bool  explicitTagging 
)
virtual

This method encodes an ASN.1 bit string value using the BER or DER encoding rules. The UNIVERSAL tag value and length are encoded if explicit tagging is specified.

Parameters
bufferEncode message buffer object
explicitTaggingFlag indicating explicit tagging should be done
Returns
Length of component or negative status value

Reimplemented from Asn1Type.

◆ Encode() [2/10]

override void Encode ( Asn1PerEncodeBuffer  buffer)
virtual

This method encodes an unconstrained ASN.1 bit string value using the packed encoding rules (PER). The value to be encoded is stored in the 'numbits' and 'mValue' public member variables within this class.

Parameters
bufferEncode message buffer object

Reimplemented from Asn1Type.

◆ Encode() [3/10]

virtual void Encode ( Asn1PerEncodeBuffer  buffer,
long  lower,
long  upper 
)
virtual

This method encodes a size-constrained ASN.1 bit string value using the packed encoding rules (PER). The value to be encoded is stored in the 'numbits' and 'mValue' public member variables within this class.

Parameters
bufferEncode message buffer object
lowerLower bound (inclusive) of size constraint
upperUpper bound (inclusive) of size constraint

References Asn1Type.BIT_STRING.

◆ Encode() [4/10]

override void Encode ( Asn1XerEncoder  buffer,
System.String  elemName 
)
virtual

This method encodes ASN.1 bit string type using the XML encoding rules (XER).

Parameters
bufferEncode message buffer object
elemNameXML element name used to wrap string

Reimplemented from Asn1Type.

◆ Encode() [5/10]

virtual void Encode ( Asn1XerEncoder  buffer,
System.String  elemName,
System.String []  namedbits,
int []  namedbitindex 
)
virtual

This method encodes ASN.1 bit string type using the XML Encoding as specified in the itu-t XER standard.

Parameters
bufferEncode message buffer object
elemNameXML element name used to wrap string
namedbitsArray of named bits
namedbitindexArrat of named bits index values

References Asn1XmlXerEncoder.Copy(), Asn1XmlXerEncoder.EncodeBinStrValue(), Asn1XerEncoder.EncodeEmptyElement(), Asn1XerEncoder.EncodeEndElement(), Asn1XmlXerEncoder.EncodeNamedValueElement(), Asn1XerEncoder.EncodeStartElement(), and Asn1XmlXerEncoder.Indent().

◆ Encode() [6/10]

virtual void Encode ( Asn1XmlEncoder  buffer,
System.String  elemName,
System.String  nsPrefix,
System.String []  namedbits,
int []  namedbitindex 
)
virtual

This method encodes ASN.1 bit string type using the XML Encoding as specified in the XML Schema standard.

Parameters
bufferEncode message buffer object
elemNameXML element name used to wrap string
nsPrefixXML element namespace name
namedbitsArray of named bits
namedbitindexArrat of named bits index values

◆ Encode() [7/10]

override void Encode ( Asn1XmlEncoder  buffer,
System.String  elemName,
System.String  nsPrefix 
)
virtual

This method encodes ASN.1 bit string type using the XML Encoding as specified in the XML Schema standard.

Parameters
bufferEncode message buffer object
elemNameXML element name used to wrap string
nsPrefixXML element namespace name

Reimplemented from Asn1Type.

References Asn1XmlXerEncoder.EncodeBinStrValue(), Asn1XmlEncoder.EncodeEmptyElement(), Asn1XmlEncoder.EncodeEndElement(), Asn1XmlEncoder.EncodeStartElement(), and Asn1XmlXerEncoder.Indent().

◆ Encode() [8/10]

override void Encode ( Asn1BerOutputStream  outs,
bool  explicitTagging 
)
virtual

This method encodes and writes to the stream an ASN.1 bit string value including the UNIVERSAL tag value and length if explicit tagging is specified. This overloaded version uses the Basic Encoding Rules (BER).

Throws, exception thrown by the underlying System.IO.Stream object.

Parameters
outsBER Output Stream object
explicitTaggingFlag indicating explicit tagging should be done
Exceptions
Asn1ExceptionThrown, if operation is failed.

Reimplemented from Asn1Type.

◆ Encode() [9/10]

override void Encode ( Asn1PerOutputStream  outs)
virtual

This method encodes an unconstrained ASN.1 bit string value using the packed encoding rules (PER)into the stream. The value to be encoded is stored in the 'numbits' and 'mValue' public member variables within this class.

Also throws any exception thrown by the underlying Asn1PerOutputStream.

Parameters
outsPER Output Stream object
Exceptions
Asn1ExceptionThrown, if operation is failed.

Reimplemented from Asn1Type.

◆ Encode() [10/10]

virtual void Encode ( Asn1PerOutputStream  outs,
long  lower,
long  upper 
)
virtual

This method encodes a size-constrained ASN.1 bit string value using the packed encoding rules (PER) into the stream. The value to be encoded is stored in the 'numbits' and 'mValue' public member variables within this class.

Also throws any exception thrown by the underlying Asn1PerOutputStream.

Parameters
outsPER Output Stream object
lowerLower bound (inclusive) of size constraint
upperUpper bound (inclusive) of size constraint
Exceptions
Asn1ExceptionThrown, if operation is failed.

References Asn1Tag.PRIM, and Asn1Tag.UNIV.

◆ Equals() [1/2]

virtual bool Equals ( int  nbits,
byte []  value 
)
virtual

This method compares this bit string value to the given value for equality.

This method assumes all unused bits in the last byte are set to zero.

Parameters
nbitsThe number of bits to compare from the byte array.
valueThe byte array to compare with the current Object.
Returns
true if the specified bit array is equal to the current Object; otherwise, false.

◆ Equals() [2/2]

override bool Equals ( System.Object  value)

This method compares this bit string value to the given value for equality. This method assumes all unused bits in the last byte are set to zero.

Parameters
valueThe Object to compare with the current Object. Object should be instance of Asn1BitString.
Returns
true if the specified Object is equal to the current Object; otherwise, false.

References Asn1BitString.mValue, Asn1BitString.numbits, and Asn1Value.StringEqualsBytes().

◆ Get()

virtual bool Get ( int  bitno)
virtual

Gets the value of the bit at a specific position in the bit array.

Parameters
bitnoThe zero-based index of the bit to get. The bit numbers start at zero and with the MSB of the first byte and progress from left to right.
Returns
true if bit is set; otherwise false.

Referenced by Asn1DerEncodeBuffer.TrimBitString().

◆ GetHashCode()

override int GetHashCode ( )

Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.

Returns
A hash code for the current Object.

◆ GetOerEffectiveMin()

virtual int GetOerEffectiveMin ( )
protectedvirtual

Return the lower bound for the OER effective size constraint. When trimZeroBits is set, this controls the trimming done for OER encoding.

Subclasses must override this to return the correct value if the BIT STRING has named bits and the effective size constraint has a lower bound other than zero.

References Asn1XmlXerEncoder.EncodeBinStrValue(), Asn1XerEncoder.EncodeEmptyElement(), Asn1XerEncoder.EncodeEndElement(), Asn1XerEncoder.EncodeStartElement(), and Asn1XmlXerEncoder.Indent().

◆ IsNamedBitStr()

virtual bool IsNamedBitStr ( System.String  buffer)
virtual

This method determines is the input character string represented as named bit string or as bits sequence. It is used for XML decoding.

Parameters
bufferBit string as string to be tested.
Returns
true, if bit string is represented as sequnece of identifiers.

◆ Set() [1/2]

virtual void Set ( int  bitno,
bool  value 
)
virtual

This method sets the given bit number in the bit string with given value. It will expand the existing bit array if it needs to, , setting any added bits, except bitno, to 0.

Parameters
bitnoThe zero-based index of the bit to set. The bit numbers start at zero and with the MSB of the first byte and progress from left to right.
valueThe Boolean value to assign to the bit.

◆ Set() [2/2]

virtual void Set ( int  bitno)
virtual

This method will set the given bit number to one (1). It will expand the existing bit array if it needs to.

Parameters
bitnoThe zero-based index of the bit to set. The bit numbers start at zero and with the MSB of the first byte and progress from left to right.

◆ ToBoolArray()

virtual bool [] ToBoolArray ( )
virtual

This method converts the bit string stored in this object to a boolean array.

Returns
Boolean array value

◆ ToHexString()

virtual System.String ToHexString ( )
virtual

This method will return a hex string representation of the bit string value. The output format is a string of hex bytes with no extra delimiting characters (ex. 0D56EF).

Returns
Stringified representation of the value

References Asn1Util.ToHexString().

◆ toInputStream()

virtual System.IO.Stream toInputStream ( )
virtual

This method will return a byte array input stream representation of the bit string value.

Returns
Reference to System.IO.MemoryStream object

◆ ToString()

override System.String ToString ( )

This method will return a string representation of the bit string value. The output format is a string of hex digits/binary digits according to the value set for mStringFormat variable.

Returns
String representation of the value

References Asn1BerOutputStream.EncodeBitString(), and Diag.Prtln().

Member Data Documentation

◆ _TAG

new readonly Asn1Tag _TAG
static

The _TAG constant describes the universal tag for this data type (UNIVERSAL 3).

Referenced by Asn1CerOutputStream.EncodeBitString().

◆ mStringFormat

StringFormat mStringFormat = StringFormat.HEXBIN
static

The mStringFormat variable can be used to set the string format for print() or event handler calls or toString() functions. The possible options are: HEX, BITS, ASN1VALUE HEX is the default format.

◆ mValue

byte [] mValue

This variable holds the bit string value. These are the bits that are encoded when encode is invoked. It is also where the decoded bit string is stored after a Decode operation.

Referenced by Asn1BitString.Equals().

◆ numbits

int numbits

This variable contains the number of bits in the bit string value.

Referenced by Asn1BitString.Equals(), Asn1DerEncodeBuffer.TrimBitString(), and Asn1BerEncodeBuffer.TrimBitString().

◆ trimZeroBits

bool trimZeroBits

This variable describes whether trailing zero bits should be truncated. This is required when encoding a named bit string using CER, DER, PER, or C-OER. By default, no trimming is done.

Property Documentation

◆ Length

override int Length
get

Gets the length of the BIT STRING in bits.

Value: Number of bits.

◆ this[int bitno]

virtual bool this[int bitno]
getset

Gets or Sets the given bit in the bit string. It will expand the existing bit array if it needs to set the bit value.

Parameters
bitnoThe position of the bit in bit array

Value: true if bit is set; otherwise false.