iaik.asn1.structures
Class Name

java.lang.Object
  |
  +--iaik.asn1.structures.Name
All Implemented Interfaces:
ASN1Type, Principal

public class Name
extends Object
implements Principal, ASN1Type

This class represents a X.500 Name structure (Distinguished Name). A distinguished name is defined as a sequence of Relative Distinguished Names:

Name ::= SEQUENCE OF RelativeDistinguishedName

A Name object may be used for specifying, e.g. issuer and subject within a X.509 certificate. For creating a Name structure, use a proper constructor. You later may supply the relative distinguished names constituting your actual Name object by repeatedly calling the addRDN method, e.g.:

  Name subject = new Name();
  subject.addRDN(ObjectID.country, "AT");
  subject.addRDN(ObjectID.locality, "Graz");
  subject.addRDN(ObjectID.organization ,"TU Graz");
  subject.addRDN(ObjectID.organizationalUnit ,"IAIK");
  subject.addRDN(ObjectID.commonName ,"TestUser");
 
This class also allows to add more than one RDN of the same attribute type.

Version:
File Revision 25

Constructor Summary
Name()
          The default constructor.
Name(ASN1Object obj)
          Constructs a Name from an ASN1Object.
Name(byte[] name)
          Creates a name from a DER encoded byte array.
 
Method Summary
 void addRDN(ObjectID oid, Object value)
          Adds a RelativeDistinguishedName with given attribute type and value to this Name.
 void addRDN(RDN rdn)
          Adds a RelativeDistinguishedName to this Name.
 void decode(ASN1Object obj)
          Decodes a Name from the given ASN1Object.
 Enumeration elements()
          Returns an enumeration of all RDNs included in this Name.
 boolean equals(Object obj)
          Compares this Name to the specified object.
 byte[] getEncoded()
          Returns this Name as DER encoded byte array.
 String getName()
          Returns a string that represents this Name.
 String getRDN(ObjectID oid)
          Returns the RDN value assigned to a given ObjectID.
 String[] getRDNs(ObjectID oid)
          Returns the values of all RDNs assigned to a given ObjectID.
 Object getRDNValue(ObjectID oid)
          Returns the RDN value assigned to a given ObjectID.
 Object[] getRDNValues(ObjectID oid)
          Returns the values of all RDNs assigned to a given ObjectID.
 String getRFC2253String()
          Returns a string representation of this Name according to RFC 2253.
 int hashCode()
          Returns a hashcode for this Name.
 boolean isEmpty()
          Checks if there are any RDNs included in this Name.
 boolean removeRDN(ObjectID oid)
          Removes all RelativeDistinguishedNames with the given attribute type (oid) from this Name.
 ASN1Object toASN1Object()
          Returns this Name as ASN1Object.
 String toString()
          Returns a string that represents this Name.
 String toString(boolean detailed)
          Returns a string that represents this Name.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Name

public Name()
The default constructor.

Name

public Name(byte[] name)
     throws CodingException
Creates a name from a DER encoded byte array. The supplied byte array represents the DER encoding of an already existing Name object.
Parameters:
name - a DER encoded Name

Name

public Name(ASN1Object obj)
     throws CodingException
Constructs a Name from an ASN1Object. The supplied ASN1Object could be the ASN.1 type "Sequence of RelativeDistinguishedName" or only a SET if there would be just one element in the Sequence.
Parameters:
obj - the Name as ASN1Object
Throws:
CodingException - if the ASN1Object has the wrong format
Method Detail

decode

public void decode(ASN1Object obj)
            throws CodingException
Decodes a Name from the given ASN1Object.
Specified by:
decode in interface ASN1Type
Parameters:
obj - the Name as ASN1Object
Throws:
CodingException - if the ASN1Object has the wrong format

getRDN

public String getRDN(ObjectID oid)
Returns the RDN value assigned to a given ObjectID. The inherent RDN objects are searched for the given objectID (attribute type). The value of first RDN with the requested ObjectID is returned. If no RDN with such an ObjectID (attribute type) is included, null is returned.

Attention! This method only may be used for querying for a String RDN value. If you expect a non-string value (e.g. when searching for a uniqueIdentifier), use method getRDNValue which returns the value as Java object.

Parameters:
oid - the ObjectID of the RDN (attribute) type to be searched for
Returns:
the value (as Java String) of the first RDN having the requested ObjectID; or null if no RDN of the requested type (oid) is included

getRDNs

public String[] getRDNs(ObjectID oid)
Returns the values of all RDNs assigned to a given ObjectID.

Some CAs support certificates where the subject name may have multiple RDNs of same attribute type (ObjectID), e.g. two organizationalUnit entries. More than one RDN of same attribute type may be added to a Name structure by repeatedly calling the addRDN method with the same objectID (attribute type), e.g.:

 name.addRDN(ObjectID.organizationalUnit,"...");
 name.addRDN(ObjectID.organizationalUnit,"...");
   ...
 
When calling this getRDNs method, all the inherent RDN objects are searched for the given objectID (attribute type). Any detected value contributes to a String array returning the values of all included RDN objects with the requested attribute type (oid). If no RDN with such an ObjectID (attribute type) is included, null is returned. Attention! This method only may be used for querying for String RDN values. If you expect non-string values (e.g. when searching for a uniqueIdentifier), use method getRDNValues which returns the values as an array of Java objects.

