Package com.oss.asn1

Class BitString

All Implemented Interfaces:
com.oss.asn1.Sizeable, Serializable, Cloneable
Direct Known Subclasses:
ContainingBitString

public class BitString extends AbstractBinary implements com.oss.asn1.Sizeable
The BitString class represents an ASN.1 BIT STRING, an arbitrarily long string of bits, that may or may not be octet-aligned.
Since:
ASN.1/Java 1.0-beta A
See Also:
  • Field Summary

    Fields inherited from class com.oss.asn1.AbstractData

    EQUALS, GREATER_THAN, LESS_THAN
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default constructor creates an empty bit string
    BitString(byte[] value)
    Construct from a byte array.
    BitString(byte[] value, int sigBits)
    Construct from a byte array and significant bits.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    clearBit(int bit)
    Set a bit, identified by an index, to 0.
    final boolean
    Compare 'this' object to another BitString object to see if their contents are the same.
    final boolean
    getBit(int bit)
    Check whether a bit at some index is 0 or 1.
    final int
    Get the index of rightmost '1' bit in the BitString
    final int
    Deprecated.
    Get the number of significant bits the BitString contains.
    final int
    Get the number of significant bits of BitString
    int
    Returns a hash code for this object
    final void
    setBit(int bit)
    Set a bit, identified by an index, to 1.
    final void
    setSignificantBits(int sigBits)
    Set the significant bits of BitString.
    final void
    setValue(byte[] value)
    Set the value of this object to a byte[].
    final void
    setValue(byte[] value, int sigBits)
    Set the value of this object to a byte[].

    Methods inherited from class com.oss.asn1.AbstractBinary

    byteArrayValue, clone, delete

    Methods inherited from class com.oss.asn1.AbstractData

    equals, isEncodable, isPDU, isValid, toString, toString

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BitString

      public BitString()
      The default constructor creates an empty bit string
    • BitString

      public BitString(byte[] value)
      Construct from a byte array. The significant bits are set to value.length * 8.
      Parameters:
      value - the byte array to set this object to.
    • BitString

      public BitString(byte[] value, int sigBits)
      Construct from a byte array and significant bits.
      Parameters:
      value - the byte array to set this object to.
      sigBits - the number of significant bits.
  • Method Details

    • setValue

      public final void setValue(byte[] value)
      Set the value of this object to a byte[].
      Overrides:
      setValue in class AbstractBinary
      Parameters:
      value - the value to set this object to.
    • setValue

      public final void setValue(byte[] value, int sigBits)
      Set the value of this object to a byte[].
      Parameters:
      value - the value to set this object to.
      sigBits - the number of significant bits.
    • getBit

      public final boolean getBit(int bit)
      Check whether a bit at some index is 0 or 1.
      Parameters:
      bit - the index of the bit to check.
      Returns:
      true is returned if the bit at the index is set to 1, otherwise false is returned.
    • setBit

      public final void setBit(int bit)
      Set a bit, identified by an index, to 1.
      Parameters:
      bit - the index of the bit to set to 1.
    • clearBit

      public final void clearBit(int bit)
      Set a bit, identified by an index, to 0.
      Parameters:
      bit - the index of the bit to clear.
    • getSignificantBits

      @Deprecated public final int getSignificantBits()
      Deprecated.
      Get the number of significant bits the BitString contains. This method is deprecated. Use the getSize method instead.
      Returns:
      integer value indicating the number of significant bits.
    • setSignificantBits

      public final void setSignificantBits(int sigBits)
      Set the significant bits of BitString.
      Parameters:
      sigBits - an integer value indicating the number of significant bits to set.
    • getSize

      public final int getSize()
      Get the number of significant bits of BitString
      Specified by:
      getSize in interface com.oss.asn1.Sizeable
      Returns:
      integer value indicating the number of significant bits.
    • getLastBit

      public final int getLastBit()
      Get the index of rightmost '1' bit in the BitString
      Returns:
      integer value indicating the index of rightmost bit set to '1'.
    • equalTo

      public final boolean equalTo(BitString that)
      Compare 'this' object to another BitString object to see if their contents are the same. If ASN.1 definition of a BIT STRING has named bits then the comparison ignores trailing zero bits in the BIT STRING value.
      Parameters:
      that - the BitString object to compare 'this' object to.
      Returns:
      true if contents of both objects are the same.
    • hashCode

      public int hashCode()
      Returns a hash code for this object
      Overrides:
      hashCode in class AbstractBinary
      Returns:
      a hash code for this object