|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.demac.impl.j2me.process.base.service.webservices.asn1.ASN1AbstractType
org.demac.impl.j2me.process.base.service.webservices.asn1.ASN1BitString
public class ASN1BitString
Represents an ASN.1 BIT STRING type. The corresponding Java type is
boolean[]
.
This class has to modes of initialization which play a crucial role in standards compliant DER encoding. One mode initializes instances of this class as a representation of "named bits". The second mode initializes it as a plain bitstring.
An ASN.1 structure with named bits looks e.g., as follows:
Rights ::= BIT STRING { read(0), write(1), execute(2)}Such bitstrings have a special canonical encoding. The mode (and defaults) are specified in the documentation of the constructors of this class. Basically, in named bits mode, trailing zeroes are truncated from the internal representation of the bitstring.
Constructor Summary | |
---|---|
ASN1BitString()
Initializes an instance for decoding. |
|
ASN1BitString(boolean[] b)
Initializes the instance for encoding with the given bits. |
|
ASN1BitString(byte[] b,
int pad)
Creates an instance with the given contents. |
Method Summary | |
---|---|
int |
bitCount()
Returns the number of bits of the bitstring representation. |
int |
byteCount()
|
void |
decode(Decoder dec)
Decodes this instance. |
void |
encode(Encoder enc)
DOCUMENT ME! |
boolean[] |
getBits()
Returns the contents bits of this instance. |
byte[] |
getBytes()
Returns the contents octets of this instance. |
int |
getPadCount()
|
int |
getTag()
DOCUMENT ME! |
java.lang.Object |
getValue()
This method calls getBits() . |
boolean |
isNamedBits()
|
boolean |
isZero()
Returns true if the bit string contains no bits that are
1. |
void |
setBits(boolean[] bits)
Sets the contents bits of this instance. |
void |
setBits(byte[] b,
int pad)
Sets the bit string from the given byte aray and pad count. |
java.lang.String |
toString()
Returns the string representation of this ASN1BitString. |
Methods inherited from class org.demac.impl.j2me.process.base.service.webservices.asn1.ASN1AbstractType |
---|
checkConstraints, getConstraint, getTagClass, isExplicit, isOptional, isType, readExternal, setConstraint, setExplicit, setOptional, writeExternal |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ASN1BitString()
public ASN1BitString(boolean[] b)
b
- The string of bits to be encoded.public ASN1BitString(byte[] b, int pad)
b
- The left aligned contents bits.pad
- The number of pad bits.Method Detail |
---|
public java.lang.Object getValue()
getBits()
.
getValue
in interface ASN1Type
getValue
in class ASN1AbstractType
public boolean[] getBits()
public void setBits(boolean[] bits) throws ConstraintException
bits
- The contents bits that are set.
ConstraintException
- if the given bits violates the specified constraint.public void setBits(byte[] b, int pad) throws ConstraintException
&0x07
) in byte floor(n/8).
The length of the bit string is b.length
*8-pad. The pad
value be in the range of [0..7]. In other words the bits in the byte
array are left aligned.
The given byte array may be copied by reference. Subsequent modification of it can cause side effects. The mode is set not to represent named bits.
b
- The bits encoded into a byte array.pad
- The number of pad bits after the actual bits in the array.
java.lang.IllegalArgumentException
- if the pad value is out of range.
ConstraintException
- if the given bits violates thepublic byte[] getBytes()
Please also note that the bits in the bytes are left aligned. In other words, the bits are shifted to the left by the amount of pad bits. Bit X in the byte array corresponds to the logical bit with the number X minus pad count.
public int getPadCount()
public int byteCount()
public int bitCount()
public boolean isNamedBits()
true
iff this instance has named bits.public boolean isZero()
true
if the bit string contains no bits that are
1. Otherwise, false
is returned. This method is used by
the DEREncoder
in order to determine cases in which
special encoding is to be used. If no bits of a BIT STRING are 1 then it
is encoded as 0x03 0x01 0x00
even if the BIT STRING has
hundreds of bits in length.
true
if all bits are zero.public int getTag()
getTag
in interface ASN1Type
getTag
in class ASN1AbstractType
public void encode(Encoder enc) throws ASN1Exception, java.io.IOException
encode
in interface ASN1Type
encode
in class ASN1AbstractType
enc
- The encoder which is used to encode
ASN1Exception
- DOCUMENT ME!
java.io.IOException
- if an I/O error occurespublic void decode(Decoder dec) throws ASN1Exception, java.io.IOException
decode
in interface ASN1Type
decode
in class ASN1AbstractType
dec
- The decoder which is used to decode
java.io.IOException
- if an I/O error occures
ASN1Exception
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |