com.rsa.certj.cert

Class X501Attributes

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

public class X501Attributes
extends Object
implements Cloneable, Serializable

This class builds and holds X.501 attributes. It holds the collection of attributes. The X501Attribute class stores, encodes, and decodes the data.

The ASN.1 definition is as follows:

 Attributes ::= SET OF Attribute
 Attribute ::= SEQUENCE {
   attrID      OBJECT IDENTIFIER
   value       SET OF { specificValue } }

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

See Also

Serialized Form

Constructor Summary

X501Attributes()

Constructs an empty X501Attributes object.

X501Attributes(byte[] attributesBER, int offset, int special)

Constructs an X501Attributes object and initializes it with the collection of attributes represented by attributesBER.

 

Method Summary

 int

addAttribute(X501Attribute attribute)

Adds a new X.501-defined attribute.

 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 X501Attributes object, returns false otherwise.

 X501Attribute

getAttributeByIndex(int index)

Gets the attribute at the specified index in the list.

 X501Attribute

getAttributeByOID(byte[] oid)

Gets the attribute that is of the given oid.

 X501Attribute

getAttributeByType(int attributeType)

Gets the attribute of the given type, attributeType.

 int

getAttributeCount()

Gets the number of attributes in this object.

 int

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

Places the DER encoding of the X.501 attributes into encoding, beginning at offset, and returns the number of bytes placed into the encoding array.

 int

getDERLen(int special)

Returns the number of bytes of the DER encoding of these X.501 attributes.

static int

getNextBEROffset(byte[] attributesBER, int offset)

Finds the index of the next element in the encoded data, given attributesBER, the BER encoding of X.501 attributes beginning at offset.

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

Constructor Detail

X501Attributes

public X501Attributes()
Constructs an empty X501Attributes object.

X501Attributes

public X501Attributes(byte[] attributesBER,
                      int offset,
                      int special)
               throws AttributeException
Constructs an X501Attributes object and initializes it with the collection of attributes represented by attributesBER.

The ASN.1 definition (previously defined in this class) means the tag will be 0x31. However, an X.501 attributes object can be part of a certificate request (or some other construct), and it might have a different tag, caused by IMPLICIT or EXPLICIT. For example, PKCS #10 defines CertRequestInfo with Attributes, but the Attributes portion itself is defined as follows:

      attributes   [0] IMPLICIT Attributes   

In this case, the tag will change from 0x31 to 0xa0. To indicate that the DER encoding of the Attributes object should follow any special circumstances, use the special argument.

For instance, to indicate the following:

      attributes   [0] IMPLICIT Attributes   
Pass in the following:

      special = (ASN1.CONTEXT_IMPLICIT | 0);   

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

         attributesBER  

A byte array that contains the BER encoding of the X.501 attributes.

         offset  

The offset into attributesBER where the encoding begins.

         special  

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

Throws

AttributeException - If the BER encoding is invalid.
Method Detail

getNextBEROffset

public static int getNextBEROffset(byte[] attributesBER,
                                   int offset)
                            throws AttributeException
Finds the index of the next element in the encoded data, given attributesBER, the BER encoding of X.501 attributes beginning at offset. In other words, gets the next offset after the attributes.

For example, if the offset is 120 and the attributes' BER encoding is 1819 bytes, this method returns 1939, the index immediately following the attributes. That is, attributesBER[120] is the first byte in the encoding of the attributes, attributesBER[1938] is the last byte in the encoding of the attributes, and the next element begins at index 1939.

Parameters

         attributesBER  

The BER encoding of X.501 attributes.

         offset  

The offset into attributesBER, where the encoding begins.

Returns

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

Throws

AttributeException - If the method cannot read the BER encoding.

getDERLen

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

The ASN.1 definition (previously defined in this class) means that the tag will be 0x31. However, an X.501 attributes object can be part of a certificate request (or some other construct), and it may have a different tag, caused by IMPLICIT or EXPLICIT. For example, PKCS #10 defines CertRequestInfo with Attributes, but the Attributes portion itself is defined as follows:

 
      attributes   [0] IMPLICIT Attributes   
To indicate that the encoding of Attributes should follow any special circumstances, use the special argument. For example, to indicate the following:

      attributes   [0] IMPLICIT Attributes   
Pass in the following:

      special = (ASN1.CONTEXT_IMPLICIT | 0);   
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

         special  

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

Returns

The number of bytes of the DER encoding of these X.501 attributes.

getDEREncoding

public int getDEREncoding(byte[] encoding,
                          int offset,
                          int special)
                   throws AttributeException
Places the DER encoding of the X.501 attributes into encoding, beginning at offset, and returns the number of bytes placed into the encoding array. If there are no attributes, this method places nothing into the array and returns zero.

The ASN.1 definition (previously defined in this class) means that the tag will be 0x31. However, an X.501 attributes object can be part of a certificate request (or some other construct), and it may have a different tag, caused by IMPLICIT or EXPLICIT. For example, PKCS #10 defines CertRequestInfo with Attributes, but the Attributes portion itself is defined as follows:

      attributes   [0] IMPLICIT Attributes   
To indicate that the encoding of Attributes should follow any special circumstances, use the special argument. Set special to any special circumstances of the BER encoding; for example, to indicate the following:

      attributes   [0] IMPLICIT Attributes   
Pass in the following:

      special = (ASN1.CONTEXT_IMPLICIT | 0);   
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  

The byte array into which the result will be placed.

         offset  

The offset into encoding where writing begine.

         special  

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

Returns

A byte array that contains the DER encoding of the X.501 attributes.

Throws

AttributeException - If the DER cannot be encoded.

addAttribute

public int addAttribute(X501Attribute attribute)
Adds a new X.501-defined attribute. If the object already contains an attribute of the type given in the argument attribute, then this method deletes the previous attribute and adds the new one. If the attribute passed in is null, then this method returns -1.

Parameters

         attribute  

An object that contains the attribute type and value or values. See the X501Attribute class and its subclasses for information about building attributes.

Returns

The index into the list of this attribute.

getAttributeCount

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

Returns

An int that contains the number of attributes in this object.

getAttributeByIndex

public X501Attribute getAttributeByIndex(int index)
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

         index  

The index into the list of the attribute to be retrieved.

Returns

A new X501Attribute object that contains the data.

getAttributeByType

public X501Attribute getAttributeByType(int attributeType)
Gets the attribute of the given type, attributeType. The possible values of attributeType are given in the X501Attribute class. If this object does not contain an attribute of the given type, then this method returns null.

Parameters

         attributeType  

The flag indicating which attribute type to get. See the X501Attribute class for a list of possible values.

Returns

A new X501Attribute object that contains the data.

getAttributeByOID

public X501Attribute getAttributeByOID(byte[] oid)
Gets the attribute that is of the given oid. If this object does not contain an attribute of the given oid, then this method returns a null.

Parameters

         oid  

The byte array that contains the OID to be compared.

Returns

A new X501Attribute object that contains the data.

clone

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

Returns

A new X501Attributes object, a copy of this object.

Throws

CloneNotSupportedException - If the cloning operation is not successful.

equals

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

Overrides

equals in class Object

Parameters

         obj  

The instance of an X501Attributes object.

Returns

A boolean indicating whether these objects are equal.


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