com.rsa.certj.cert

Class RDN

java.lang.Object
  |
  +--com.rsa.certj.cert.RDN
All Implemented Interfaces:
Cloneable, Serializable

public class RDN
extends Object
implements Cloneable, Serializable

This class builds and holds a relative distinguished name. The ASN.1 definition is as follows:

 RelativeDistinguishedName ::= SET SIZE (1..MAX) OF AttributeTypeAndValue

 AttributeTypeAndValue ::=	SEQUENCE
 	type	ATTRIBUTE.&id ({SupportedAttributes}),
 	value	({ATTRIBUTE.&Type ({SupportedAttributes}{@type})}

Supported attribute types (in the AttributeValueAssertion class):

Copyright © RSA Security Inc., 1998-2002. All rights reserved.

See Also

Serialized Form

Constructor Summary

RDN()

Constructs an empty RDN object.

RDN(byte[] rdnBER, int offset, int special)

Creates an RDN object and initializes it with the collection of attributes represented by rdnBER.

 

Method Summary

 void

addNameAVA(AttributeValueAssertion ava)

Adds the attribute value assertion to this RDN object.

 Object

clone()

Overrides the default clone method to get a deeper clone.

 boolean

equals(Object obj)

Returns true if this object and obj contain the same RDN, returns false otherwise.

 AttributeValueAssertion

getAttribute(int attributeType)

Gets the attribute of type attributeType from the RDN object.

 AttributeValueAssertion

getAttributeByIndex(int attributeIndex)

Gets the attribute at the specified index in the list.

 int

getAttributeCount()

Gets the number of attributes in this RDN object.

 int

getDEREncoding(byte[] encoding, int offset, int special)

Places the DER encoding of the RDN object into encoding, beginning at offset.

 int

getDERLen(int special)

Returns the number of bytes of the DER encoding of this RDN.

static int

getNextBEROffset(byte[] rdnBER, int offset)

Given rdnBER, the BER of a relative distinguished name beginning at offset, finds the index to the next element in the encoding.

 void

removeAVA(int index)

Deletes the AttributeValueAssertion object at the specified index.

 void

setAVA(AttributeValueAssertion name, int index)

Sets the new AttributeValueAssertion object at the specified index.

 String

toString()

Returns a String that describes this RDN.

 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RDN

public RDN(byte[] rdnBER,
           int offset,
           int special)
    throws NameException
Creates an RDN object and initializes it with the collection of attributes represented by rdnBER.

Parameters

         rdnBER  

A byte array that contains the BER encoding of the RDN object.

         offset  

The offset into rdnBER where the encoding begins.

         special  

The special circumstances of the BER encoding, if there are any. If there are no special circumstances, pass in special = 0.

Throws

NameException - If the encoding is invalid.

RDN

public RDN()
Constructs an empty RDN object. After this constructor is called, use the addNameAVA method to set the attributes for the RDN object.
Method Detail

clone

public Object clone()
             throws CloneNotSupportedException
Overrides the default clone method to get a deeper clone.

Returns

A new RDN object, a copy of this object.

Throws

CloneNotSupportedException - If the cloning operation is not successful.

toString

public String toString()
Returns a String that describes this RDN.

Overrides

toString in class Object

Returns

A String that describes this RDN.

getAttributeCount

public int getAttributeCount()
Gets the number of attributes in this RDN object.

Returns

The number of attributes in this RDN.

getAttributeByIndex

public AttributeValueAssertion getAttributeByIndex(int attributeIndex)
                                            throws NameException
Gets the attribute at the specified index in the list. If there is no attribute at the index given, then this method returns null.

Parameters

         attributeIndex  

The index into the list of attributes where the requested attribute is located.

Returns

The specified attribute.

Throws

NameException - If the index is invalid.

removeAVA

public void removeAVA(int index)
               throws NameException
Deletes the AttributeValueAssertion object at the specified index.

Parameters

         index  

The index to the specified AttributeValueAssertion object in the list.

Throws

NameException - If index is invalid.

setAVA

public void setAVA(AttributeValueAssertion name,
                   int index)
            throws NameException
Sets the new AttributeValueAssertion object at the specified index.

Parameters

         name  

A new AttributeValueAssertion object.

         index  

The index to the specified AttributeValueAssertion object in the list.

Throws

NameException - If index is invalid.

getAttribute

public AttributeValueAssertion getAttribute(int attributeType)
Gets the attribute of type attributeType from the RDN object. The attributeType will be one of the fields specified in the AttributeValueAssertion class, such as COUNTRY_NAME or COMMON_NAME. If the RDN object does not possess an attribute of type attributeType, the return value is null.

Parameters

         attributeType  

The flag indicating which attribute type is requested.

Returns

The attribute of type attributeType.

getNextBEROffset

public static int getNextBEROffset(byte[] rdnBER,
                                   int offset)
                            throws NameException
Given rdnBER, the BER of a relative distinguished name beginning at offset, finds the index to the next element in the encoding. In other words, gets the next offset after the RDN.

For example, if the offset is 120 and the BER encoding of the RDN is 1819 bytes, this method will return 1939, the index immediately following the RDN. That is, rdnBER[120] is the first byte in the encoding of the RDN, rdnBER>[1938] is the last byte in the encoding of the RDN, and the next element begins at index 1939.

Parameters

         rdnBER  

The BER encoding of a RDN.

         offset  

The offset into rdnBER where the encoding begins.

Returns

An int that contains the index to the next element in the BER encoding.

Throws

NameException - If the method cannot read the BER encoding.

getDERLen

public int getDERLen(int special)
Returns the number of bytes of the DER encoding of this RDN. If this object is not set with values, then this method returns zero.

Parameters

         special  

The special circumstances of the DER encoding, if there are any.

Returns

The number of bytes of the DER encoding of this RDN.

getDEREncoding

public int getDEREncoding(byte[] encoding,
                          int offset,
                          int special)
                   throws NameException
Places the DER encoding of the RDN object into encoding, beginning at offset. To determine the length of the encoding, call getDERLen. If this object is not yet set with a value, then this method places nothing into the array and returns zero.

The ASN.1 definition of an RDN (previously defined in this class) means the tag will be 0x31. However, a RDN object can be part of an X500Name (or some other construct), and it might have a different tag caused by IMPLICIT or EXPLICIT.

For example, suppose the definition is as follows:

      name   [1] IMPLICIT RDN   
In this case, the tag will change from 0x31 to 0xa1. To indicate that the DER encoding of the RDN object should follow any special circumstances, use the special argument.

For example, to indicate the following:

      name   [1] IMPLICIT RDN   
Pass in the following:

      special = (ASN1.CONTEXT_IMPLICIT | 1);

If there are no special circumstances, pass in the following:

     special = 0 
The following ASN.1 constants are possible values for special: APP_IMPLICIT, APP_EXPLICIT, PRIVATE_IMPLICIT, PRIVATE_EXPLICIT, OPTIONAL, DEFAULT, CONTEXT_IMPLICIT, or CONTEXT_EXPLICIT.

Parameters

         encoding  

A byte array that will hold the DER encoding of the RDN.

         offset  

The offset into encoding where the encoding begins.

         special  

The special circumstances of the DER encoding, if there are any, such as OPTIONAL.

Returns

The number of bytes placed into encoding.

Throws

NameException - If unable to encode the RDN.

addNameAVA

public void addNameAVA(AttributeValueAssertion ava)
Adds the attribute value assertion to this RDN object.

Parameters

         ava  

The AVA object to add to this RDN object.


equals

public boolean equals(Object obj)
Returns true if this object and obj contain the same RDN, returns false otherwise.

Overrides

equals in class Object

Parameters

         obj  

The instance of the RDN object.

Returns

A boolean indicating whether these objects are equal.


RSA BSAFE ® Cert-J 2.1.1 001-047007-211-001-000