org.mozilla.jss.asn1
Class BIT_STRING
java.lang.Object
org.mozilla.jss.asn1.BIT_STRING
- ASN1Value
public class BIT_STRING
extends java.lang.Object
An ASN.1 BIT STRING
, which is an ordered sequence of bits.
The bits are stored the same way they are encoded in BER: as an array
of bytes with 0-7 unused bits at the end.
BIT_STRING(BitSet bs, int numBits) - Constructs a BIT_STRING from a BitSet.
|
BIT_STRING(byte[] bits, int padCount)
|
void | encode(OutputStream ostream) - Write this value's DER encoding to an output stream using
its own base tag.
|
void | encode(Tag implicitTag, OutputStream ostream) - Write this value's DER encoding to an output stream using
an implicit tag.
|
byte[] | getBits() - Returns the bits packed into an array of bytes, with padding
at the end.
|
int | getPadCount() - Returns the number of padding bits at the end of the array.
|
boolean | getRemoveTrailingZeroes() - Determines whether the DER-encoding of this bitstring will have
its trailing zeroes removed.
|
Tag | getTag() - Returns the base tag for this type, not counting any tags
that may be imposed on it by its context.
|
static BIT_STRING.Template | getTemplate()
|
void | setRemoveTrailingZeroes(boolean removeTrailingZeroes) - Determines whether the DER-encoding of this bitstring will have
its trailing zeroes removed.
|
BitSet | toBitSet() - Copies this BIT STRING into a Java BitSet.
|
boolean[] | toBooleanArray() - Copies this BIT STRING into a boolean array.
|
FORM
public static final Form FORM
TAG
public static final Tag TAG
BIT_STRING
public BIT_STRING(BitSet bs,
int numBits)
throws NumberFormatException
Constructs a BIT_STRING from a BitSet.
bs
- A BitSet.numBits
- The number of bits to copy from the BitSet.
This is necessary because the size of a BitSet is always padded
up to a multiple of 64, but not all of these bits may
be significant.
BIT_STRING
public BIT_STRING(byte[] bits,
int padCount)
throws NumberFormatException
bits
- The bits packed into an array of bytes, with padding
at the end. The array may be empty (but not null), in which case
padCount
must be zero. The array is referenced,
not cloned.padCount
- The number of padding bits at the end of the array.
Must be in the range [0,7]
.
encode
public void encode(OutputStream ostream)
throws IOException
Write this value's DER encoding to an output stream using
its own base tag.
- encode in interface ASN1Value
encode
public void encode(Tag implicitTag,
OutputStream ostream)
throws IOException
Write this value's DER encoding to an output stream using
an implicit tag.
- encode in interface ASN1Value
getBits
public byte[] getBits()
Returns the bits packed into an array of bytes, with padding
at the end. The array may be empty (but not null), in which case
padCount
must be zero. The array is referenced,
not cloned.
getPadCount
public int getPadCount()
Returns the number of padding bits at the end of the array.
Must be in the range [0,7]
.
getRemoveTrailingZeroes
public boolean getRemoveTrailingZeroes()
Determines whether the DER-encoding of this bitstring will have
its trailing zeroes removed. Generally, DER requires that trailing
zeroes be removed when the bitstring is used to hold flags, but
not when it is used to hold binary data (such as a public key).
The default is false.
getTag
public Tag getTag()
Returns the base tag for this type, not counting any tags
that may be imposed on it by its context.
- getTag in interface ASN1Value
setRemoveTrailingZeroes
public void setRemoveTrailingZeroes(boolean removeTrailingZeroes)
Determines whether the DER-encoding of this bitstring will have
its trailing zeroes removed. Generally, DER requires that trailing
zeroes be removed when the bitstring is used to hold flags, but
not when it is used to hold binary data (such as a public key).
The default is false. If this bit string is used to hold
flags, you should set this to true.
toBitSet
public BitSet toBitSet()
Copies this BIT STRING into a Java BitSet. Note that BitSet.size()
will not accurately reflect the number of bits in the BIT STRING,
because the size of a BitSet is always rounded up to the next multiple
of 64. The extra bits will be set to 0.
toBooleanArray
public boolean[] toBooleanArray()
Copies this BIT STRING into a boolean array. Each element of the array
represents one bit with true
for 1 and false
for 0.