com.objsys.asn1j.runtime
Class Asn1OctetString

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1Type
      extended by com.objsys.asn1j.runtime.Asn1OctetString
All Implemented Interfaces:
Asn1TypeIF, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable
Direct Known Subclasses:
Asn1Base64BinaryString, Asn1OpenType

public class Asn1OctetString
extends Asn1Type
implements java.lang.Comparable

This is a container class for holding the components of an ASN.1 octet string value.

See Also:
Serialized Form

Field Summary
static Asn1Tag TAG
          The TAG constant describes the universal tag for this data type (UNIVERSAL 4).
 byte[] value
          This variable holds the octet string value.
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1Type
BIT_STRING, BMPString, BOOLEAN, DATE, DATE_TIME, DURATION, ENUMERATED, EOC, EXTERNAL, GeneralString, GeneralTime, GraphicString, IA5String, INTEGER, NULL, NumericString, OBJECT_IDENTIFIER, ObjectDescriptor, OCTET_STRING, OID_IRI, OpenType, PrintableString, REAL, RELATIVE_OID_IRI, RelativeOID, SEQUENCE, SET, T61String, TeletexString, TIME, TIME_OF_DAY, UniversalString, UTCTime, UTF8String, VideotexString, VisibleString
 
Constructor Summary
Asn1OctetString()
          This constructor creates an empty octet string that can be used in a decode method call to receive an octet string value.
Asn1OctetString(byte[] data)
          This constructor initializes an octet string from the given byte array.
Asn1OctetString(byte[] data, int offset, int nbytes)
          This constructor initializes an octet string from a portion of the given byte array.
Asn1OctetString(java.lang.String value_)
          This constructor parses the given ASN.1 value text (either a binary or hex data string) and assigns the values to the internal bit string.
 
