com.ibm.security.pkcsutil
Class PKCSAttribute

com.ibm.security.pkcsutil.PKCSAttribute

public final class PKCSAttribute
implements Cloneable

Represent an Attribute as defined in X.501.

Attributes are additonal information which can be inserted in a PKCS #10 certificate request. For example a "Driving License Certificate" could have the driving license number as an attribute. They are also used to add information to the PrivateKeyInfo defined by PKCS #8.

Attributes are represented as a sequence of the attribute identifier (Object Identifier) and a set of DER encoded attribute values. ASN.1 definition of Attribute:

 Attribute :: SEQUENCE {
    type    AttributeType,
    values  SET OF AttributeValue
 }
 AttributeType  ::= OBJECT IDENTIFIER
 AttributeValue ::= ANY defined by type
 

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


Constructor Summary
PKCSAttribute(byte[] der)
          Create a PKCSAttribute object with a DER byte array.
PKCSAttribute(byte[] der, String provider)
          Create a PKCSAttribute object with a DER byte array.
PKCSAttribute(ObjectIdentifier id, Object value)
          Constructs an attribute from individual components of ObjectIdentifier and the value (any Java object).
PKCSAttribute(ObjectIdentifier id, Object value, String provider)
          Constructs an attribute from individual components of ObjectIdentifier and the value (any Java object).
PKCSAttribute(PKCS9DerObject attr)
          Constructs an attribute from PKCS #9 attribute.
PKCSAttribute(PKCS9DerObject attr, String provider)
          Constructs an attribute from PKCS #9 attribute.
PKCSAttribute(String filename, boolean base64)
          Create a PKCSAttribute with the filename of the DER-encoded or BASE64-encoded object.
PKCSAttribute(String filename, boolean base64, String provider)
          Create a PKCSAttribute with the filename of the DER-encoded or BASE64-encoded object.
PKCSAttribute(UnresolvedAttribute attr)
          Constructs an attribute from a non-standard attribute.
PKCSAttribute(UnresolvedAttribute attr, String provider)
          Constructs an attribute from a non-standard attribute.
 
Method Summary
 Object clone()
          Creates a clone of this PKCSAttribute object.
protected  void decode(com.ibm.security.pkcsutil.DerValue encoding)
          Initializes a PKCSAttribute object from a DerValue.
 void derEncode(OutputStream out)
          DER encode this object onto an output stream.
 void encode(OutputStream out)
          Encode the attributes in DER form to the stream.
 boolean equals(Object obj)
          Determines if this PKCSAttribute object is equivalent to the input object.
 ObjectIdentifier getAttributeId()
          Returns a reference to the ObjectIdentifier of the attribute.
 Object getAttributeValue()
          Returns a copy of the attribute value.
 PKCS9DerObject getPKCS9DerObject()
          Returns a PKCS9DerObject based on the PKCSAttribute value.
 String toString()
          Returns the attribute in user readable form.
 

Constructor Detail

PKCSAttribute

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

PKCSAttribute

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

PKCSAttribute

public PKCSAttribute(ObjectIdentifier id,
                     Object value)
              throws IOException
Constructs an attribute from individual components of ObjectIdentifier and the value (any Java object).
Parameters:
id - the ObjectIdentifier of the attribute.
value - an instance of a class that implements the attribute identified by the ObjectIdentifier. If the ObjectIdentifier is not defined in PKCS #9, the value must be a byte array that is a SET OF DER-encoding.

PKCSAttribute

public PKCSAttribute(ObjectIdentifier id,
                     Object value,
                     String provider)
              throws IOException
Constructs an attribute from individual components of ObjectIdentifier and the value (any Java object).
Parameters:
id - the ObjectIdentifier of the attribute.
value - an instance of a class that implements the attribute identified by the ObjectIdentifier. If the ObjectIdentifier is not defined in PKCS #9, the value must be a byte array that is a SET OF DER-encoding.
provider - the provider to be used.

PKCSAttribute

public PKCSAttribute(PKCS9DerObject attr)
Constructs an attribute from PKCS #9 attribute.
Parameters:
attr - the PKCSAttr to create from.

PKCSAttribute

public PKCSAttribute(PKCS9DerObject attr,
                     String provider)
Constructs an attribute from PKCS #9 attribute.
Parameters:
attr - the PKCSAttr to create from.
provider - the provider to be used.

PKCSAttribute

public PKCSAttribute(UnresolvedAttribute attr)
              throws IOException
Constructs an attribute from a non-standard attribute. Non-standard attributes are those not defined in PKCS #9.
Parameters:
attr - the non-standard to create from.

PKCSAttribute

public PKCSAttribute(UnresolvedAttribute attr,
                     String provider)
              throws IOException
Constructs an attribute from a non-standard attribute. Non-standard attributes are those not defined in PKCS #9.
Parameters:
attr - the non-standard to create from.
provider - the provider to be used.

PKCSAttribute

public PKCSAttribute(String filename,
                     boolean base64)
              throws IOException
Create a PKCSAttribute 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.

PKCSAttribute

public PKCSAttribute(String filename,
                     boolean base64,
                     String provider)
              throws IOException
Create a PKCSAttribute 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.

equals

public boolean equals(Object obj)
Determines if this PKCSAttribute object is equivalent to the input object.
Parameters:
other - the object to compare this one to.
Returns:
true, if the two objects are equivalent, false otherwise.

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.

derEncode

public void derEncode(OutputStream out)
               throws IOException
DER encode this object onto an output stream. Implements the DerEncoder interface.
Parameters:
out - the OutputStream on which to write the DER encoding.
Throws:
IOException - on encoding errors.

getAttributeId

public ObjectIdentifier getAttributeId()
Returns a reference to the ObjectIdentifier of the attribute. The object identifier is an immutable object.

getAttributeValue

public Object getAttributeValue()
                         throws IOException
Returns a copy of the attribute value.
Throws:
IOException - if the attribute value cannot be copied.

toString

public String toString()
Returns the attribute in user readable form.

getPKCS9DerObject

public PKCS9DerObject getPKCS9DerObject()
Returns a PKCS9DerObject based on the PKCSAttribute value.

decode

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