com.ibm.security.pkcs12
Class SafeContents

java.lang.Object
  |
  +--com.ibm.security.pkcsutil.PKCSDerObject
        |
        +--com.ibm.security.pkcs12.SafeContents

public final class SafeContents
extends PKCSDerObject
implements Cloneable

Implements the SafeContents data type as defined in PKCS #12:

SafeContents ::= SEQUENCE OF SafeBag

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

See Also:
SafeBag

Fields inherited from class com.ibm.security.pkcsutil.PKCSDerObject
provider
 
Constructor Summary
SafeContents(byte[] der)
          Create a SafeContents object with a DER byte array.
SafeContents(byte[] der, String provider)
          Create a SafeContents object with a DER byte array.
SafeContents(SafeBag[] bags)
          Create a SafeContents object with the input SafeBags.
SafeContents(SafeBag[] bags, String provider)
          Create a SafeContents object with the input SafeBags.
SafeContents(String filename, boolean base64)
          Create a SafeContents with the filename of the DER-encoded or BASE64-encoded object.
SafeContents(String filename, boolean base64, String provider)
          Create a SafeContents with the filename of the DER-encoded or BASE64-encoded object.
 
Method Summary
 SafeContents addBags(SafeBag[] inBags)
          Add one or more SafeBags to this object and return the result in a new SafeContents * object.
 Object clone()
          Creates a clone of this SafeContents object.
protected  void decode(com.ibm.security.pkcs12.DerValue encoding)
          Initialize a SafeContents object from an input stream.
 void encode(OutputStream out)
          Encodes this object to a DER OutputStream.
 boolean equals(Object obj)
          Determines if this SafeContents object is equivalent to the input object.
 SafeBag[] getSafeBags()
          Returns a copy of the SafeBags present in this SafeContents object.
 ContentInfo protect(int mode)
          Protect the data privacy of this SafeContents object according to the input mode.
 String toString()
          Returns a string representation of this SafeContents object.
 
Methods inherited from class com.ibm.security.pkcsutil.PKCSDerObject
decode, decode, encode, getObjectIdentifier, hashCode, read, readBASE64, write, write, writeBASE64
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SafeContents

public SafeContents(byte[] der)
             throws IOException
Create a SafeContents object with a DER byte array.

SafeContents

public SafeContents(byte[] der,
                    String provider)
             throws IOException
Create a SafeContents object with a DER byte array.

SafeContents

public SafeContents(SafeBag[] bags)
             throws IOException
Create a SafeContents object with the input SafeBags.

SafeContents

public SafeContents(SafeBag[] bags,
                    String provider)
             throws IOException
Create a SafeContents object with the input SafeBags.

SafeContents

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

SafeContents

public SafeContents(String filename,
                    boolean base64,
                    String provider)
             throws IOException
Create a SafeContents 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 - a provider to be used
Throws:
IOException - on decoding errors.
Method Detail

encode

public void encode(OutputStream out)
            throws IOException
Encodes this object to a DER OutputStream.
Overrides:
encode in class PKCSDerObject
Parameters:
out - the DER OutputStream to write the encoded data to.
Throws:
IOException - on encoding errors.

addBags

public SafeContents addBags(SafeBag[] inBags)
Add one or more SafeBags to this object and return the result in a new SafeContents * object. The original SafeContents object remains unchanged.
Parameters:
bag - the SafeBags to add.

getSafeBags

public SafeBag[] getSafeBags()
Returns a copy of the SafeBags present in this SafeContents object.
Returns:
a copy of this object's SafeBags.

protect

public ContentInfo protect(int mode)
                    throws IOException,
                           PKCSException
Protect the data privacy of this SafeContents object according to the input mode. Valid input values are PKCS12.NO_ENCRYPT (no data privacy, the returned ContentInfo has Data content type) or PKCS12.PASSWD_ENCRYPT (password-based encyption, the returned ContentInfo has EncryptedData content type). Public-key encryption is not yet supported.
Parameters:
mode - the privacy mode to use. Valid values are PKCS12.NO-ENCRYPT for no data privacy or PKCS12.PASSWD_ENCRYPT for password-based encryption.
Returns:
the protected data enclosed in a ContentInfo object.
Throws:
IOException - if the object SafeBag data cannot be encoded.
IllegalArgumentException - if the input mode is not supported.
PKCSException - if the return ContentInfo cannot be constructed.

clone

public Object clone()
Creates a clone of this SafeContents object.
Overrides:
clone in class Object
Returns:
clone of this SafeContents object.

equals

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

toString

public String toString()
Returns a string representation of this SafeContents object.
Overrides:
toString in class PKCSDerObject
Returns:
a string representation of this object.

decode

protected void decode(com.ibm.security.pkcs12.DerValue encoding)
               throws IOException
Initialize a SafeContents object from an input stream. The data on that input stream must be a DER-encoded SafeContents object.
Parameters:
encoding - an input stream with a DER-encoded SafeContents object.
Throws:
IOException - on parsing errors.