BitStringpublic final class BitString extends Object Represents ASN.1 bit string value |
Fields Summary |
---|
private static final byte[] | SET_MASK | private static final byte[] | RESET_MASK | public final byte[] | bytesSequence of bits padded with unused bits. | public final int | unusedBitsNumber of unused bits in the last byte. |
Constructors Summary |
---|
public BitString(byte[] bytes, int unusedBits)Constructs bit string
// constraints are set according X.690
if (unusedBits < 0 || unusedBits > 7) {
throw new IllegalArgumentException(
Messages.getString("security.13D")); //$NON-NLS-1$
}
if (bytes.length == 0 && unusedBits != 0) {
throw new IllegalArgumentException(
Messages.getString("security.13E")); //$NON-NLS-1$
}
this.bytes = bytes;
this.unusedBits = unusedBits;
| public BitString(boolean[] values)Constructs bit string from array of booleans
unusedBits = values.length % 8;
int size = values.length / 8;
if (unusedBits != 0) {
size++;
}
bytes = new byte[size];
for (int i = 0; i < values.length; i++) {
setBit(i, values[i]);
}
|
Methods Summary |
---|
public boolean | getBit(int bit)
int offset = bit % 8;
int index = bit / 8;
return (bytes[index] & SET_MASK[offset]) != 0;
| public void | setBit(int bit, boolean value)
int offset = bit % 8;
int index = bit / 8;
if (value) {
bytes[index] |= SET_MASK[offset];
} else {
bytes[index] &= RESET_MASK[offset];
}
| public boolean[] | toBooleanArray()
boolean[] result = new boolean[bytes.length * 8 - unusedBits];
for (int i = 0; i < result.length; i++) {
result[i] = getBit(i);
}
return result;
|
|