codec.asn1
Class ASN1AbstractString

java.lang.Object
  extended by codec.asn1.ASN1AbstractType
      extended by codec.asn1.ASN1AbstractString
All Implemented Interfaces:
ASN1String, ASN1Type, Cloneable
Direct Known Subclasses:
ASN1BMPString, ASN1IA5String, ASN1PrintableString, ASN1T61String, ASN1UniversalString, ASN1UTF8String

public abstract class ASN1AbstractString
extends ASN1AbstractType
implements ASN1String

The root class of all ASN.1 string types including but not limited to IA5String, VisibleString, PrintableString, UTCTime, and GeneralizedTime.

Each string type is encoded as if it is declared as [UNIVERSAL x] IMPLICIT OCTET STRING where x is the tag number of the respective string type (see ITU-T Rec. X.690, paragraph 8.20.3).

There are 8 restructed string types of which 4 do not allow escape sequences, namely NumericString, PrintableString, VisibleString (ISO646String) and IA5String. TeletexString (T61String), VideotextString, GraphicString, and GeneralString allow the use of escape sequences. However, the srings must be encoded such as to use the minimum number of octets possible. All these strings use 1-octet representations; IA5String uses 2-octet representations for special characters.

Two unrestricted string types are defined in X.680, namely BMPString and UniversalString. BMPString uses a 2-octet representation per character and UniversalString uses a 4-octet representation.

Each string type represented in this package handles octets to character and character to octets conversion according to the general coding scheme of the particular string, but not neccessarily restriction to a particular character set. This is to be implemented through constraints that are added to the respective types on creation (in the constructors). Restriction of character sets is thus done on the Unicode character set used by Java.

This class implements plain 1-octet to character conversion by default. Class BMPString handles 2-octet conversion and class UniversalString handles 4-octets conversion. Without reference to ISO defined character encodings these implementations assume that the n-octet tuples represent the least significant bits of the Unicode characters with the corresponding bits set to zero.

Version:
"$Id: ASN1AbstractString.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth

Field Summary
private static String DEFAULT_VALUE
           
private  String value_
           
 
Constructor Summary
ASN1AbstractString()
           
ASN1AbstractString(String s)
          Creates an instance with the given string value.
 
Method Summary
 String convert(byte[] b)
          Converts the given byte array to a string by filling up each consecutive byte with 0's to the size of the Unicode characters.
 byte[] convert(String s)
          Converts the given string to a byte array by chopping away all but the least significant byte of each character.
 int convertedLength(String s)
          Returns the number of bytes required to store the converted string.
 void decode(Decoder enc)
           
 void encode(Encoder enc)
           
 String getString()
          Returns the represented string value.
 Object getValue()
          Returns the represented string value.
 void setString(String s)
          Sets the string value.
protected  void setString0(String s)
           
 String toString()
           
 
Methods inherited from class codec.asn1.ASN1AbstractType
checkConstraints, getConstraint, getTag, getTagClass, isExplicit, isOptional, isType, setConstraint, setExplicit, setOptional
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface codec.asn1.ASN1Type
checkConstraints, getConstraint, getTag, getTagClass, isExplicit, isOptional, isType, setConstraint, setExplicit, setOptional
 

Field Detail

DEFAULT_VALUE

private static final String DEFAULT_VALUE
See Also:
Constant Field Values

value_

private String value_
Constructor Detail

ASN1AbstractString

public ASN1AbstractString()

ASN1AbstractString

public ASN1AbstractString(String s)
Creates an instance with the given string value. This constructor calls setString to set the string value.

Parameters:
The - string value.
Method Detail

getValue

public Object getValue()
Returns the represented string value.

Specified by:
getValue in interface ASN1Type
Specified by:
getValue in class ASN1AbstractType
Returns:
The string value of this type.

getString

public String getString()
Returns the represented string value.

Specified by:
getString in interface ASN1String
Returns:
The string value of this type.

setString

public void setString(String s)
               throws ConstraintException
Sets the string value.

Specified by:
setString in interface ASN1String
Parameters:
s - The string value.
Throws:
ConstraintException - if the given string does not match the constraint set for this instance.

setString0

protected void setString0(String s)

encode

public void encode(Encoder enc)
            throws ASN1Exception,
                   IOException
Specified by:
encode in interface ASN1Type
Specified by:
encode in class ASN1AbstractType
Throws:
ASN1Exception
IOException

decode

public void decode(Decoder enc)
            throws ASN1Exception,
                   IOException
Specified by:
decode in interface ASN1Type
Specified by:
decode in class ASN1AbstractType
Throws:
ASN1Exception
IOException

convert

public String convert(byte[] b)
               throws ASN1Exception
Converts the given byte array to a string by filling up each consecutive byte with 0's to the size of the Unicode characters.

Specified by:
convert in interface ASN1String
Parameters:
b - The byte array to convert.
Throws:
ASN1Exception

convert

public byte[] convert(String s)
               throws ASN1Exception
Converts the given string to a byte array by chopping away all but the least significant byte of each character.

Specified by:
convert in interface ASN1String
Parameters:
s - The string to convert.
Throws:
ASN1Exception

convertedLength

public int convertedLength(String s)
                    throws ASN1Exception
Returns the number of bytes required to store the converted string.

Specified by:
convertedLength in interface ASN1String
Parameters:
s - The string.
Throws:
ASN1Exception

toString

public String toString()
Overrides:
toString in class Object


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.