com.ibm.security.pkcsutil
Class PKCSAttributes

com.ibm.security.pkcsutil.PKCSAttributes

public final class PKCSAttributes
implements Cloneable

This class defines the ASN.1 attributes data type. The ASN.1 syntax is:

Attributes ::= SET OF Attribute

PKCSAttributes objects are immutable; they cannot be changed once created.


Constructor Summary
PKCSAttributes()
          Default constructor for the PKCSAttributes object.
PKCSAttributes(byte[] der)
          Create a PKCSAttributes object with a DER byte array.
PKCSAttributes(byte[] der, String provider)
          Create a PKCSAttributes object with a DER byte array.
PKCSAttributes(com.ibm.security.pkcsutil.DerInputStream in)
          Create the object, decoding the values from the passed DER stream.
PKCSAttributes(com.ibm.security.pkcsutil.DerInputStream in, String provider)
          Create the object, decoding the values from the passed DER stream.
PKCSAttributes(PKCSAttribute[] attrs)
          Create the object from the array of PKCSAttribute objects.
PKCSAttributes(PKCSAttribute[] attrs, String provider)
          Create the object from the array of PKCSAttribute objects.
PKCSAttributes(String provider)
           
PKCSAttributes(String filename, boolean base64)
          Create a PKCSAttributes with the filename of the DER-encoded or BASE64-encoded object.
PKCSAttributes(String filename, boolean base64, String provider)
          Create a PKCSAttributes with the filename of the DER-encoded or BASE64-encoded object.
 
Method Summary
 PKCSAttributes addAttribute(PKCSAttribute attr)
          Adds an attribute to this set of attributes and returns the combined set in a new object.
 PKCSAttributes addAttributes(PKCSAttributes attrs)
          Adds the attributes in the input PKCSAttributes to this set of attributes and returns the combined set in a new object.
 Object clone()
          Creates a clone of this PKCSAttribute object.
protected  void decode(com.ibm.security.pkcsutil.DerValue encoding)
          Initializes a PKCSAttributes object from a DerValue.
 PKCSAttributes deleteAttribute(ObjectIdentifier oid)
          Deletes the attribute value associated with the input object identifier.
 PKCSAttributes deleteAttribute(PKCSAttribute attr)
          Delete the attribute from this set of attributes.
 PKCSAttributes deleteAttribute(String name)
          Deletes the attribute value associated with the input object identifier string.
 void derEncode(OutputStream out)
          Encode the attributes in DER form to the stream.
 void encode(OutputStream out)
          Encode the attributes in DER form to the stream.
 boolean equals(Object other)
          Compares this PKCSAttributes for equality with the specified object.
 byte[] generateDerEncoding()
          Returns the byte array of the DER encoding.
 Object getAttribute(ObjectIdentifier oid)
          Returns a copy of the attribute associated with the input object identifier.
 Object getAttribute(String name)
          Returns a copy of the attribute associated with the input object identifier string.
 PKCSAttribute[] getAttributes()
          Return the attributes as an array of PKCSAttribute objects.
 int hashCode()
          Returns a hashcode value for this PKCSAttributes.
 int size()
          Return the number of PKCSAttribute objects that the PKCSAttributes object contains.
 String toString()
          Returns a string representation of this PKCSAttributes object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space).
 

Constructor Detail

PKCSAttributes

public PKCSAttributes()
Default constructor for the PKCSAttributes object.

PKCSAttributes

public PKCSAttributes(String provider)
Parameters:
provider - the provider to be used.

PKCSAttributes

public PKCSAttributes(com.ibm.security.pkcsutil.DerInputStream in)
               throws IOException
Create the object, decoding the values from the passed DER stream. The DER stream contains the SET OF Attribute.
Parameters:
in - the DerInputStream to read the attributes from.
Throws:
IOException - on decoding errors.

PKCSAttributes

public PKCSAttributes(com.ibm.security.pkcsutil.DerInputStream in,
                      String provider)
               throws IOException
Create the object, decoding the values from the passed DER stream. The DER stream contains the SET OF Attribute.
Parameters:
in - the DerInputStream to read the attributes from.
provider - the provider to be used.
Throws:
IOException - on decoding errors.

PKCSAttributes

public PKCSAttributes(byte[] der)
               throws IOException
Create a PKCSAttributes object with a DER byte array.
Parameters:
der - a DER byte array of a PKCSAttributes object.
Throws:
IOException - on decoding errors.

PKCSAttributes

public PKCSAttributes(byte[] der,
                      String provider)
               throws IOException
Create a PKCSAttributes object with a DER byte array.
Parameters:
der - a DER byte array of a PKCSAttributes object.
provider - the provider to be used.
Throws:
IOException - on decoding errors.

PKCSAttributes

public PKCSAttributes(PKCSAttribute[] attrs)
Create the object from the array of PKCSAttribute objects.
Parameters:
attrs - the array of PKCSAttribute objects.

PKCSAttributes

public PKCSAttributes(PKCSAttribute[] attrs,
                      String provider)
Create the object from the array of PKCSAttribute objects.
Parameters:
attrs - the array of PKCSAttribute objects.
provider - the provider to be used.

PKCSAttributes

public PKCSAttributes(String filename,
                      boolean base64)
               throws IOException
Create a PKCSAttributes with the filename of the DER-encoded or BASE64-encoded object.
Parameters:
filename - name of the DER-encoded or base64-encoded object
base64 - true if BASE64-encoded, false if DER-encoded
Throws:
IOException - on decoding errors.

PKCSAttributes

public PKCSAttributes(String filename,
                      boolean base64,
                      String provider)
               throws IOException
Create a PKCSAttributes with the filename of the DER-encoded or BASE64-encoded object.
Parameters:
filename - name of the DER-encoded or base64-encoded object
base64 - true if BASE64-encoded, false if DER-encoded
provider - the provider to be used
Throws:
IOException - on decoding errors.
Method Detail

clone

public Object clone()
Creates a clone of this PKCSAttribute object.
Returns:
clone of this PKCSAttribute object.

encode

public void encode(OutputStream out)
            throws IOException
Encode the attributes in DER form to the stream.
Parameters:
out - the OutputStream to marshal the contents to.
Throws:
IOException - on encoding errors.

generateDerEncoding

public byte[] generateDerEncoding()
                           throws IOException
Returns the byte array of the DER encoding.
Returns:
the byte array of the DER encoding

derEncode

public void derEncode(OutputStream out)
               throws IOException
Encode the attributes in DER form to the stream. Implements the DerEncoder interface.
Parameters:
out - the OutputStream to marshal the contents to.
Throws:
IOException - on encoding errors.

addAttribute

public PKCSAttributes addAttribute(PKCSAttribute attr)
Adds an attribute to this set of attributes and returns the combined set in a new object. If the attribute already exists, it will be replaced. The original PKCSAttributes object remains unchanged.
Parameters:
attr - the attribute to add.
Throws:
IllegalArgumentException - if the input attribute is null or consists of null elements.

addAttributes

public PKCSAttributes addAttributes(PKCSAttributes attrs)
Adds the attributes in the input PKCSAttributes to this set of attributes and returns the combined set in a new object. If an attribute already exists, it will be replaced. The original PKCSAttributes object remains unchanged.
Parameters:
attrs - the attributes to add.
Throws:
IllegalArgumentException - if the input attribute is null or consists of null elements.

getAttribute

public Object getAttribute(String name)
Returns a copy of the attribute associated with the input object identifier string.
Parameters:
name - Object Identifier string

getAttribute

public Object getAttribute(ObjectIdentifier oid)
Returns a copy of the attribute associated with the input object identifier.
Parameters:
oid - ObjectIdentifier

deleteAttribute

public PKCSAttributes deleteAttribute(String name)
Deletes the attribute value associated with the input object identifier string. This method does not modify the original PKCSAttributes object. It returns a new instance of PKCSAttributes.
Parameters:
name - Object Identifier string

deleteAttribute

public PKCSAttributes deleteAttribute(ObjectIdentifier oid)
Deletes the attribute value associated with the input object identifier. This method does not modify the original PKCSAttributes object. It returns a new instance of PKCSAttributes.
Parameters:
oid - ObjectIdentifier

deleteAttribute

public PKCSAttributes deleteAttribute(PKCSAttribute attr)
Delete the attribute from this set of attributes. This method does not modify the original PKCSAttributes object. It returns a new instance of PKCSAttributes.
Parameters:
attr - the attribute to delete

getAttributes

public PKCSAttribute[] getAttributes()
Return the attributes as an array of PKCSAttribute objects.

size

public int size()
Return the number of PKCSAttribute objects that the PKCSAttributes object contains.

equals

public boolean equals(Object other)
Compares this PKCSAttributes for equality with the specified object. If the other object is an instanceof PKCSAttributes, then all the entries are compared with the entries from this.
Parameters:
other - the object to test for equality with this PKCSAttributes.
Returns:
true iff all the entries match that of the Other, false otherwise.

hashCode

public int hashCode()
Returns a hashcode value for this PKCSAttributes.
Returns:
the hashcode value.

toString

public String toString()
Returns a string representation of this PKCSAttributes object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space).

Overrides the toString method of Object.

Returns:
a string representation of this PKCSAttributes.

decode

protected void decode(com.ibm.security.pkcsutil.DerValue encoding)
               throws IOException
Initializes a PKCSAttributes object from a DerValue. The DER encoding must be in the format specified by the ASN.1 notation of the contained attributes.
Parameters:
encoding - a DER-encoded PKCSAttributes object.
Throws:
IOException - on parsing error.