iaik.asn1.structures
Class Attribute

java.lang.Object
  |
  +--iaik.asn1.structures.Attribute
All Implemented Interfaces:
ASN1Type

public class Attribute
extends Object
implements ASN1Type

This class implements the ASN.1 type Attribute. An Attribute object consists of an attribute type (specified by an object identifier) and one or more attribute values:

 Attribute ::= SEQUENCE {
  type    AttributeType,
  values  SET OF AttributeValue
    -- at least one value is required --
 }

 AttributeType           ::=   OBJECT IDENTIFIER
 AttributeValue          ::=   ANY DEFINED BY type
 

When creating a new Attribute object, the attribute type has to be specified as ObjectID, and the attribute value(s) have to be supplied as array of ASN1Objects, e.g.:

 Date signingDate = ...;
 ChoiceOfTime choiceOfTime = new ChoiceOfTime(date);
 ASN1Object[] asn1Objects = new ASN1Object[] { choiceOfTime.toASN1Object() };
 Attribute attribute = new Attribute(ObjectID.signingTime, asn1Objects);
 
The example above creates a PKCS#9 SigningTime attribute to be used for specifying the time a signer has signed a PKCS#7 SignedData message.

Alternatively an Attribute may be created from an AttributeValue object. AttributeValue is an abstract class allowing to implement and register particular attribute values. If an registered implementation of some particular AttributeValue exists an Attribute may be created immediately from a corresponding implementation object. In this way, if an implementation of the SigningTime attribute has been registered, the example from above alternatively may look like:

 Date signingDate = ...;
 SigningTime signingTime = new SigningTime(date);
 Attribute attribute = new Attribute(signingTime);
 
AttributeValue implementations also make it more convenient to query an existing attribute for its value(s):
 SigningTime signingTime = (SigningTime)attribute.getAttributeValue();
 Date signingDate = signingTime.getDate();
 
respectively (if more than one value are included -- will not occur for SigningTime):
 AttributeValue[] signingTimes = attribute.getAttributeValues();
 for (int i = 0; i < signingTimes.length; i++) {
   SigningTime signingTimes = (SigningTime)signingTimes[i];
   ...
 }
 
to be compared against method getValue returning the values as array of ASN1Objects:
 ASN1Object signingTimes = attribute.getValue();
 ChoiceOfTime cot = new ChoiceOfTime(signingTimes.getValue()[0]);
 Date signingDate = cot.getDate();
 
If no attribute value implementation is registered for a particular attribute type method getAttributeValue will return an UnknownAttributeValue.

Version:
File Revision 26
See Also:
AttributeValue, UnknownAttributeValue

Constructor Summary
Attribute()
          Creates an empty Attribute.
Attribute(ASN1Object obj)
          Creates an Attribute from an ASN1Object.
Attribute(AttributeValue attributeValue)
          Creates an Attribute from the given AttributeValue.
Attribute(AttributeValue attributeValue, boolean sorted)
          Creates an Attribute from the given AttributeValue.
Attribute(ObjectID type, ASN1Object[] value)
          Creates an Attribute from attribute type (ObjectID) and attribute values.
Attribute(ObjectID type, ASN1Object[] value, boolean sorted)
          Creates an Attribute from attribute type (ObjectID) and attribute values.
 
Method Summary
 void addAttributeValue(AttributeValue attributeValue)
          Adds an AttributeValue to the set of attribute values.
static AttributeValue create(ObjectID attributeType)
          Returns the implementation of the specified AttributeValue defined through an ASN.1 ObjectID (the attribute type).
 void decode(ASN1Object obj)
          Decodes an Attribute from the given ASN1Object.
 boolean equals(Object obj)
          Compares two Attributes.
 AttributeValue getAttributeValue()
          Returns the value of this (single valued) Attribute.
 AttributeValue[] getAttributeValues()
          Returns the values of this (multi valued) Attribute.
 ObjectID getType()
          Returns the type of this Attribute.
 ASN1Object[] getValue()
          Returns the value of this Attribute.
 int hashCode()
          Returns a hash code for this object.
static void register(ObjectID attributeType, Class cl)
          Registers a class for implementing a particular attribute value.
 ASN1Object toASN1Object()
          Returns the Attribute as an ASN1Object.
 ASN1Object toASN1Object(boolean sorted)
          Returns the Attribute as an ASN1Object.
 String toString()
          Returns a string that represents the contents of this Attribute.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Attribute

public Attribute()
Creates an empty Attribute.

Attribute

public Attribute(ObjectID type,
                 ASN1Object[] value)
Creates an Attribute from attribute type (ObjectID) and attribute values.
Parameters:
type - the type of the attribute as ObjectID
value - the value of the attribute as array of ASN1Objects

Attribute

public Attribute(ObjectID type,
                 ASN1Object[] value,
                 boolean sorted)
Creates an Attribute from attribute type (ObjectID) and attribute values.
Parameters:
type - the type of the attribute as ObjectID
value - the value of the attribute as array of ASN1Objects
sorted - whether to sort the SET of AttributeValue according there encoding

Attribute

public Attribute(AttributeValue attributeValue)
          throws CodingException
Creates an Attribute from the given AttributeValue.

The attribute type is derived from the supplied AttributeValue.

