JSS 3.1.2

org.mozilla.jss.asn1
Class BIT_STRING

java.lang.Object
  |
  +--org.mozilla.jss.asn1.BIT_STRING
All Implemented Interfaces:
ASN1Value

public class BIT_STRING
extends java.lang.Object
implements 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.


Inner Class Summary
static class BIT_STRING.Template
          A class for decoding a BIT_STRING from its BER encoding.
 
Field Summary
private  byte[] bits
           
static Form FORM
           
private  int padCount
           
static Tag TAG
           
private static BIT_STRING.Template templateInstance
           
 
Constructor Summary
private BIT_STRING()
           
  BIT_STRING(java.util.BitSet bs, int numBits)
          Constructs a BIT_STRING from a BitSet.
  BIT_STRING(byte[] bits, int padCount)
           
 
Method Summary
 void encode(java.io.OutputStream ostream)
          Write this value's DER encoding to an output stream using its own base tag.
 void encode(Tag implicitTag, java.io.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.
 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()
           
 java.util.BitSet toBitSet()
          Copies this BIT STRING into a Java BitSet.
 boolean[] toBooleanArray()
          Copies this BIT STRING into a boolean array.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

bits

private byte[] bits

padCount

private int padCount

TAG

public static final Tag TAG

FORM

public static final Form FORM

templateInstance

private static final BIT_STRING.Template templateInstance
Constructor Detail

BIT_STRING

private BIT_STRING()

BIT_STRING

public BIT_STRING(byte[] bits,
                  int padCount)
           throws java.lang.NumberFormatException
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 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].
Throws:
java.lang.NumberFormatException - If padCount is not in the range [0,7], or bits is empty and padCount is non-zero.

BIT_STRING

public BIT_STRING(java.util.BitSet bs,
                  int numBits)
           throws java.lang.NumberFormatException
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:
java.lang.NumberFormatException - If numBits is larger than bs.size() or less than zero.
Method Detail

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.

toBitSet

public java.util.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.

getPadCount

public int getPadCount()
Returns the number of padding bits at the end of the array. Must be in the range [0,7].

getTag

public Tag getTag()
Description copied from interface: ASN1Value
Returns the base tag for this type, not counting any tags that may be imposed on it by its context.
Specified by:
getTag in interface ASN1Value

encode

public void encode(java.io.OutputStream ostream)
            throws java.io.IOException
Description copied from interface: ASN1Value
Write this value's DER encoding to an output stream using its own base tag.
Specified by:
encode in interface ASN1Value

encode

public void encode(Tag implicitTag,
                   java.io.OutputStream ostream)
            throws java.io.IOException
Description copied from interface: ASN1Value
Write this value's DER encoding to an output stream using an implicit tag.
Specified by:
encode in interface ASN1Value

getTemplate

public static BIT_STRING.Template getTemplate()

JSS 3.1.2