FileDocCategorySizeDatePackage
PublicKeyStoreBuilderBase.javaAPI DocJ2ME MIDP 2.03803Thu Nov 07 12:02:38 GMT 2002com.sun.midp.mekeytool

PublicKeyStoreBuilderBase

public class PublicKeyStoreBuilderBase extends com.sun.midp.publickeystore.PublicKeyStore
A read-write serializable {@link PublicKeyStore}. This class is the base for {@link PublicKeyStoreBuilder}, and does not have any methods that depend on any Microediton specific classes so it can be used alone in a tool written with Standard Edition Java.

Fields Summary
private Vector
keyList
Vecor of keys maintained as a list.
Constructors Summary
public PublicKeyStoreBuilderBase()
Constructs an empty read-write keystore.


              
      
        initPublicKeyStore(keyList);
    
public PublicKeyStoreBuilderBase(InputStream in)
Constructs a read-write keystore from a serialized keystore created by this class.

param
in stream to read a keystore serialized by {@link #serialize(OutputStream)} from
exception
IOException if the key storage was corrupted

        initPublicKeyStore(in, keyList);
    
Methods Summary
public synchronized voidaddKey(com.sun.midp.publickeystore.PublicKeyInfo keyInfo)
Adds a public key.

param
keyInfo the key to add

        keyList.addElement(keyInfo);
    
public voiddeleteKey(int number)
Deletes a public key from this keystore by number.

param
number number of the key with 0 being the first.
exception
ArrayIndexOutOfBoundsException if an invalid number was given.

        keyList.removeElementAt(number);
    
private voidputKeyInStorage(OutputStorage storage, com.sun.midp.publickeystore.PublicKeyInfo key)
Serializes every field with a tag.

param
storage what to put the key in
param
key key information object

        storage.writeValue(PublicKeyInfo.OWNER_TAG, key.getOwner());
        storage.writeValue(PublicKeyInfo.NOT_BEFORE_TAG, key.getNotBefore());
        storage.writeValue(PublicKeyInfo.NOT_AFTER_TAG, key.getNotAfter());
        storage.writeValue(PublicKeyInfo.MODULUS_TAG, key.getModulus());
        storage.writeValue(PublicKeyInfo.EXPONENT_TAG, key.getExponent());
        storage.writeValue(PublicKeyInfo.DOMAIN_TAG, key.getDomain());
    
public voidserialize(java.io.OutputStream out)
Serializes the keystore to the given stream.

param
out stream to serialize the keystore to
exception
IOException is thrown, if an I/O error occurs

        OutputStorage storage = new OutputStorage(out);
        Enumeration e;
        PublicKeyInfo keyInfo;
  
        e = keyList.elements();
        while (e.hasMoreElements()) {
            keyInfo = (PublicKeyInfo)e.nextElement();
            putKeyInStorage(storage, keyInfo);
        }
    
public synchronized voidupdateKey(int number, com.sun.midp.publickeystore.PublicKeyInfo newKeyInfo)
Updates all of an key's information except for the security domain. information in the store.

param
number key number of key 0 being the first
param
newKeyInfo new key information
exception
ArrayIndexOutOfBoundsException if an invalid number was given.

        PublicKeyInfo oldKeyInfo;

        oldKeyInfo = getKey(number);

        newKeyInfo.setDomain(oldKeyInfo.getDomain());

        keyList.setElementAt(newKeyInfo, number);