|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--iaik.asn1.structures.Attribute
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.
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 |
public Attribute()
public Attribute(ObjectID type,
ASN1Object[] value)
type - the type of the attribute as ObjectIDvalue - the value of the attribute as array of ASN1Objects
public Attribute(ObjectID type,
ASN1Object[] value,
boolean sorted)
type - the type of the attribute as ObjectIDvalue - the value of the attribute as array of ASN1Objectssorted - whether to sort the SET of AttributeValue according there
encoding
public Attribute(AttributeValue attributeValue)
throws CodingException
The attribute type is derived from the supplied AttributeValue.
type - the type of the attribute as ObjectIDvalue - the value of the attribute as array of ASN1ObjectsCodingException - since attribute values internally are maintained as ASN1Object
a CodingException might be thrown when getting the ASN.1
representation of the given AttributeValue
public Attribute(AttributeValue attributeValue,
boolean sorted)
throws CodingException
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.
attributeValue - the value of the attributesorted - whether to sort the SET of AttributeValue according there
encodingCodingException - since attribute values internally are maintained as ASN1Object
a CodingException might be thrown when getting the ASN.1
representation of the given AttributeValue
public Attribute(ASN1Object obj)
throws CodingException
toASN1Object()
method.obj - the Attribute as ASN1ObjectCodingException - if this ASN1Object could not be parsed| Method Detail |
public static AttributeValue create(ObjectID attributeType)
throws InstantiationException
This method belongs to the static part of this class.
attributeType - the OID identifying the attribute type the AttributeValue belongs toInstantiationException - if the internal factory
couldn't create an instance of requested type
public static void register(ObjectID attributeType,
Class cl)
This method belongs to the static part of this class.
attributeType - the OID identifying the attribute type the AttributeValue implementing class belongs toclass - the class which implements the attribute value in mind
public void addAttributeValue(AttributeValue attributeValue)
throws CodingException,
IllegalArgumentException
attributeValue - the attribute value to be addedCodingException - since attribute values internally are maintained as ASN1Object
a CodingException might be thrown when getting the ASN.1
representation of the given AttributeValueIllegalArgumentException - if the attributValue is of a type not matching to the type
of this Attribute
public void decode(ASN1Object obj)
throws CodingException
toASN1Object()
method.decode in interface ASN1Typeobj - the ASN.1 type as ASN1ObjectCodingException - if the ASN1Object could not be parsedpublic ASN1Object toASN1Object()
toASN1Object in interface ASN1Typepublic ASN1Object toASN1Object(boolean sorted)
sorted - whether to sort the SET of AttributeValue according there
encoding (overrides the value that already may have been
set via constructorpublic ObjectID getType()
public ASN1Object[] getValue()
public AttributeValue getAttributeValue()
throws CodingException
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.
public AttributeValue[] getAttributeValues()
throws CodingException
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.
public boolean equals(Object obj)
equals in class Objectobj - the other Attributetrue, if the two Attributes are equal,
false otherwisepublic int hashCode()
hashCode in class Objectpublic String toString()
toString in class Object
|
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). | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK