Asn1BitString Class Reference
Public Types | |
enum | StringFormat |
Public Member Functions | |
Asn1BitString (System.Collections.BitArray bitArray) | |
Asn1BitString (System.String value_) | |
Asn1BitString (bool[] bitValues) | |
Asn1BitString (byte[] data) | |
Asn1BitString (int numbits_, byte[] data) | |
Asn1BitString () | |
virtual void | Clear (int bitno) |
virtual void | Decode (Asn1JsonDecodeBuffer buffer) |
void | Decode (Asn1MderDecodeBuffer buffer, int length) |
virtual void | Decode (Asn1PerDecodeBuffer buffer, long lower, long upper) |
override void | Decode (Asn1PerDecodeBuffer buffer) |
override void | Decode (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength) |
virtual void | DecodeXER (System.String buffer, System.String attrs) |
override void | DecodeXML (System.String buffer, System.String attrs) |
virtual void | Encode (Asn1PerOutputStream outs, long lower, long upper) |
override void | Encode (Asn1PerOutputStream outs) |
override void | Encode (Asn1BerOutputStream outs, bool explicitTagging) |
virtual void | Encode (Asn1JsonOutputStream outstream) |
override void | Encode (Asn1XmlEncoder buffer, System.String elemName, System.String nsPrefix) |
virtual void | Encode (Asn1XmlEncoder buffer, System.String elemName, System.String nsPrefix, System.String[] namedbits, int[] namedbitindex) |
virtual void | Encode (Asn1XerEncoder buffer, System.String elemName, System.String[] namedbits, int[] namedbitindex) |
override void | Encode (Asn1XerEncoder buffer, System.String elemName) |
void | Encode (Asn1MderOutputStream outs, int length) |
virtual void | Encode (Asn1PerEncodeBuffer buffer, long lower, long upper) |
override void | Encode (Asn1PerEncodeBuffer buffer) |
override int | Encode (Asn1BerEncodeBuffer buffer, bool explicitTagging) |
override bool | Equals (System.Object value) |
virtual bool | Equals (int nbits, byte[] value) |
virtual bool | Get (int bitno) |
override int | GetHashCode () |
virtual bool | IsNamedBitStr (System.String buffer) |
virtual void | Set (int bitno) |
virtual void | Set (int bitno, bool value) |
virtual bool[] | ToBoolArray () |
virtual System.String | ToHexString () |
virtual System.IO.Stream | toInputStream () |
override System.String | ToString () |
Public Attributes | |
byte[] | mValue |
int | numbits |
bool | trimZeroBits |
Static Public Attributes | |
static new readonly Asn1Tag | _TAG |
static StringFormat | mStringFormat = StringFormat.HEXBIN |
Properties | |
override int | Length [get] |
virtual bool | this [int bitno] [get, set] |
Detailed Description
This is a container class for holding the components of an ASN.1 bit string value.
Member Enumeration Documentation
enum StringFormat |
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 | ( | ) |
This constructor creates an empty bit string that can be used in a Decode method call to receive a bit string value.
Asn1BitString | ( | int | numbits_, | |
byte[] | data | |||
) |
This constructor initializes a bit string with the given number of bits and data.
- Parameters:
-
numbits_ Number of bits data Binary bit string contents
Asn1BitString | ( | byte[] | data | ) |
This constructor initializes a bit string with the given bytes, using all 8 bits of each byte.
- Parameters:
-
data Binary bit string contents
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:
-
bitValues The boolean array
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
Asn1BitString | ( | System.Collections.BitArray | bitArray | ) |
This constructor initializes a bit string from the given BitSet object.
- Parameters:
-
bitArray C# BitArray object
Member Function Documentation
virtual void Clear | ( | int | bitno | ) | [virtual] |
This method clears the given bit in the bit string.
- Parameters:
-
bitno The 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.
virtual void Decode | ( | Asn1JsonDecodeBuffer | buffer | ) | [virtual] |
Decode ASN.1 bit string from JSON.
void Decode | ( | Asn1MderDecodeBuffer | buffer, | |
int | length | |||
) |
Decode a BIT STRING from the MDER encoding into this object. Exactly the given length of bits will be decoded.
- Parameters:
-
length This should be 8, 16, or 32, as these are the only lengths MDER supports. However, this is not checked here as it should be able to be checked at code generation time.
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:
-
buffer Decode message buffer object lower Lower bound (inclusive) of size constraint upper Upper bound (inclusive) of size constraint
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:
-
buffer Decode message buffer object
Reimplemented from Asn1Type.
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:
-
buffer Decode message buffer object explicitTagging Flag indicating element is explicitly tagged implicitLength Length of contents if implicit
Reimplemented from Asn1Type.
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:
-
buffer String containing data to be decoded attrs Attributes string from element tag
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:
-
buffer String containing data to be decoded attrs Attributes string from element tag
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:
-
outs PER Output Stream object lower Lower bound (inclusive) of size constraint upper Upper bound (inclusive) of size constraint
- Exceptions:
-
Asn1Exception Thrown, if operation is failed.
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:
-
outs PER Output Stream object
- Exceptions:
-
Asn1Exception Thrown, if operation is failed.
Reimplemented from Asn1Type.
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:
-
outs BER Output Stream object explicitTagging Flag indicating explicit tagging should be done
- Exceptions:
-
Asn1Exception Thrown, if operation is failed.
Reimplemented from Asn1Type.
virtual void Encode | ( | Asn1JsonOutputStream | outstream | ) | [virtual] |
Encode this bit string to JSON.
- Parameters:
-
outstream
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:
-
buffer Encode message buffer object elemName XML element name used to wrap string nsPrefix XML element namespace name
Reimplemented from Asn1Type.
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:
-
buffer Encode message buffer object elemName XML element name used to wrap string nsPrefix XML element namespace name namedbits Array of named bits namedbitindex Arrat of named bits index values
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:
-
buffer Encode message buffer object elemName XML element name used to wrap string namedbits Array of named bits namedbitindex Arrat of named bits index values
override void Encode | ( | Asn1XerEncoder | buffer, | |
System.String | elemName | |||
) | [virtual] |
This method encodes ASN.1 bit string type using the XML encoding rules (XER).
- Parameters:
-
buffer Encode message buffer object elemName XML element name used to wrap string
Reimplemented from Asn1Type.
void Encode | ( | Asn1MderOutputStream | outs, | |
int | length | |||
) |
Encode this BIT STRING into the MDER encoding. The length of this BIT STRING must match the given length.
- Parameters:
-
length This should be 8, 16, or 32, as these are the only lengths MDER supports. However, this is not checked here as it should be able to be checked at code generation time. We only check here that the actual and given lengths match.
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:
-
buffer Encode message buffer object lower Lower bound (inclusive) of size constraint upper Upper bound (inclusive) of size constraint
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:
-
buffer Encode message buffer object
Reimplemented from Asn1Type.
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:
-
buffer Encode message buffer object explicitTagging Flag indicating explicit tagging should be done
- Returns:
- Length of component or negative status value
Reimplemented from Asn1Type.
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:
-
value The 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
.
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:
-
nbits The number of bits to compare from the byte array. value The byte array to compare with the current Object.
- Returns:
true
if the specified bit array is equal to the current Object; otherwise,false
.
virtual bool Get | ( | int | bitno | ) | [virtual] |
Gets the value of the bit at a specific position in the bit array.
- Parameters:
-
bitno The 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; otherwisefalse
.
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.
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:
-
buffer Bit string as string to be tested.
- Returns:
- true, if bit string is represented as sequnece of identifiers.
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:
-
bitno The 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.
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.
- Parameters:
-
bitno The 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. value The Boolean value to assign to the bit.
virtual bool [] ToBoolArray | ( | ) | [virtual] |
This method converts the bit string stored in this object to a boolean array.
- Returns:
- Boolean array value
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
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
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
Member Data Documentation
The _TAG
constant describes the universal tag for this data type (UNIVERSAL 3).
Reimplemented from Asn1Type.
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.
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.
int numbits |
This variable contains the number of bits in the bit string value.
bool trimZeroBits |
This variable tells whether or not to trim zero bits at the end of a bit string encoding. In CER and DER, it is required to trim trailing zero bits if the bit string is a Named Bit String.
Property Documentation
override int Length [get] |
virtual bool this[int bitno] [get, set] |
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:
-
bitno The position of the bit in bit array
Value:
true if bit is set; otherwise false.