Method Summary
 int compareTo(java.lang.Object octstr)
          This method compares two Asn1OctetString objects for equality.
 void decode(Asn1BerDecodeBuffer buffer, boolean explicit, int implicitLength)
          This method decodes an ASN.1 octet string value including the UNIVERSAL tag value and length if explicit tagging is specified.
 void decode(Asn1JsonDecodeBuffer buffer)
          Decode ASN.1 octet string from JSON.
 void decode(Asn1MderDecodeBuffer buffer)
          Decode an unconstrained octet string from the MDER encoding into this object.
 void decode(Asn1MderDecodeBuffer buffer, int constrainedLength)
          Decode an octet string from the MDER encoding into this object.
 void decode(Asn1PerDecodeBuffer buffer)
          This method decodes an ASN.1 octet string value using the packed encoding rules (PER).
 void decode(Asn1PerDecodeBuffer buffer, long lower, long upper)
          This method decodes a sized ASN.1 octet string value using the packed encoding rules (PER).
 void decodeXER(java.lang.String buffer, java.lang.String attrs, boolean base64)
          This method decodes ASN.1 octet string type using the XML encoding rules (XER).
 void decodeXML(java.lang.String buffer, java.lang.String attrs)
          This method decodes an ASN.1 octet string type using the XML schema encoding rules.
 int encode(Asn1BerEncodeBuffer buffer, boolean explicit)
          This method encodes an ASN.1 octet string value including the UNIVERSAL tag value and length if explicit tagging is specified.
 void encode(Asn1BerOutputStream out, boolean explicit)
          This method encodes and writes to the stream an ASN.1 octet string value including the UNIVERSAL tag value and length if explicit tagging is specified.
 void encode(Asn1JsonOutputStream outstream)
          Encode this octet string to JSON.
 void encode(Asn1MderOutputStream out)
          Encode this octet string into the MDER encoding.
 void encode(Asn1MderOutputStream out, int constrainedLength)
          Encode this octet string into the MDER encoding.
 void encode(Asn1PerEncodeBuffer buffer)
          This method encodes an unconstrained ASN.1 octet string value using the packed encoding rules (PER).
 void encode(Asn1PerEncodeBuffer buffer, long lower, long upper)
          This method encodes a size-constrained ASN.1 octet string value using the packed encoding rules (PER).
 void encode(Asn1PerOutputStream out)
          This method encodes an unconstrained ASN.1 octet string value using the packed encoding rules (PER).
 void encode(Asn1PerOutputStream out, long lower, long upper)
          This method encodes a size-constrained ASN.1 octet string value using the packed encoding rules (PER).
 void encode(Asn1XerEncoder buffer, java.lang.String elemName)
          This method encodes ASN.1 octet string type using the XML encoding rules (XER).
 void encode(Asn1XmlEncoder buffer, java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes ASN.1 octet string type as an xmlhstring.
 void encode(Asn1XmlEncoder buffer, java.lang.String elemName, java.lang.String nsPrefix, boolean base64)
          This method encodes ASN.1 octet string type using the XML Encoding as specified in the XML schema standard(asn2xsd).
 void encodeAttribute(Asn1XmlEncoder buffer, java.lang.String attrName)
          This method encodes ASN.1 octet string type using the XML Encoding as specified in the XML schema standard(asn2xsd).
static java.lang.String encodeBase64Binary(byte[] data)
          Encodes bytes into base64 ASCII characters using the algorithm defined in RFC2045, as defined in w3c stadard http://www.w3.org/tr/2001/rec-xmlschema-2-20010502#base64Binary
 boolean equals(byte[] value)
          This method compares this octet string value to the given value for equality.
 boolean equals(java.lang.Object os)
          This method compares this octet string value to the given value for equality.
 int getLength()
          This method will return the length of the OCTET STRING in octets.
 int getMderLength()
          Return the length of the MDER encoding for this type, assuming that the type is NOT a fixed length OCTET STRING (if it is fixed length, you need not call this method!).
 int hashCode()
          This method returns the hashcode for the Asn1OctetString.
 java.io.InputStream toInputStream()
          This method will return a byte array input stream representation of the octet string value.
 java.lang.String toString()
          This method will return a string representation of the octet string value.
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1Type
clone, decode, decode, decode, decode, decode, encode, encode, equals, getTypeName, indent, isOpenType, matchTag, matchTag, pdiag, print, setKey, setOpenType
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TAG

public static final Asn1Tag TAG
The TAG constant describes the universal tag for this data type (UNIVERSAL 4).


value

public transient byte[] value
This variable holds the octet string value. These are the octets that are encoded when encode is invoked. It is also where the decoded octet string is stored after a decode operation.

Constructor Detail

Asn1OctetString

public Asn1OctetString()
This constructor creates an empty octet string that can be used in a decode method call to receive an octet string value.


Asn1OctetString

public Asn1OctetString(byte[] data)
This constructor initializes an octet string from the given byte array.

Parameters:
data - Byte array containing an octet string in binary form.

Asn1OctetString

public Asn1OctetString(byte[] data,
                       int offset,
                       int nbytes)
This constructor initializes an octet string from a portion of the given byte array. A new byte array is created starting at the given offset and consisting of the given number of bytes.

Parameters:
data - Byte array containing an octet string in binary form.
offset - Starting offset in data from which to copy bytes
nbytes - Number of bytes to copy from target array

Asn1OctetString

public Asn1OctetString(java.lang.String value_)
                throws Asn1ValueParseException
This constructor parses the given ASN.1 value text (either a binary or hex data string) and assigns the values to the internal bit string. Examples of valid value formats are as follows: Binary string: '11010010111001'B Hex string: '0fa56920014abc'H Char string: 'abcdefg'

Parameters:
value_ - The ASN.1 value specification text
Throws:
Asn1ValueParseException
Method Detail

compareTo

public int compareTo(java.lang.Object octstr)
This method compares two Asn1OctetString objects for equality. The OCTET STRING's are equal if a) all octets are equal, and b) the lengths are the same. This method is required to implement the Comparable interface used for sorting.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
octstr - Asn1OctetString to compare

decode

public void decode(Asn1BerDecodeBuffer buffer,
                   boolean explicit,
                   int implicitLength)
            throws Asn1Exception,
                   java.io.IOException
This method decodes an ASN.1 octet string value including the UNIVERSAL tag value and length if explicit tagging is specified.

Specified by:
decode in interface Asn1TypeIF
Overrides:
decode in class Asn1Type
Parameters:
buffer - Decode message buffer object
explicit - Flag indicating element is explicitly tagged
implicitLength - Length of contents if implicit
Throws:
Asn1Exception
java.io.IOException

encode

public int encode(Asn1BerEncodeBuffer buffer,
                  boolean explicit)
           throws Asn1Exception
This method encodes an ASN.1 octet string value including the UNIVERSAL tag value and length if explicit tagging is specified.

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1Type
Parameters:
buffer - Encode message buffer object
explicit - Flag indicating explicit tagging should be done
Returns:
Length of encoded component
Throws:
Asn1Exception

decode

public void decode(Asn1PerDecodeBuffer buffer)
            throws Asn1Exception,
                   java.io.IOException
This method decodes an ASN.1 octet string value using the packed encoding rules (PER). The string is assumed to not contain a size constraint.

Specified by:
decode in interface Asn1TypeIF
Overrides:
decode in class Asn1Type
Parameters:
buffer - Decode message buffer object
Throws:
Asn1Exception
java.io.IOException

decode

public void decode(Asn1PerDecodeBuffer buffer,
                   long lower,
                   long upper)
            throws Asn1Exception,
                   java.io.IOException
This method decodes a sized ASN.1 octet string value using the packed encoding rules (PER).

Parameters:
buffer - Decode message buffer object
lower - Lower bound (inclusive) of size constraint
upper - Upper bound (inclusive) of size constraint
Throws:
Asn1Exception
java.io.IOException

encode

public void encode(Asn1PerEncodeBuffer buffer)
            throws Asn1Exception,
                   java.io.IOException
This method encodes an unconstrained ASN.1 octet string value using the packed encoding rules (PER). The value to be encoded is stored in the 'value' public member variable within this class.

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1Type
Parameters:
buffer - Encode message buffer object
Throws:
Asn1Exception
java.io.IOException

encode

public void encode(Asn1PerEncodeBuffer buffer,
                   long lower,
                   long upper)
            throws Asn1Exception,
                   java.io.IOException
This method encodes a size-constrained ASN.1 octet string value using the packed encoding rules (PER). The value to be encoded is stored in the 'value' public member variable within this class.

Parameters:
buffer - Encode message buffer object
lower - Lower bound (inclusive) of size constraint
upper - Upper bound (inclusive) of size constraint
Throws:
Asn1Exception
java.io.IOException

decode

public void decode(Asn1MderDecodeBuffer buffer)
            throws Asn1Exception,
                   java.io.IOException
Decode an unconstrained octet string from the MDER encoding into this object.

Throws:
Asn1Exception
java.io.IOException

decode

public void decode(Asn1MderDecodeBuffer buffer,
                   int constrainedLength)
            throws Asn1Exception,
                   java.io.IOException
Decode an octet string from the MDER encoding into this object.

Parameters:
constrainedLength - The constrained length of the type being encoded. Pass -1 if the type is unconstrained. For a constrained length octet string, exactly that many octets will be read.
Throws:
Asn1Exception
java.io.IOException

getMderLength

public int getMderLength()
Return the length of the MDER encoding for this type, assuming that the type is NOT a fixed length OCTET STRING (if it is fixed length, you need not call this method!).

Returns:

encode

public void encode(Asn1XerEncoder buffer,
                   java.lang.String elemName)
            throws java.io.IOException,
                   Asn1Exception
This method encodes ASN.1 octet string type using the XML encoding rules (XER).

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1Type
Parameters:
buffer - Encode message buffer object
elemName - XML element name used to wrap string
Throws:
java.io.IOException - Any exception thrown by the underlying stream.
Asn1Exception - Thrown, if operation is failed.

decodeXER

public void decodeXER(java.lang.String buffer,
                      java.lang.String attrs,
                      boolean base64)
               throws Asn1Exception
This method decodes ASN.1 octet string type using the XML encoding rules (XER). Extended-XER is supported by the base64 parameter.

Parameters:
buffer - String containing data to be decoded
attrs - Attributes string from element tag
base64 - pass true if encoding is base64 (extended-XER only)
Throws:
Asn1Exception

encode

public void encode(Asn1XmlEncoder buffer,
                   java.lang.String elemName,
                   java.lang.String nsPrefix)
            throws java.io.IOException,
                   Asn1Exception
This method encodes ASN.1 octet string type as an xmlhstring.

Parameters:
buffer - Encode message buffer object
elemName - XML element name used to wrap string
nsPrefix - XML element name space prefix
Throws:
java.io.IOException
Asn1Exception

encode

public void encode(Asn1XmlEncoder buffer,
                   java.lang.String elemName,
                   java.lang.String nsPrefix,
                   boolean base64)
            throws java.io.IOException,
                   Asn1Exception
This method encodes ASN.1 octet string type using the XML Encoding as specified in the XML schema standard(asn2xsd).

Parameters:
buffer - Encode message buffer object
elemName - XML element name used to wrap string
nsPrefix - XML element name space prefix
base64 - Pass true to encode as base64 (extended-XER only, including XSD compilation)
Throws:
java.io.IOException
Asn1Exception

encodeAttribute

public void encodeAttribute(Asn1XmlEncoder buffer,
                            java.lang.String attrName)
                     throws Asn1Exception,
                            java.io.IOException
This method encodes ASN.1 octet string type using the XML Encoding as specified in the XML schema standard(asn2xsd).

Parameters:
buffer - Encode message buffer object
elemName - XML element name used to wrap string
nsPrefix - XML element name space prefix
Throws:
Asn1Exception
java.io.IOException

decodeXML

public void decodeXML(java.lang.String buffer,
                      java.lang.String attrs)
               throws Asn1Exception
This method decodes an ASN.1 octet string type using the XML schema encoding rules.

Specified by:
decodeXML in interface Asn1TypeIF
Overrides:
decodeXML in class Asn1Type
Parameters:
buffer - String containing data to be decoded
attrs - Attributes string from element tag
Throws:
Asn1Exception

decode

public void decode(Asn1JsonDecodeBuffer buffer)
            throws java.io.IOException
Decode ASN.1 octet string from JSON.

Parameters:
buffer -
Throws:
java.io.IOException

encode

public void encode(Asn1JsonOutputStream outstream)
            throws java.io.IOException
Encode this octet string to JSON.

Parameters:
outstream -
Throws:
java.io.IOException

encodeBase64Binary

public static java.lang.String encodeBase64Binary(byte[] data)
Encodes bytes into base64 ASCII characters using the algorithm defined in RFC2045, as defined in w3c stadard http://www.w3.org/tr/2001/rec-xmlschema-2-20010502#base64Binary

Parameters:
data - Array containing bytes to be encoded
Returns:
Encoded ASCII string

equals

public boolean equals(byte[] value)
This method compares this octet string value to the given value for equality.

Parameters:
value - Byte array containing octet data

equals

public boolean equals(java.lang.Object os)
This method compares this octet string value to the given value for equality.

Overrides:
equals in class java.lang.Object
Parameters:
os - Asn1OctetString object to compare

hashCode

public int hashCode()
This method returns the hashcode for the Asn1OctetString.

Overrides:
hashCode in class Asn1Type

getLength

public int getLength()
              throws Asn1InvalidLengthException
This method will return the length of the OCTET STRING in octets.

Overrides:
getLength in class Asn1Type
Returns:
Number of octets.
Throws:
Asn1InvalidLengthException

toInputStream

public java.io.InputStream toInputStream()
This method will return a byte array input stream representation of the octet string value.

Returns:
Reference to input stream object

toString

public java.lang.String toString()
This method will return a string representation of the octet string value. The format is the ASN.1 value format for this type..

Overrides:
toString in class java.lang.Object
Returns:
Stringified representation of the value

encode

public void encode(Asn1BerOutputStream out,
                   boolean explicit)
            throws Asn1Exception,
                   java.io.IOException
This method encodes and writes to the stream an ASN.1 octet string value including the UNIVERSAL tag value and length if explicit tagging is specified. This overloaded version uses the Basic Encoding Rules (BER).

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1Type
Parameters:
out - BER Output Stream object
explicit - Flag indicating explicit tagging should be done
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encode

public void encode(Asn1PerOutputStream out)
            throws Asn1Exception,
                   java.io.IOException
This method encodes an unconstrained ASN.1 octet string value using the packed encoding rules (PER). The value to be encoded is stored in the 'value' public member variable within this class.

Specified by:
encode in interface Asn1TypeIF
Overrides:
encode in class Asn1Type
Parameters:
out - PER Output Stream object
Throws:
java.io.IOException - Any exception thrown by the Asn1PerOutputStream.
Asn1Exception - Thrown, if operation is failed.

encode

public void encode(Asn1PerOutputStream out,
                   long lower,
                   long upper)
            throws Asn1Exception,
                   java.io.IOException
This method encodes a size-constrained ASN.1 octet string value using the packed encoding rules (PER). The value to be encoded is stored in the 'value' public member variable within this class.

Parameters:
out - PER Output Stream object
lower - Lower bound (inclusive) of size constraint
upper - Upper bound (inclusive) of size constraint
Throws:
java.io.IOException - Any exception thrown by the Asn1PerOutputStream.
Asn1Exception - Thrown, if operation is failed.

encode

public void encode(Asn1MderOutputStream out)
            throws Asn1Exception,
                   java.io.IOException
Encode this octet string into the MDER encoding. This should be used for octet string types that are not of fixed length.

Throws:
Asn1MderUnsupported - if the actual length > 65535 (maximum allowed by MDER).
Asn1Exception
java.io.IOException

encode

public void encode(Asn1MderOutputStream out,
                   int constrainedLength)
            throws Asn1Exception,
                   java.io.IOException
Encode this octet string into the MDER encoding.

Parameters:
constrainedLength - The constrained length of the type being encoded. Pass -1 if the type is unconstrained.
Throws:
Asn1ConsVioException - if a constrained length is given and the value is not exactly that length.
Asn1MderUnsupported - if the length is unconstrained and the actual length > 65535 (maximum allowed by MDER).
Asn1Exception
java.io.IOException