Parameters:
type - the type of the attribute as ObjectID
value - the value of the attribute as array of ASN1Objects
Throws:
CodingException - since attribute values internally are maintained as ASN1Object a CodingException might be thrown when getting the ASN.1 representation of the given AttributeValue

Attribute

public Attribute(AttributeValue attributeValue,
                 boolean sorted)
          throws CodingException
Creates an Attribute from the given AttributeValue.

The attribute type is derived from the supplied AttributeValue. This constructor may be used for creating a Attribute from an AttributeValue for which a class implemenation exists. Any further attribute value may be added to the set of attribute values by calling method addAttributeValue.

Parameters:
attributeValue - the value of the attribute
sorted - whether to sort the SET of AttributeValue according there encoding
Throws:
CodingException - since attribute values internally are maintained as ASN1Object a CodingException might be thrown when getting the ASN.1 representation of the given AttributeValue

Attribute

public Attribute(ASN1Object obj)
          throws CodingException
Creates an Attribute from an ASN1Object. The supplied ASN1Object represents an already existing Attribute object that may have been created by means of the toASN1Object() method.
Parameters:
obj - the Attribute as ASN1Object
Throws:
CodingException - if this ASN1Object could not be parsed
Method Detail

create

public static AttributeValue create(ObjectID attributeType)
                             throws InstantiationException
Returns the implementation of the specified AttributeValue defined through an ASN.1 ObjectID (the attribute type).

This method belongs to the static part of this class.

Parameters:
attributeType - the OID identifying the attribute type the AttributeValue belongs to
Returns:
the implementation of the attribute value identified by the given attribute type
Throws:
InstantiationException - if the internal factory couldn't create an instance of requested type

register

public static void register(ObjectID attributeType,
                            Class cl)
Registers a class for implementing a particular attribute value.

This method belongs to the static part of this class.

Parameters:
attributeType - the OID identifying the attribute type the AttributeValue implementing class belongs to
class - the class which implements the attribute value in mind

addAttributeValue

public void addAttributeValue(AttributeValue attributeValue)
                       throws CodingException,
                              IllegalArgumentException
Adds an AttributeValue to the set of attribute values.
Parameters:
attributeValue - the attribute value to be added
Throws:
CodingException - since attribute values internally are maintained as ASN1Object a CodingException might be thrown when getting the ASN.1 representation of the given AttributeValue
IllegalArgumentException - if the attributValue is of a type not matching to the type of this Attribute

decode

public void decode(ASN1Object obj)
            throws CodingException
Decodes an Attribute from the given ASN1Object. The supplied ASN1Object represents an already existing Attribute object that may have been created by means of the toASN1Object() method.
Specified by:
decode in interface ASN1Type
Parameters:
obj - the ASN.1 type as ASN1Object
Throws:
CodingException - if the ASN1Object could not be parsed

toASN1Object

public ASN1Object toASN1Object()
Returns the Attribute as an ASN1Object.
Specified by:
toASN1Object in interface ASN1Type
Returns:
the Attribute as ASN1Object

toASN1Object

public ASN1Object toASN1Object(boolean sorted)
Returns the Attribute as an ASN1Object.
Parameters:
sorted - whether to sort the SET of AttributeValue according there encoding (overrides the value that already may have been set via constructor
Returns:
the Attribute as ASN1Object

getType

public ObjectID getType()
Returns the type of this Attribute.
Returns:
the type of this Attribute, as ObjectID

getValue

public ASN1Object[] getValue()
Returns the value of this Attribute.
Returns:
the value of this Attribute, as array of ASN1Objects

getAttributeValue

public AttributeValue getAttributeValue()
                                 throws CodingException
Returns the value of this (single valued) Attribute.

This method preferably may be called for getting the value of an Attribute having only one single value. For getting all the values of an multi-valued Attribute call method getAttributeValues or method getValue().

This method looks if there exists an registered implementation of the attribute value belonging to the attribute type this Attribute object represents. If an AttributeValue implementation exists, this method returns the attribute value as corresponding AttributeValue descendant. If no implementation exists, this method returns an UnknownAttributeValue object to may be parsed for its ASN.1 representation.

Returns:
the AttributeValue of this (single valued) attribute

getAttributeValues

public AttributeValue[] getAttributeValues()
                                    throws CodingException
Returns the values of this (multi valued) Attribute.

This method preferably may be called for getting the values of an Attribute having more than only one single value.

For each included attribute value this method looks if there exists an registered implementation of the attribute value belonging to the attribute type this Attribute object represents. If an AttributeValue implementation exists, this method returns the attribute values as corresponding AttributeValue descendants. If no implementation exists, this method returns an array of UnknownAttributeValue objects to may be parsed for their ASN.1 representation.

Returns:
the AttributeValues of this (multi valued) attribute

equals

public boolean equals(Object obj)
Compares two Attributes.
Overrides:
equals in class Object
Parameters:
obj - the other Attribute
Returns:
true, if the two Attributes are equal, false otherwise

hashCode

public int hashCode()
Returns a hash code for this object.
Overrides:
hashCode in class Object
Returns:
the hash code

toString

public String toString()
Returns a string that represents the contents of this Attribute.
Overrides:
toString in class Object
Returns:
the string representation

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