org.mozilla.jss.pkix.primitive

Class DirectoryString

Implemented Interfaces:
ASN1Value

public class DirectoryString
extends java.lang.Object
implements ASN1Value

An X.500 DirectoryString. DirectoryString is defined as follows:
 DirectoryString ::= CHOICE {
      teletexString               TeletexString (SIZE (1..MAX)),
      printableString             PrintableString (SIZE (1..MAX)),
      universalString             UniversalString (SIZE (1..MAX)),
      utf8String                  UTF8String (SIZE (1..MAX)),
      bmpString                   BMPString (SIZE (1..MAX))  }
 

Nested Class Summary

static class
DirectoryString.Template
A Template for decoding DirectoryStrings from their BER encoding.

Constructor Summary

DirectoryString(String s)
Encodes a Java String into a Directory String.
DirectoryString(CharacterString s)
Creates a DirectoryString from an ASN.1 string.

Method Summary

void
encode(OutputStream ostream)
Write this value's DER encoding to an output stream using its own base tag.
void
encode(Tag implicitTag, OutputStream ostream)
Write this value's DER encoding to an output stream using an implicit tag.
Tag
getTag()
Returns the base tag for this type, not counting any tags that may be imposed on it by its context.
static DirectoryString.Template
getTemplate()
Returns a singleton instance of the decoding template for this class.
String
toString()
Converts an ASN.1 DirectoryString to a Java string.

Constructor Details

DirectoryString

public DirectoryString(String s)
            throws CharConversionException
Encodes a Java String into a Directory String. The following rules for choosing an encoding are from the IETF PKIX document Internet X.509 Public Key Infrastructure: Certificate and CRL Profile:
  • The preferred encoding is UTF8String, and all certificates issued after December 31, 2003, MUST use UTF8String encoding, with a few exceptions.
  • Until December 31, 2003, strings that fit in the PrintableString character set MAY use PrintableString.
  • Until December 31, 2003, string that fit in the BMPString character set MAY use BMPString.
  • Strings that fit in neither the PrintableString nor the BMPString character set MUST use UTF8String.
This is all very nice, but for backwards compatibility, what we really do is:
  • Try PrintableString
  • Try TeletexString
  • Try UniversalString

DirectoryString

public DirectoryString(CharacterString s)
Creates a DirectoryString from an ASN.1 string.
Parameters:
s - Must be a TeletexString, PrintableString, UniversalString, UTF8String, or BMPString.

Method Details

encode

public void encode(OutputStream ostream)
            throws IOException
Write this value's DER encoding to an output stream using its own base tag.
Specified by:
encode in interface ASN1Value

encode

public void encode(Tag implicitTag,
                   OutputStream ostream)
            throws IOException
Write this value's DER encoding to an output stream using an implicit tag.
Specified by:
encode in interface ASN1Value

getTag

public Tag getTag()
Returns the base tag for this type, not counting any tags that may be imposed on it by its context.
Specified by:
getTag in interface ASN1Value

getTemplate

public static DirectoryString.Template getTemplate()
Returns a singleton instance of the decoding template for this class.

toString

public String toString()
Converts an ASN.1 DirectoryString to a Java string.
Parameters: