iaik.cms
Class SignedAttributes

java.lang.Object
  extended by iaik.asn1.structures.Attributes
      extended by iaik.cms.SignedAttributes

public class SignedAttributes
extends Attributes

Signed attributes set of a CMS SignerInfo.

Provides an alternative way for getting the signed attributes from a parsed SignerInfo object:

 SignerInfo signerInfo = ...;
 SignedAttributes signedAttributes = signerInfo.getSignedAttrs();
 


Field Summary
 
Fields inherited from class iaik.asn1.structures.Attributes
attributes_
 
Method Summary
 void addAttribute(Attribute attribute)
          Adds the given attribute.
 void addAttribute(Attribute attribute, boolean replace)
          Adds the given attribute.
 void addAttributes(Attribute[] attributes)
          Adds the given attributes.
 void clearAll()
          Clears all attributes included in the container.
 void clearEncoded()
          Clears the attributes encoding.
 byte[] getEncoded()
          Returns the DER encoded implicitly tagged signed attributes.
 void insertAttributeAt(Attribute attribute, int index)
          Inserts the given attribute.
 boolean removeAttribute(Attribute attribute)
          Removes the first representative of the given attribute.
 Attribute removeAttribute(ObjectID type)
          Removes the first attribute with the given type from the container
 boolean removeAttributes(Attribute attribute)
          Removes all representatives of the given attribute from the container.
 Attribute[] removeAttributes(ObjectID type)
          Removes all attributes with the given type from the container
 int size()
          Returns the number of attributes held by this Attributes object.
 
Methods inherited from class iaik.asn1.structures.Attributes
encodeAsAsn1SEQUENCE, encodeAsAsn1SET, encodeAsAsn1SET, getAttribute, getAttributes, getAttributes, toArray, toAsn1SEQUENCE, toAsn1SET, toAsn1SET, toString, writeToAsn1SEQUENCE, writeToAsn1SET, writeToAsn1SET
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

addAttribute

public void addAttribute(Attribute attribute)
Adds the given attribute.

Overrides:
addAttribute in class Attributes
Parameters:
attribute - the attribute to be added.

addAttribute

public void addAttribute(Attribute attribute,
                         boolean replace)
Adds the given attribute.

Overrides:
addAttribute in class Attributes
Parameters:
attribute - the attribute to be added.
replace - whether to replace any already existing attribute with the given type

addAttributes

public void addAttributes(Attribute[] attributes)
Adds the given attributes.

Overrides:
addAttributes in class Attributes
Parameters:
attributes - the attributes to be added.

insertAttributeAt

public void insertAttributeAt(Attribute attribute,
                              int index)
Inserts the given attribute.

Overrides:
insertAttributeAt in class Attributes
Parameters:
attribute - the attribute to be inserted.
index - the position at which to insert the attribute

removeAttribute

public boolean removeAttribute(Attribute attribute)
Removes the first representative of the given attribute.

Overrides:
removeAttribute in class Attributes
Parameters:
attribute - the attribute to be removed
Returns:
true if the attribute has been removed, false if no such attribute was present

removeAttribute

public Attribute removeAttribute(ObjectID type)
Removes the first attribute with the given type from the container

Overrides:
removeAttribute in class Attributes
Parameters:
type - the type of the attribute to be removed
Returns:
the attribute just removed, or null if no attribute with this type was present

removeAttributes

public boolean removeAttributes(Attribute attribute)
Removes all representatives of the given attribute from the container.

Overrides:
removeAttributes in class Attributes
Parameters:
attribute - the attribute to be removed
Returns:
true if the attributes have been removed, false if no such attribute was present

removeAttributes

public Attribute[] removeAttributes(ObjectID type)
Removes all attributes with the given type from the container

Overrides:
removeAttributes in class Attributes
Parameters:
type - the type of the attributes to be removed
Returns:
an array containing the attributes just removed; the array may be empty if no attribute with this type was present

size

public int size()
Returns the number of attributes held by this Attributes object.

Returns:
the number of attributes included

getEncoded

public byte[] getEncoded()
                  throws CodingException
Returns the DER encoded implicitly tagged signed attributes.

According to the CMS specification (RFC 5652) the SignerInfo signed attributes are encoded as SET of Attribute, implicitly tagged wrapped into a CON_SPEC with tag 0:

 SignerInfo ::= SEQUENCE {
   ... 
       
   signedAttrs         [0] IMPLICIT Attributes OPTIONAL,
   
   ... }

 SignedAttributes ::= SET SIZE (1..MAX) OF Attribute
 
Note that the attributes are not wrapped into a CON_SPEC when calling any of the writeToAsn1SET, writeToAsn1SEQUENCE methods.
If the encoding of the attribute has been kept during parsing the kept encoding is returned, otherwise the attributes are DER encoded (i.e. the attributes are sorted, wrapped into a CON_SPEC and encoded).

Returns:
the DER encoded signed attributes
Throws:
CodingException - if an Encoding error occurs

clearEncoded

public void clearEncoded()
Clears the attributes encoding.
This method maybe called to clear the parsed encoding so that any following call to method getEncoded() will build the internal ASN.1 structure anew. This may be required when any attributes have been added/removed/changed from outside.


clearAll

public void clearAll()
Clears all attributes included in the container.

Overrides:
clearAll in class Attributes

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

IAIK-CMS 6.0, (c) 2002 IAIK, (c) 2003, 2023 SIC