Parameters:
oid - the ObjectID of the RDN (attribute) type to be searched for
Returns:
the values (as array of Strings) of all included RDNs having the requested ObjectID; or null if no RDN of the requested type (oid) is included

getRDNValue

public Object getRDNValue(ObjectID oid)
Returns the RDN value assigned to a given ObjectID. The inherent RDN objects are searched for the given objectID (attribute type). The value of first RDN with the requested ObjectID is returned. If no RDN with such an ObjectID (attribute type) is included, null is returned.
Parameters:
oid - the ObjectID of the RDN (attribute) type to be searched for
Returns:
the value (as Java Object) of the first RDN having the requested ObjectID; or null if no RDN of the requested type (oid) is included

getRDNValues

public Object[] getRDNValues(ObjectID oid)
Returns the values of all RDNs assigned to a given ObjectID.

Some CAs support certificates where the subject name may have multiple RDNs of same attribute type (ObjectID), e.g. two organizationalUnit entries. More than one RDN of same attribute type may be added to a Name structure by repeatedly calling the addRDN method with the same objectID (attribute type), e.g.:

 name.addRDN(ObjectID.organizationalUnit,"...");
 name.addRDN(ObjectID.organizationalUnit,"...");
   ...
 
When calling this getRDNs method, all the inherent RDN objects are searched for the given objectID (attribute type). Any detected value contributes to a String array returning the values of all included RDN objects with the requested attribute type (oid). If no RDN with such an ObjectID (attribute type) is included, null is returned.

Parameters:
oid - the ObjectID of the RDN (attribute) type to be searched for
Returns:
the values (as array of Java objects) of all included RDNs having the requested ObjectID; or null if no RDN of the requested type (oid) is included

elements

public Enumeration elements()
Returns an enumeration of all RDNs included in this Name.
Returns:
an enumeration of all included RDN objects

isEmpty

public boolean isEmpty()
Checks if there are any RDNs included in this Name.
Returns:
true if there are no RDNs, false otherwise

addRDN

public void addRDN(ObjectID oid,
                   Object value)
Adds a RelativeDistinguishedName with given attribute type and value to this Name.
Parameters:
oid - the ObjectID (attribute type) of the RDN to be added
value - the value of the RDN to be added

addRDN

public void addRDN(RDN rdn)
Adds a RelativeDistinguishedName to this Name.
Parameters:
rdn - the RDN to be added

removeRDN

public boolean removeRDN(ObjectID oid)
Removes all RelativeDistinguishedNames with the given attribute type (oid) from this Name.
Parameters:
oid - the ObjectID (attribute type) of the RDN which shall be removed
Returns:
true if some RDN(s) have been removed; false if no RDN has been removed, since no RDN of the requested type is included in this Name

toASN1Object

public ASN1Object toASN1Object()
Returns this Name as ASN1Object.
Specified by:
toASN1Object in interface ASN1Type
Returns:
this Name as ASN1Object

getEncoded

public byte[] getEncoded()
Returns this Name as DER encoded byte array.
Returns:
this Name as DER encoded byte array

hashCode

public int hashCode()
Returns a hashcode for this Name.
Specified by:
hashCode in interface Principal
Overrides:
hashCode in class Object
Returns:
a hashcode for this Name

equals

public boolean equals(Object obj)
Compares this Name to the specified object.
Specified by:
equals in interface Principal
Overrides:
equals in class Object
Parameters:
obj - - the object to compare this Name against.
Returns:
true, if the object represents the same Name false otherwise

getName

public String getName()
Returns a string that represents this Name.
Specified by:
getName in interface Principal
Returns:
the string representation of this Name

toString

public String toString()
Returns a string that represents this Name.
Specified by:
toString in interface Principal
Overrides:
toString in class Object
Returns:
the string representation

toString

public String toString(boolean detailed)
Returns a string that represents this Name.
Parameters:
detailed - true if no shortNames shall be used when printing the attribute types of the AVAs
Returns:
the string representation

getRFC2253String

public String getRFC2253String()
                        throws RFC2253NameParserException
Returns a string representation of this Name according to RFC 2253.

RFC 2253 specifies a string representation of Distinguished Names as used for LDAP lookups.

The included RDNs are represented in reversed order starting with the last element and moving to the first. Adjoining RDNs are separated by a comma (",").

The AttributeTypeAndValues of each included RDN are represented as specified in sections 2.3, 2.4 of RFC 2253 (adjoining AttributeTypeAndValues (or AVAs) are separated by a plus ("+") character):

The attribute type is represented as described in section 2.3 of RFC 2253. If there is no known name string for the attribute type a dotted-decimal encoding of the attribute type´s identifier.

The string representation of the attribute value is either a hexadecimal represenation of its BER encoding (introduced by a "#" character) or based on the algorithm given in section 2.4 of RFC 2253 applying the following escaping mechanisms:

Additionally this method escapes Any non printable ASCII (< 0x21 or > 0x7e) and any non-ASCII character by an hexadecimal representation of its UTF-8 encoding. The space character (0x21) only is escaped when appearing at the beginning or the end of the string.
Returns:
the string representation according to RFC 2253.
Throws:
RFC2253NameParserException - if the AVA cannot be represented according to the rules above

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