iaik.utils
Class RFC2253NameParser

java.lang.Object
  |
  +--iaik.utils.RFC2253NameParser

public class RFC2253NameParser
extends Object

Implements functionality to parse the UTF-8 string representation of a X.501 Name, according to RFC 2253. This class may be used for converting a RFC 2253 string representation of a X.501 Name into a iaik.asn1.structures.Name object.

For converting a RFC 2253 string first create a new #RFC2253NameParser object and supply the string to be converted. Subsequently simply call method parse to get the Name object, e.g.:

 String rcf2253Name = "CN=Gregor Karlinger,O=IAIK,C=AT";
 RFC2253NameParser nameParser = new RFC2253NameParser(rcf2253Name);
 iaik.asn1.structures.Name = nameParser.parse();
 
Attention! When using this parser, please be aware that a valid transformation from an RFC 2253 string to a Distinguished Name (rspectively its encoding) only can be done when the RFC 2253 string gives a hexadecimal representation of the encoding. See RFC 2253, section 7.2: 7.2. Use of Distinguished Names in Security Applications The transformations of an AttributeValue value from its X.501 form to an LDAP string representation are not always reversible back to the same BER or DER form. An example of a situation which requires the DER form of a distinguished name is the verification of an X.509 certificate. For example, a distinguished name consisting of one RDN with one AVA, in which the type is commonName and the value is of the TeletexString choice with the letters 'Sam' would be represented in LDAP as the string CN=Sam. Another distinguished name in which the value is still 'Sam' but of the PrintableString choice would have the same representation CN=Sam. Applications which require the reconstruction of the DER form of the value SHOULD NOT use the string representation of attribute syntaxes when converting a distinguished name to the LDAP format. Instead, they SHOULD use the hexadecimal form prefixed by the octothorpe ('#') as described in the first paragraph of section 2.4. As specified by RFC 2253 this parser expects a hexadecimal representation when the AttributeType is given in the dotted-decimal form, e.g.:
 1.3.6.1.4.1.1466.0=#04024869
 

Version:
File Revision 19

Inner Class Summary
protected  class RFC2253NameParser.AVA
          Represents the parsing result for a Attribute-Value-Assertion.
protected  class RFC2253NameParser.ParsedName
          Represents the parsing result for a Name.
protected  class RFC2253NameParser.ParsedRDN
          Represents the parsing result for a Relative Distinguished Name.
protected  class RFC2253NameParser.ShortNameOIDAssociation
          Provides functionality to map a Short Name of an well known Object Identifier to the corresponding Object Identifier.
 
Field Summary
protected static Hashtable associations_
          Repository for mapping shortNames to OIDs.
protected  RFC2253NameParser.ParsedName name_
          Collects the parsing results.
protected  StringBuffer nameStrBuf_
          The name to be parsed as StringBuffer.
protected  int position_
          The current parsing position within nameStrBuf_ to be parsed.
 
Constructor Summary
RFC2253NameParser(String name)
          Standard constructor.
 
Method Summary
 Name parse()
          Parses the name string, which has been set in the constructor.
protected  String parseAttrType()
          Parses the type of an Attribute-Value-Assertion, starting from the position indicated by the current value of the member variable position_.
protected  RFC2253NameParser.AVA parseAttrValue()
          Parses the value of an Attribute-Value-Assertion, starting from the position indicated by the current value of the member variable position_.
protected  RFC2253NameParser.AVA parseAVA()
          Parses an Attribute-Value-Assertion, starting from the position indicated by the current value of the member variable position_.
protected  char parseHexPair()
          Parses a pair of two characters representing the hex value of a character, starting from the position indicated by the current value of the member variable position_.
protected  char parseHexPairEscapeSequence()
           
protected  RFC2253NameParser.ParsedRDN parseRDN()
          Parses a Relative distinguished Name, starting from the position indicated by the current value of the member variable position_.
static void register(String shortName, ObjectID oid)
          Associates the supplied short name with the given OID.
protected  void skipOIDIntro()
          Checks if the next for characters, starting at position position_ equal the String "OID." (case will be ignored).
protected  void skipSpace()
          Increases the member variable position_ as long as the character at position position_ does not equal the space character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

associations_

protected static Hashtable associations_
Repository for mapping shortNames to OIDs.

name_

protected RFC2253NameParser.ParsedName name_
Collects the parsing results.

position_

protected int position_
The current parsing position within nameStrBuf_ to be parsed.

nameStrBuf_

protected StringBuffer nameStrBuf_
The name to be parsed as StringBuffer.
Constructor Detail

RFC2253NameParser

public RFC2253NameParser(String name)
Standard constructor. Initializes a new parser with the name to be parsed.
Parameters:
name - The ISO 10646 string to be parsed.
Method Detail

register

public static void register(String shortName,
                            ObjectID oid)
Associates the supplied short name with the given OID.

This method allows an application to register additional shortName -- OID associations. The foolowing associations are already registered:

 "CN" ....... commonName ("2.5.4.3")
 "SN" ....... surName ("2.5.4.4")
 "C"  ....... countryName ("2.5.4.6")
 "L"  ....... localityName ("2.5.4.7")
 "ST" ....... stateOrProvinceName ("2.5.4.8")
 "STREET" ... streetAddress ("2.5.4.9")
 "O"  ....... organizationName ("2.5.4.10")
 "OU" ....... organizationUnitName ("2.5.4.11")
 "T"  ....... title ("2.5.4.12")
 "DC" ....... domainComponent ("0.9.2342.19200300.100.1.25")
 "UID" ...... userid ("0.9.2342.19200300.100.1.1")
 "EMail" .... emailAddress ("1.2.840.113549.1.9.1")
 "E" ........ emailAddress ("1.2.840.113549.1.9.1")
 "EA" ....... emailAddress ("1.2.840.113549.1.9.1")
 "MAIL" ..... emailAddress ("1.2.840.113549.1.9.1")
 "EMAIL" .... emailAddress ("1.2.840.113549.1.9.1")
 "serialNumber" ....... serialNumber ("2.5.4.5")
 "postalAddress" ...... postalAddress ("2.5.4.16")
 "postalCode" ......... postalCode ("2.5.4.17")
 "telephoneNumber" .... telephoneNumber ("2.5.4.20")
 "telexNumber" ........ telexNumber ("2.5.4.21");
 
Notice that calling this method for one of the registered shortName will replace the corresponding registration entry.
Parameters:
shortName - the short name to be associated with an OID
oid - the object identifier for the short name in mind

parse

public Name parse()
           throws RFC2253NameParserException
Parses the name string, which has been set in the constructor.
Returns:
a Name object representing the structure of the parsed X.501 Name.
Throws:
RFC2253NameParserException - if the name string could not be parsed successfully.

parseRDN

protected RFC2253NameParser.ParsedRDN parseRDN()
                                        throws RFC2253NameParserException
Parses a Relative distinguished Name, starting from the position indicated by the current value of the member variable position_.
Returns:
a ParsedRDN object representing the structure of the parsed RDN.
Throws:
RFC2253NameParserException - if the RDN could not be parsed successfully.

parseAVA

protected RFC2253NameParser.AVA parseAVA()
                                  throws RFC2253NameParserException
Parses an Attribute-Value-Assertion, starting from the position indicated by the current value of the member variable position_.
Returns:
a AVA object representing the structure of the parsed AVA.
Throws:
RFC2253NameParserException - if the AVA could not be parsed successfully.

parseAttrType

protected String parseAttrType()
                        throws RFC2253NameParserException
Parses the type of an Attribute-Value-Assertion, starting from the position indicated by the current value of the member variable position_.
Returns:
a String representing the type of a AVA.
Throws:
RFC2253NameParserException - if the AVA type could not be parsed successfully.

parseAttrValue

protected RFC2253NameParser.AVA parseAttrValue()
                                        throws RFC2253NameParserException
Parses the value of an Attribute-Value-Assertion, starting from the position indicated by the current value of the member variable position_.
Returns:
a AVA object with its value_ and hasHexValue_ fields set.
Throws:
RFC2253NameParserException - if the AVA value could not be parsed successfully.

parseHexPair

protected char parseHexPair()
                     throws RFC2253NameParserException
Parses a pair of two characters representing the hex value of a character, starting from the position indicated by the current value of the member variable position_.
Returns:
the character represented by the hex pair.
Throws:
RFC2253NameParserException - if the next two characters cannot be interpreted as hex pair.

parseHexPairEscapeSequence

protected char parseHexPairEscapeSequence()
                                   throws RFC2253NameParserException

skipSpace

protected void skipSpace()
Increases the member variable position_ as long as the character at position position_ does not equal the space character.

skipOIDIntro

protected void skipOIDIntro()
Checks if the next for characters, starting at position position_ equal the String "OID." (case will be ignored). If yes, increases position_ by 4.

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK