iaik.asn1
Class UNIString

java.lang.Object
  |
  +--iaik.asn1.ASN1Object
        |
        +--iaik.asn1.UNIString

public class UNIString
extends ASN1Object

This class implements the native ASN.1 type "UniveralString". UNIString is a simple ASN.1 string type identified by the UNIVERSAL TAG number 28.

UniversalString is defined in ASN.1:1993.

When creating a new UNIString object the value to be represented has to be supplied as Java String type:

 String s = ...;
 UNIString uniString = new UNIString(s);
 
Attention: When supplying the string value to be represented, no check is performed if it actually is composed only of characters belonging to UniversalString character set! An application itself has to take care for supplying a proper UniversalString value.

When calling the getValue method for getting the inherent string value from an ASN.1 UNIString instance, a Java object of type String is returned:

 String s = (String)uniString.getValue();
 
DER en/decoding generally is done by means of the several methods of the DerCoder class; decoding alternatively may be performed by using the DerInputStream utility.

Attention! Since Java characters are UNICODE (16 bit), but UNIVERSAL STRING uses 32 bit, wrong (de)coding results may occur when charcaters occupy more than 16 bits!

See Also:
ASN1Object, ASN

Fields inherited from class iaik.asn1.ASN1Object
asnType, encode_listener, stream_mode
 
Constructor Summary
protected UNIString()
          Creates an empty UNIString.
  UNIString(java.lang.String value)
          Creates a new ASN.1 UNIString object for the given String value.
 
Method Summary
protected  void decode(int length, java.io.InputStream is)
          Decodes an UNIString value from the given InputStream.
protected  void encode(java.io.OutputStream os)
          DER encodes this UNIString ASN1Object and writes the result to the given output stream.
 java.lang.Object getValue()
          Returns the value of this UNIString as a String object.
 void setValue(java.lang.Object object)
          Sets the value of this UNIString.
 java.lang.String toString()
          Returns a string that represents the contents of this UNIString.
 
Methods inherited from class iaik.asn1.ASN1Object
addComponent, addEncodeListener, countComponents, encodeObject, getAsnType, getComponentAt, indefiniteLength, isA, isConstructed, setIndefiniteLength, setIndefiniteRecursive
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UNIString

protected UNIString()
Creates an empty UNIString.

UNIString

public UNIString(java.lang.String value)
Creates a new ASN.1 UNIString object for the given String value.

Attention: No check is performed if the supplied String value actually is composed only of characters belonging to the UniversalString character set! An application itself has to take care for supplying a proper UniversalString value.

Parameters:
value - the String value this UNIString object should be initialized with
Method Detail

getValue

public java.lang.Object getValue()
Returns the value of this UNIString as a String object.
Overrides:
getValue in class ASN1Object
Returns:
the value of this UNIString as a String object

setValue

public void setValue(java.lang.Object object)
Sets the value of this UNIString.

The supplied value has to be a Java object of type String. Attention: No check is performed if the supplied String value actually is composed only of characters belonging to UniversalString character set! An application itself has to take care for supplying a proper UniversalString value.

Overrides:
setValue in class ASN1Object
Parameters:
object - the Java String value to be set for this UNIString

encode

protected void encode(java.io.OutputStream os)
               throws java.io.IOException
DER encodes this UNIString ASN1Object and writes the result to the given output stream.

This is a protected method and will not be used by an application for DER encoding an UNIString object. An application will call one of the encode methods of the DerCoder class for performing the encoding, and the DerCoder internally will call this encode method. AttentionUNIVERSAL STRING uses 32 bit character encoding. This method only converts each character to an 32 bit representation by setting the three high-order bytes to zero. So for characters "out of range" the encoding may give a wrong result!

Overrides:
encode in class ASN1Object
Parameters:
os - the output stream to which to write the data
Throws:
java.io.IOException - if an I/O error occurs while writing to the stream

decode

protected void decode(int length,
                      java.io.InputStream is)
               throws java.io.IOException
Decodes an UNIString value from the given InputStream. The given input stream carries DER encoded data, and the next length bytes to be read represent the value of an ASN.1 object of type UNIString.

This is a protected method and will not be used by an application for decoding a DER encoded UNIString. An application will call one of the decode methods of the DerCoder class for performing the decoding. The DerCoder then determines the number of bytes (length) occupied by the value of this UniversalString object and internally calls this decode method for actually reading the value. No check is performed if the received value actually is composed only of characters belonging to the UniversalString character set!

Attention! Since Java characters are UNICODE (16 bit), but UNIVERSAL STRING uses 32 bit, wrong (de)coding results may occur when charcaters occupy more than 16 bits!

Overrides:
decode in class ASN1Object
Parameters:
length - the already decoded length, i.e. number of the bytes representing the value of the UNIString to be decoded
is - the input stream from which the DER encoded data is read in
Throws:
java.io.IOException - if there is a problem with the InputStream

toString

public java.lang.String toString()
Returns a string that represents the contents of this UNIString.
Overrides:
toString in class ASN1Object
Returns:
the string representation
See Also:
ASN1Object.toString()