|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.asn1.ASN1Object | +--iaik.asn1.BIT_STRING
This class implements the native ASN.1 type "BIT STRING".
BIT STRING is a simple ASN.1 string type identified by the UNIVERSAL TAG number 3. An ASN.1 BIT STRING object may represent any arbitrary string of bits.
The value of a BIT STRING object is DER encoded by first specifying the number of bits not used in the last of the following contents octets.
For instance: DER encoding the bit string '011010001'B will need two content octets:
01101000 10000000
(hexadecimal 68 80); seven bits of the last octet
are not used leading to the following DER encoding (hexadecimal):
03 03 07 68 80where the first octet is the identifier octet: <03> for BIT STRING; the following length octet indicates the number (3) of content octets: <03>; and the first of the final contents octets indicates that seven bits of the last content octet will not be used: <07> <68> <80>
When creating a new ASN.1 BIT_STRING object, the value to be represented may be supplied in one of three formats:
BIT_STRING(byte[] array, int bitsNotValid)
constructor. Otherwise the encoding
only will give the expected result when there are no unused bits in the last
content octet.
Consider, for instance, the bit string '011010001'B example from above: when
supplying the value as binary string or boolean array, the number (7) of unused
bits automatically is calculated giving the right encoding of 03 03 07 68 80
:
BIT_STRING bit_string = new BIT_STRING("011010001"); //or BIT_STRING bit_string = new BIT_STRING(new boolean[] {false,true,true,false,true false,false,false,true };As stated above, the content represeantation of the bit string '011010001'B will give two content octets of values 0x68 0x80 (hexadecimal). Now, when using these two bytes for supplying the value of a new BIT_STRING object, explicitly the number of unused bits (7) of the last content octet has to be specified:
byte[] value = { (byte)0x68, (byte)0x80 }; BIT_STRING bit_string = new BIT_STRING(value,7);Otherwise it would be assumed, that all bits of the last content octet are significant (number of invalid bits = 0), and the encoding will be a different one.
When calling the getValue
method for getting the inherent value
from an ASN.1 BIT_STRING instance, a byte array is returned. For getting a "binary
string" representation of the value, use the getBinaryString()
method.
DER en/decoding generally is done by means of the several methods of the DerCoder
class; decoding alternatively may be performed by
using the DerInputStream
utility.
ASN1Object
,
ASN
Field Summary | |
protected int |
bits_not_valid
Number of bits not valid in the byte array of bits. |
protected byte[] |
value
The bits of the BIT STRING in a byte array, initialized with null . |
Fields inherited from class iaik.asn1.ASN1Object |
asnType, constructed, encode_listener, indefinite_length, isStringType, stream_mode |
Constructor Summary | |
protected |
BIT_STRING()
Creates a new BIT STRING object. |
|
BIT_STRING(boolean[] array)
Creates a new BIT STRING from a boolean array. |
|
BIT_STRING(byte[] array)
Creates a new BIT STRING object where all bits of the byte array are valid. |
|
BIT_STRING(byte[] array,
int bitsNotValid)
Creates a new BIT STRING object from a byte array and an integer. |
|
BIT_STRING(String binaryString)
Creates a new BIT STRING from a binary string (e.g. |
Method Summary | |
int |
bitsNotValid()
Returns the number of bits which are not valid. |
Object |
clone()
Returns a clone of this ASN1String. |
protected void |
decode(int length,
InputStream is)
Decodes a BIT_STRING value from the given InputStream. |
protected void |
encode(OutputStream os)
DER encodes this BIT STRING ASN1Object and writes the result to the given output stream. |
String |
getBinaryString()
Returns the value of this BIT_STRING as a binary string. |
Object |
getValue()
Returns the value of this BIT_STRING as a byte array. |
void |
setValue(Object object)
Sets the value of this object to value. |
String |
toString()
Returns a string that represents the contents of this BIT STRING ASN1Object. |
Methods inherited from class iaik.asn1.ASN1Object |
addComponent, addEncodeListener, countComponents, encodeObject, getAsnType, getComponentAt, indefiniteLength, isA, isConstructed, isStringType, setIndefiniteLength |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected int bits_not_valid
protected byte[] value
null
.Constructor Detail |
protected BIT_STRING()
public BIT_STRING(byte[] array, int bitsNotValid)
The, forinstance, bit string '011010001'B can be represented by two content octets of values 0x68 0x80 (hexadecimal). Now, when using these two bytes for supplying the value of a new BIT_STRING object, explicitly the number of unused bits (7) of the last content octet has to be specified:
byte[] value = { (byte)0x68, (byte)0x80 }; BIT_STRING bit_string = new BIT_STRING(value,7);
array
- the bits in a byte arraybitsNotValid
- number of bits which are not valid in the last bytepublic BIT_STRING(byte[] array)
array
- the byte array containing the bitspublic BIT_STRING(String binaryString)
BIT_STRING bit_string = new BIT_STRING("011010001");
binaryString
- the String containing the bitspublic BIT_STRING(boolean[] array)
BIT_STRING bit_string = new BIT_STRING(new boolean[] {false,true,true,false,true false,false,false,true };
array
- the boolean array representing the bit string valueMethod Detail |
public Object clone()
clone
in class ASN1Object
public Object getValue()
getValue
in class ASN1Object
public void setValue(Object object)
BIT_STRING(byte[] array, int bitsNotValid)
constructor for supplying a
byte array value and explicitly setting the number of invalid bits.setValue
in class ASN1Object
value
- the byte array value to be set for this BIT STRING objectpublic int bitsNotValid()
public String getBinaryString()
protected void encode(OutputStream os) throws IOException
encode
methods of the
DerCoder
class for performing
the encoding, and the DerCoder internally will call this
encode
method.encode
in class ASN1Object
os
- the output stream to which to write the dataIOException
- if an I/O error occurs while writing to the streamprotected void decode(int length, InputStream is) throws IOException
length
bytes to be read represent the value (content octets
including bitsNotValid specification) of an ASN.1 object of type BIT_STRING.
This is a protected method and will not be used by
an application for decoding a DER encoded BIT_STRING. An application
will call one of the decode
methods of the
DerCoder
class for performing
the decoding. The DerCoder then determines the number of
bytes (length
) occupied by the value of this BIT_STRING
object and internally calls this decode
method for actually reading the value.
decode
in class ASN1Object
length
- the already decoded length, i.e. number of the bytes representing the
value of the BIT_STRING to be decodedis
- the input stream from which the der encoded data is read inIOException
- if there is a problem with the InputStreampublic String toString()
toString
in class ASN1Object
ASN1Object.toString()
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |