com.novell.security.japi.pki
Class NPKITcache

java.lang.Object
  |
  +--com.novell.security.japi.pki.NPKIToolbox
        |
        +--com.novell.security.japi.pki.NPKITcache

public class NPKITcache
extends NPKIToolbox

Creates a cache which can be used to store PKI elements for example certificates, wrapped private keys, etc. The cache is stored on the local file system. The cache files are stored relative to the current working directory, unless a different path is specified.


Field Summary
static int NPKIT_NORMAL_FORMAT
          Specifies that the element info should be returned in the normal or DER format.
static int NPKIT_PEM_ASCII_NAME
          Specifies the ASCII naming convention is to be used.
static int NPKIT_PEM_FORMAT
          Specifies that the element info should be returned in the PEM format.
static int NPKIT_PEM_NORMAL_NAME
          Specifies the default Unicode naming convention that is to be used.
static int NPKIT_PEM_OVERWRITE_FILE
          Specifies that existing cache files should be overwritten.
 
Constructor Summary
NPKITcache()
          Constructor.
 
Method Summary
 void addElement(int elementType, byte[] data)
          Adds a cache element of type elementType to the context.
 void addPKCS12Elements(java.lang.String password, byte[] pfx, java.lang.Integer numberOfElementsAdded)
          Adds all the elements in the PKCS#12 data to the context.
 void clearAllElements()
          Clears all elements from a cache context
 void createContext()
          Creates a new NPKIT cache context and initializes it with default values.
 int elementInfo(int index, byte[][] data)
          Retreives information about the specified cache element
 int elementInfo(int flags, int index, byte[][] data)
          Retreives information about the specified cache element
 void freeContext()
          Frees a previously allocated NPKIT cache context and all associated memory
 int getContextHandle()
           
 void initialize()
          Initializes NPKITcache.
 int read(int flags, java.lang.String name, java.lang.String path)
          Reads the specified cache file
 void write(int flags, java.lang.String name, java.lang.String path)
          Writes all the cache elements in the cache context to the specfied cache file
 
Methods inherited from class com.novell.security.japi.pki.NPKIToolbox
decodeCSR, destroy, finalize, getUTCString, loadLibrary, version
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NPKIT_PEM_NORMAL_NAME

public static final int NPKIT_PEM_NORMAL_NAME
Specifies the default Unicode naming convention that is to be used.

(NPKIT_PEM_NORMAL_NAME = 0)

See Also:
Constant Field Values

NPKIT_PEM_ASCII_NAME

public static final int NPKIT_PEM_ASCII_NAME
Specifies the ASCII naming convention is to be used.

(NPKIT_PEM_ASCII_NAME = 1)

See Also:
Constant Field Values

NPKIT_PEM_OVERWRITE_FILE

public static final int NPKIT_PEM_OVERWRITE_FILE
Specifies that existing cache files should be overwritten.

(NPKIT_PEM_OVERWRITE_FILE = 100)

See Also:
Constant Field Values

NPKIT_NORMAL_FORMAT

public static final int NPKIT_NORMAL_FORMAT
Specifies that the element info should be returned in the normal or DER format.

(NPKIT_NORMAL_FORMAT = 0)

See Also:
Constant Field Values

NPKIT_PEM_FORMAT

public static final int NPKIT_PEM_FORMAT
Specifies that the element info should be returned in the PEM format.

(NPKIT_PEM_FORMAT = 1)

See Also:
Constant Field Values
Constructor Detail

NPKITcache

public NPKITcache()
           throws NPKI_Exception
Constructor.

Throws:
NPKI_Exception - Throws a PKI error code if not successful.
Method Detail

initialize

public void initialize()
                throws NPKI_Exception
Initializes NPKITcache.

Overrides:
initialize in class NPKIToolbox
Throws:
NPKI_Exception - Throws a PKI error code if not successful.

getContextHandle

public int getContextHandle()

createContext

public void createContext()
                   throws NPKI_Exception
Creates a new NPKIT cache context and initializes it with default values.

Specified by:
createContext in class NPKIToolbox
Throws:
NPKI_Exception - Throws a PKI error code if not successful.
See Also:
freeContext

