codec.asn1
Class ASN1AbstractString

java.lang.Object
  |
  +--codec.asn1.ASN1AbstractType
        |
        +--codec.asn1.ASN1AbstractString
All Implemented Interfaces:
ASN1String, ASN1Type, Cloneable, Externalizable, Serializable
Direct Known Subclasses:
ASN1BMPString, ASN1IA5String, ASN1PrintableString, ASN1T61String, ASN1UniversalString, ASN1UTF8String, ASN1VisibleString

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 ASN1BMPString handles 2-octet conversion and class ASN1UniversalString 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,v 1.4 2004/08/26 15:08:21 pebinger Exp $"
Author:
Volker Roth
See Also:
Serialized Form

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)
           
 boolean equals(Object s)
          Indicates whether some other ASN.1 string is "equal to" this one.
 String getString()
          Returns the represented string value.
 Object getValue()
          Returns the represented string value.
 int hashCode()
          Returns a hash code value for the object calculated from the contained String.
 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, readExternal, setConstraint, setExplicit, setOptional, writeExternal
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface codec.asn1.ASN1Type
checkConstraints, getConstraint, getTag, getTagClass, isExplicit, isOptional, isType, setConstraint, setExplicit, setOptional
 

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:
s - The string value.
Method Detail

getValue

public Object getValue()
Returns the represented string value.
Specified by:
getValue in interface ASN1Type
Overrides:
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
Overrides:
encode in class ASN1AbstractType

decode

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

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 - never, only for compliance with the ASN1String interface.

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 - never, only for compliance with the ASN1String interface.

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 - never, only for compliance with the ASN1String interface.

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object s)
Indicates whether some other ASN.1 string is "equal to" this one.
Overrides:
equals in class Object
Parameters:
s - the reference string with which to compare.
Returns:
true if this string is the same as the s argument; false otherwise.
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Returns a hash code value for the object calculated from the contained String.
Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
Object.hashCode()


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.