Package org.mozilla.jss.asn1
Class BIT_STRING
java.lang.Object
org.mozilla.jss.asn1.BIT_STRING
- All Implemented Interfaces:
ASN1Value
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA class for decoding aBIT_STRINGfrom its BER encoding. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]static final Formprivate intprivate booleanstatic final Tagprivate static final BIT_STRING.Template -
Constructor Summary
ConstructorsConstructorDescriptionBIT_STRING(byte[] bits, int padCount) BIT_STRING(BitSet bs, int numBits) Constructs a BIT_STRING from a BitSet. -
Method Summary
Modifier and TypeMethodDescriptionvoidencode(OutputStream ostream) Write this value's DER encoding to an output stream using its own base tag.voidencode(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.intReturns the number of padding bits at the end of the array.booleanDetermines whether the DER-encoding of this bitstring will have its trailing zeroes removed.getTag()Returns the base tag for this type, not counting any tags that may be imposed on it by its context.static BIT_STRING.TemplatevoidsetRemoveTrailingZeroes(boolean removeTrailingZeroes) Determines whether the DER-encoding of this bitstring will have its trailing zeroes removed.toBitSet()Copies this BIT STRING into a Java BitSet.boolean[]Copies this BIT STRING into a boolean array.
-
Field Details
-
bits
private byte[] bits -
padCount
private int padCount -
removeTrailingZeroes
private boolean removeTrailingZeroes -
TAG
-
FORM
-
templateInstance
-
-
Constructor Details
-
BIT_STRING
- Parameters:
bits- The bits packed into an array of bytes, with padding at the end. The array may be empty (but not null), in which casepadCountmust 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].- Throws:
NumberFormatException- IfpadCountis not in the range[0,7], orbitsis empty andpadCountis non-zero.
-
BIT_STRING
Constructs a BIT_STRING from a BitSet.- Parameters:
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.- Throws:
NumberFormatException- IfnumBitsis larger thanbs.size()or less than zero.
-
-
Method Details
-
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 isfalse.- Returns:
- True if trailing zeroes are to be removed.
-
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 isfalse. If this bit string is used to hold flags, you should set this totrue.- Parameters:
removeTrailingZeroes- True if trailing zeroes are to be removed.
-
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 casepadCountmust be zero. The array is referenced, not cloned.- Returns:
- BIT STRING as byte array.
-
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.- Returns:
- BIT STRING as BitSet.
-
toBooleanArray
public boolean[] toBooleanArray()Copies this BIT STRING into a boolean array. Each element of the array represents one bit withtruefor 1 andfalsefor 0.- Returns:
- BIT STRING as boolean array.
-
getPadCount
public int getPadCount()Returns the number of padding bits at the end of the array. Must be in the range[0,7].- Returns:
- Number of padding.
-
getTag
Description copied from interface:ASN1ValueReturns the base tag for this type, not counting any tags that may be imposed on it by its context. -
encode
Description copied from interface:ASN1ValueWrite this value's DER encoding to an output stream using its own base tag.- Specified by:
encodein interfaceASN1Value- Parameters:
ostream- Output stream.- Throws:
IOException- If an error occurred.
-
encode
Description copied from interface:ASN1ValueWrite this value's DER encoding to an output stream using an implicit tag.- Specified by:
encodein interfaceASN1Value- Parameters:
implicitTag- Implicit tag.ostream- Output stream.- Throws:
IOException- If an error occurred.
-
getTemplate
-