freeContext

public void freeContext()
Frees a previously allocated NPKIT cache context and all associated memory

Specified by:
freeContext in class NPKIToolbox
See Also:
createContext

clearAllElements

public void clearAllElements()
Clears all elements from a cache context

See Also:
createContext, addElement

addElement

public void addElement(int elementType,
                       byte[] data)
                throws NPKI_Exception
Adds a cache element of type elementType to the context.

Parameters:
elementType - Specifies the type of element to be added.
data - Specifies the data to be added.
Throws:
NPKI_Exception - Throws a PKI error code if not successful.
See Also:
createContext, write

addPKCS12Elements

public void addPKCS12Elements(java.lang.String password,
                              byte[] pfx,
                              java.lang.Integer numberOfElementsAdded)
                       throws NPKI_Exception
Adds all the elements in the PKCS#12 data to the context.

Parameters:
password - Specifioes the password used to decrypt the PKCS12 data.
pfx - Specifies the PFX (or PKCS#12) data.
numberOfElementsAdded - Returns the number of elements that were added to the cache.
Throws:
NPKI_Exception - Throws a NICI or PKI error code if not successful.
See Also:
createContext, addElement, write

elementInfo

public int elementInfo(int index,
                       byte[][] data)
                throws NPKI_Exception
Retreives information about the specified cache element

Parameters:
index - Specifies which cache element to get information from.
data - Returns the data from the specified cache element.
Returns:
the element type.
Throws:
NPKI_Exception - Throws a PKI error code if not successful.
See Also:
createContext, addElement, read

elementInfo

public int elementInfo(int flags,
                       int index,
                       byte[][] data)
                throws NPKI_Exception
Retreives information about the specified cache element

Parameters:
flags - Specifies which format the element data will be returned in. Use one of the following:
  • NPKIT_NORMAL_FORMAT - Specifies that the element info should be returned in the normal or DER format.
  • NPKIT_PEM_FORMAT - Specifies that the element info should be returned in PEM format.
index - Specifies which cache element to get information from.
data - Returns the data from the specified cache element.
Returns:
the element type.
Throws:
NPKI_Exception - Throws a PKI error code if not successful.
See Also:
createContext, addElement, read

write

public void write(int flags,
                  java.lang.String name,
                  java.lang.String path)
           throws NPKI_Exception
Writes all the cache elements in the cache context to the specfied cache file

Parameters:
flags - Specifies options for writing the cache file. The three possible flags and their behavior are listed below:
  • NPKIT_PEM_NORMAL_NAME - Using the flag NPKIT_PEM_NORMAL_NAME indicates that the paramater name is to be interperted as a unicode string.
  • NPKIT_PEM_ASCII_NAME - Using the flag NPKIT_PEM_ASCII_NAME indicates that the paramater name is to be interperted as an ASCII string.
  • NPKIT_PEM_OVERWRITE_FILE - Using the flag NPKIT_PEM_OVERWRITE_FILE specifies that existing cache files with the same name should be overwritten. This flag may be bitwise-OR'ed with either of the two other flags.
name - Specifies the name of the cache file.
path - (Optional) If used, specifies the file path to use when writing the cache file.
Throws:
NPKI_Exception - Throws a PKI or file system error code if not successful.
See Also:
createContext, clearAllElements, addElement

read

public int read(int flags,
                java.lang.String name,
                java.lang.String path)
         throws NPKI_Exception
Reads the specified cache file

Parameters:
flags - Specifies options for reading the cache file. The two valid flags and their behavior are listed below:
  • NPKIT_PEM_NORMAL_NAME - Using the flag NPKIT_PEM_NORMAL_NAME indicates that the paramater name is to be interperted as a unicode string.
  • NPKIT_PEM_ASCII_NAME - Using the flag NPKIT_PEM_ASCII_NAME indicates that the paramater name is to be interperted as an ASCII string.
name - Specifies the name of the cache file.
path - (Optional) If used, specifies the file path to use when reading the cache file.
Returns:
the number of elements in the cache file.
Throws:
NPKI_Exception - Throws a PKI or file system error code if not successful.
See Also:
createContext, clearAllElements, elementInfo