iaik.asn1.structures
Class Attributes

java.lang.Object
  |
  +--iaik.asn1.structures.Attributes

public class Attributes
extends Object

An container class for X.509 Attributes. This class may be used as a container for adding, inserting, removing, encoding X.509 Attributes. When encoding the attributes included in the container, they may be BER encoded either as ASN.1 SET OF or as ASN.1 SEQUENCE OF Attributes.

Version:
File Revision 8

Field Summary
protected  Vector attributes_
          The Attribute repository (order may be of interest).
 
Constructor Summary
Attributes()
          Empty constructor.
Attributes(ASN1Object attributes)
          Creates an Attribute container from a SET OF or SEQUENCE OF attributes.
Attributes(Attribute[] attributes)
          Creates an Attribute container from the given list of attributes.
Attributes(byte[] encodedAttributes)
          Creates an Attribute container from a BER encoded SET OF or SEQUENCE OF attributes.
Attributes(InputStream is)
          Creates an Attribute container from a BER encoded SET OF or SEQUENCE OF 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.
 Attribute getAttribute(ObjectID type)
          Returns the first attribute with the given type.
 Enumeration getAttributes()
          Returns all attributes included in the container.
 Attribute[] getAttributes(ObjectID type)
          Returns all attributes with the given type.
 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
 Attribute[] toArray()
          Returns an array containing all the attributes included in this container.
 SEQUENCE toAsn1SEQUENCE()
          Returns the attributes included in this container as ASN.1 SEQUENCE.
 SET toAsn1SET()
          Returns the attributes included in this container as ASN.1 SET.
 SET toAsn1SET(boolean sorted)
          Returns the attributes included in this container as ASN.1 SET.
 String toString()
          Returns a string that lists all the Attributes hold in this container.
 void writeToAsn1SEQUENCE(OutputStream os)
          Builds an ASN.1 SEQUENCE of the attributes included in this container and writes it encoded to the given output stream.
 void writeToAsn1SET(OutputStream os)
          Builds an ASN.1 SET of the attributes included in this container and writes it encoded to the given output stream.
 void writeToAsn1SET(OutputStream os, boolean sorted)
          Builds an ASN.1 SET of the attributes included in this container and writes it encoded to the given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

attributes_

protected Vector attributes_
The Attribute repository (order may be of interest).
Constructor Detail

Attributes

public Attributes()
Empty constructor. Creates an empty Attributes container.

Attributes

public Attributes(Attribute[] attributes)
Creates an Attribute container from the given list of attributes.
Parameters:
attributes - the attributes to be added to the container

Attributes

public Attributes(ASN1Object attributes)
           throws CodingException
Creates an Attribute container from a SET OF or SEQUENCE OF attributes.
Parameters:
attributes - the ASN.1 SET OF or SEQUENCE OF attributes to be parsed
Throws:
CodingException - if an error occurs while parsing the attributes

Attributes

public Attributes(InputStream is)
           throws CodingException,
                  IOException
Creates an Attribute container from a BER encoded SET OF or SEQUENCE OF attributes. The encoded bytes are kept.
Parameters:
is - the inputstream supplying the encoded ASN.1 SET OF or SEQUENCE OF attributes to be parsed
Throws:
CodingException - if an error occurs while parsing the attributes

Attributes

public Attributes(byte[] encodedAttributes)
           throws CodingException
Creates an Attribute container from a BER encoded SET OF or SEQUENCE OF attributes. The encoded bytes are kept.
Parameters:
encodedAttributes - the byte array supplying the encoded ASN.1 SET OF or SEQUENCE OF attributes to be parsed
Throws:
CodingException - if an error occurs while parsing the attributes
Method Detail

addAttribute

public void addAttribute(Attribute attribute)
Adds the given attribute.
Parameters:
attribute - the attribute to be added.

addAttribute

public void addAttribute(Attribute attribute,
                         boolean replace)
Adds the given attribute.
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.
Parameters:
attributes - the attributes to be added.

insertAttributeAt

public void insertAttributeAt(Attribute attribute,
                              int index)
Inserts the given attribute.
Parameters:
attribute - the attribute to be inserted.
index - the position at which to insert the attribute

getAttributes

public Enumeration getAttributes()
Returns all attributes included in the container.
Returns:
an Enumeration containing all attributes included in the container; the enumeration may be empty

getAttribute

public Attribute getAttribute(ObjectID type)
Returns the first attribute with the given type.
Returns:
the first attribute with the given type, if present; null otherwise

getAttributes

public Attribute[] getAttributes(ObjectID type)
Returns all attributes with the given type.
Returns:
an array containing all the attribute with the given type; the array may be empty if no such attribute is present in the container

toArray

public Attribute[] toArray()
Returns an array containing all the attributes included in this container.
Returns:
an array containing all the attributes included in this container; the array may be empty if no attributes are present in the container

clearAll

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

removeAttribute

public boolean removeAttribute(Attribute attribute)
Removes the first representative of the given attribute.
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
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.
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
Parameters:
type - the type of the attributes to be removed
Returns:
an array conatining the attributes just removed; the array may be empty if no attribute with this type was present

toAsn1SET

public SET toAsn1SET()
              throws CodingException
Returns the attributes included in this container as ASN.1 SET.
Returns:
the attributes included in this container as ASN.1 SET.
Throws:
CodingException - if an error occurs while building the SET

toAsn1SET

public SET toAsn1SET(boolean sorted)
              throws CodingException
Returns the attributes included in this container as ASN.1 SET.
Parameters:
sorted - whether to sort the elements of the SET when encoding it
Returns:
the attributes included in this container as ASN.1 SET.
Throws:
CodingException - if an error occurs while building the SET

toAsn1SEQUENCE

public SEQUENCE toAsn1SEQUENCE()
                        throws CodingException
Returns the attributes included in this container as ASN.1 SEQUENCE.
Returns:
the attributes included in this container as ASN.1 SEQUENCE.
Throws:
CodingException - if an error occurs while building the SEQUENCE

writeToAsn1SET

public void writeToAsn1SET(OutputStream os)
                    throws IOException
Builds an ASN.1 SET of the attributes included in this container and writes it encoded to the given output stream. If this Attributes container has been created by parsing an ASN.1 SET the original encoding is written to the stream. Otherwise a new SET is created.
Parameters:
os - the output stream to which to write the encoded SET of attributes
Throws:
IOException - if an error occurs while building/encoding the SET or writing it to the stream

writeToAsn1SET

public void writeToAsn1SET(OutputStream os,
                           boolean sorted)
                    throws IOException
Builds an ASN.1 SET of the attributes included in this container and writes it encoded to the given output stream. If this Attributes container has been created by parsing an ASN.1 SET the original encoding is written to the stream. Otherwise a new SET is created.
Parameters:
os - the output stream to which to write the encoded SET of attributes
sorted - whether to sort the elements of the SET when encoding it
Throws:
IOException - if an error occurs while building/encoding the SET or writing it to the stream

writeToAsn1SEQUENCE

public void writeToAsn1SEQUENCE(OutputStream os)
                         throws IOException
Builds an ASN.1 SEQUENCE of the attributes included in this container and writes it encoded to the given output stream. If this Attributes container has been created by parsing an ASN.1 SEQUENCE the original encoding is written to the stream. Otherwise a new SEQUENCE is created.
Parameters:
os - the output stream to which to write the encoded SEQUENCE of attributes
Throws:
IOException - if an error occurs while building/encoding the SEQUENCE or writing it to the stream

toString

public String toString()
Returns a string that lists all the Attributes hold in this container.
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