iaik.cms
Class CMSAttribute

java.lang.Object
  extended by iaik.asn1.structures.Attribute
      extended by iaik.cms.CMSAttribute
All Implemented Interfaces:
ASN1Type

public class CMSAttribute
extends Attribute

Extends class Attribute to keep the encoding when parsing an attribute from an InputStream.

This class does not have any public constructor. Instances of this class are only created from within the CMS library when parsing attributes.

To get the attribute encoding call method getEncoded, e.g.:

 ObjectID attributeType = ...;
 SignerInfo signerInfo = ...;
 CMSAttribute cmsAttribute = (CMSAttribute)signerInfo.getUnsignedAttribute(attributeType);
 byte[] encodedAttribute = cmsAttribute.getEncoded();
 
If some value of the attribute has been changed from outside it might be necessary to clear the kept attribute encoding to ensure that the (changed) attribute is encoded anew:
 cmsAttribute.clearEncoded();
 
Alternatively a new Attribute object may be created (and used) with the changed attribute value(s), e.g. (for a single-valued attribute):
 ObjectID attributeType = ...;
 SignerInfo signerInfo = ...;
 CMSAttribute cmsAttribute = (CMSAttribute)signerInfo.getUnsignedAttribute(attributeType);
 AttributeValue value = cmsAttribute.getAttributeValue();
 // change value and create new attribute
 Attribute changedAttribute = new Attribute(value);
 // remove old attribute
 signerInfo.removeUnSignedAttribute(attributeType);
 // add new (changed) attribute
 signerInfo.addUnSignedAttribute(changedAttribute);
 


Method Summary
 void addAttributeValue(AttributeValue attributeValue)
          Adds an AttributeValue to the set of attribute values.
 void clearEncoded()
          Clears the attribute encoding.
 void clearEncoded(boolean clearEncodedValues)
          Clears the attribute encoding.
 AttributeValue getAttributeValue()
          Returns the value of this (single valued) Attribute.
 AttributeValue[] getAttributeValues()
          Returns the values of this (maybe multi-valued) Attribute.
 byte[] getEncoded()
          Gets the encoded attribute.
 EncodedAttributeValue[] getEncodedAttributeValues()
          Returns the value(s) of this (maybe multi-valued) Attribute as array of EncodedAttributeValue objects.
 ASN1Object[] getValue()
          Returns the value of this Attribute.
 void setAttributeValue(AttributeValue attributeValue)
          Sets the AttributeValue to this single-valued attribute.
 ASN1Object toASN1Object(boolean sorted)
          Returns the Attribute as an ASN1Object.
 java.lang.String toString()
          Returns a string that represents the contents of this Attribute.
 
Methods inherited from class iaik.asn1.structures.Attribute
create, decode, equals, getType, hashCode, register, toASN1Object
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

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.

Overrides:
getAttributeValue in class Attribute
Returns:
the AttributeValue of this (single valued) attribute, or null if no attribute value has been set
Throws:
CodingException - if an error occurs when internally decoding the attribute value for parsing its structure

getAttributeValues

public AttributeValue[] getAttributeValues()
                                    throws CodingException
Returns the values of this (maybe 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.

Overrides:
getAttributeValues in class Attribute
Returns:
the AttributeValues of this (maybe multi-valued) attribute, the array maybe empty if no AttributeValue has been set
Throws:
CodingException - if an error occurs when internally decoding any attribute value for parsing its structure

getEncodedAttributeValues

public EncodedAttributeValue[] getEncodedAttributeValues()
                                                  throws CodingException
Returns the value(s) of this (maybe multi-valued) Attribute as array of EncodedAttributeValue objects.

The EncodedAttributeValue objects returned by this method maybe queried for their value or encoded representation.

When not needing the parsed encoded attribute value representation it is more convenient to call method getAttributeValues().

Returns:
the AttributeValues of this (maybe multi-valued) attribute as array of EncodedAttributeValue objects; the array maybe empty if no AttributeValue is included
Throws:
CodingException - if an error occurs when internally decoding any attribute value for parsing its structure

toASN1Object

public ASN1Object toASN1Object(boolean sorted)
Returns the Attribute as an ASN1Object.

Overrides:
toASN1Object in class Attribute
Parameters:
sorted - whether to sort the SET of AttributeValue according there encoding; maybe ignored if calling toASN1Object for an parsed Attribute; in this case the original encoding -- if kept -- is written (maybe cleared) to build the ASN.1 structure anew
Returns:
the Attribute as ASN1Object

addAttributeValue

public void addAttributeValue(AttributeValue attributeValue)
                       throws CodingException,
                              java.lang.IllegalArgumentException
Adds an AttributeValue to the set of attribute values.
If multiple attribute values of the attribute type are allowed, the given AttributeValue is added to the list of already included attribute values, otherwise it will replace any existing one.

Overrides:
addAttributeValue in class Attribute
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
java.lang.IllegalArgumentException - if the attributValue is of a type not matching to the type of this Attribute

setAttributeValue

public void setAttributeValue(AttributeValue attributeValue)
                       throws CodingException,
                              java.lang.IllegalArgumentException
Sets the AttributeValue to this single-valued attribute. Any already included attribute value is cleared.

Overrides:
setAttributeValue in class Attribute
Parameters:
attributeValue - the attribute value to be set for this attribute
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
java.lang.IllegalArgumentException - if the attributValue is of a type not matching to the type of this Attribute

getEncoded

public byte[] getEncoded()
Gets the encoded attribute.

Returns:
the encoded attribute

clearEncoded

public void clearEncoded()
Clears the attribute encoding.
This method maybe called to clear the parsed encoding so that any following call to toASN1Object() or getEncoded() will build the internal ASN.1 structure anew. This may be required when any of the values of the parsed attribute has be changed from outside.


clearEncoded

public void clearEncoded(boolean clearEncodedValues)
Clears the attribute encoding.
This method maybe called to clear the parsed encoding so that any following call to toASN1Object() or getEncoded() will build the internal ASN.1 structure anew. This may be required when any of the values of the parsed attribute has be changed from outside.

Parameters:
clearEncodedValues - whether to also clear the encodings of the attribute values of this attribute (true) or to only clear the attribute encoding but not the encoding of the attribute values (false)

getValue

public ASN1Object[] getValue()
Returns the value of this Attribute.

Overrides:
getValue in class Attribute
Returns:
the value of this Attribute, as array of ASN1Objects (may be empty if no values have been set so far)

toString

public java.lang.String toString()
Returns a string that represents the contents of this Attribute.

Overrides:
toString in class Attribute
Returns:
the string representation

This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note).

IAIK-CMS 5.1, (c) 2002 IAIK, (c) 2003 - 2010 SIC