pasn.misc
Class ASN1BitStringValue

java.lang.Object
  extended by pasn.misc.ASN1BitStringValue
All Implemented Interfaces:
ASN1Resetable

public final class ASN1BitStringValue
extends java.lang.Object
implements ASN1Resetable

Author:
ncottin

Constructor Summary
ASN1BitStringValue()
           
ASN1BitStringValue(byte[] value)
           
ASN1BitStringValue(byte[] value, int unusedBits)
           
 
Method Summary
 boolean equals(java.lang.Object o)
           
 int getNumberOfBits()
           Returns the number of significant bits stored in this BIT STRING
 int getNumberOfOctets()
           
 int getUnusedBits()
           
 byte[] getValue()
           
 boolean hasBitValue(int bitIndex)
           Checks that the given index is valid
 boolean isBitReset(int bitIndex)
           Checks that the bit located at the given index is reset (has value 0)
 boolean isBitSet(int bitIndex)
           Checks that the bit located at the given index is set (has value 1)
 void reset()
           Removes the value (or list or set of values) of this ASN.1 object.
 void setUnusedBits(int unusedBits)
           Initializes the number of unused bits of this BIT STRING.
 void setValue(boolean[] value)
           Initializes the value of this BIT STRING using the given value array.
 boolean setValue(boolean bitValue, int bitIndex)
           Sets or resets the bit located at the given index.
 void setValue(byte[] value)
           Initializes the value of this BIT STRING along with no unused (extra) bits
 void setValue(byte[] value, int unusedBits)
           Initializes the value of this BIT STRING along with unused bits
 void setValue(java.lang.String value)
           Initializes the value of this BIT STRING using the given string representation of bit values.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ASN1BitStringValue

public ASN1BitStringValue()

ASN1BitStringValue

public ASN1BitStringValue(byte[] value)

ASN1BitStringValue

public ASN1BitStringValue(byte[] value,
                          int unusedBits)
Method Detail

getUnusedBits

public int getUnusedBits()
Returns:
the unusedBits

getValue

public byte[] getValue()
Returns:
the value

setValue

public void setValue(byte[] value)

Initializes the value of this BIT STRING along with no unused (extra) bits

Parameters:
value - The byte array to initialize this BIT STRING with. This byte array must be considered as a list of bit values. A null value re-initializes this BIT STRING

setValue

public void setValue(byte[] value,
                     int unusedBits)

Initializes the value of this BIT STRING along with unused bits

Parameters:
value - The byte array to initialize this BIT STRING with. This byte array must be considered as a list of bit values. A null value re-initializes this BIT STRING
unusedBits - The number of unused bits, from range 0 (all bits are necessary) to 7 (all but the first bit of the last octet are not used). A negative number is changed to 0 and any value greater than 7 is transformed so that it fits in the required range (modulo 8 mathematical transformation is performed)

setValue

public void setValue(boolean[] value)

Initializes the value of this BIT STRING using the given value array. The number of unused bits is automatically initialized, depending on the length of this array

Parameters:
value - A possibly null array of boolean values. Each value corresponds to a bit value: false stands for 0 (bit reset) and true for 1 (bit set)

setValue

public void setValue(java.lang.String value)

Initializes the value of this BIT STRING using the given string representation of bit values. The number of unused bits is also initialized

Parameters:
value - Any string (possibly null or empty) composed of '0' and '1' characters, such as "001001011"

setValue

public boolean setValue(boolean bitValue,
                        int bitIndex)

Sets or resets the bit located at the given index. The internal value is automatically resized in case the bit index is outsize the length of the current value

Parameters:
bitValue - True means that the specified bit has to be set (takes value 1), false resets this bit (changes its value to 0)
bitIndex - The index (starting at 0, without -theorically- maximum limitation) of the bit that must be set. A negative value has no effect and this BIT STRING is left unchanged
Returns:
True if the value has been changed, false if the current value could not be changed (the given bit index is strictly negative)

getNumberOfBits

public int getNumberOfBits()

Returns the number of significant bits stored in this BIT STRING

Returns:
A strictly positive number which corresponds to the number of useful bits, or 0 if it has no value

getNumberOfOctets

public int getNumberOfOctets()

setUnusedBits

public void setUnusedBits(int unusedBits)

Initializes the number of unused bits of this BIT STRING. Changing this number does not affect the current bits values of this BIT STRING

Parameters:
unusedBits - Any number in range [0..7]. A negative number is changed to 0 and a number greater than 7 is transformed using a modulo operation so that it fits in the required range of values: 12 is thus transformed to 12 % 8 = 4

isBitSet

public boolean isBitSet(int bitIndex)

Checks that the bit located at the given index is set (has value 1)

Parameters:
bitIndex - A number in range [0..getNumberOfBits()[
Returns:
True if the indexed bit is currently set, false if either the indexed bit is reset or the given index is not valid
See Also:
hasBitValue(int)

isBitReset

public boolean isBitReset(int bitIndex)

Checks that the bit located at the given index is reset (has value 0)

Parameters:
bitIndex - A number in range [0..getNumberOfBits()[
Returns:
True if the indexed bit is currently reset, false if either the indexed bit is set or the given index is not valid
See Also:
hasBitValue(int)

hasBitValue

public boolean hasBitValue(int bitIndex)

Checks that the given index is valid

Parameters:
bitIndex - Any number
Returns:
True if this BIT STRING has a value and the given bit index is in range [0..getNumberOfBits()[, false if either this BIT STRING is not initialized or the given index value is out of range

reset

public void reset()
Description copied from interface: ASN1Resetable

Removes the value (or list or set of values) of this ASN.1 object. This applies to simple and structured ASN.1 objects

Specified by:
reset in interface ASN1Resetable

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object