FileDocCategorySizeDatePackage
TestKeyStoreSpi.javaAPI DocAndroid 1.5 API7716Wed May 06 22:41:06 BST 2009org.apache.harmony.security.tests.support

TestKeyStoreSpi

public class TestKeyStoreSpi extends KeyStoreSpi

Fields Summary
Map
aliases
public static final Certificate
CERT
public static final Certificate[]
CERTCHAIN
public static final Key
KEY
public static final Object
DUMMY
Constructors Summary
public TestKeyStoreSpi()

 
    
      
        aliases.put("certalias", CERT);
        aliases.put("chainalias", CERTCHAIN);
        aliases.put("keyalias", KEY);
        aliases.put("unknownalias", DUMMY);
    
Methods Summary
public java.util.EnumerationengineAliases()

        return Collections.enumeration(aliases.keySet());
    
public booleanengineContainsAlias(java.lang.String alias)

        return aliases.containsKey(alias);
    
public voidengineDeleteEntry(java.lang.String alias)

        throw new KeyStoreException("entry " + alias + " cannot be deleted");
    
public java.security.cert.CertificateengineGetCertificate(java.lang.String alias)

        return (Certificate) aliases.get(alias);
    
public java.lang.StringengineGetCertificateAlias(java.security.cert.Certificate cert)

        if (cert == null) {
            throw new NullPointerException();
        }
        
        for (Map.Entry<String, Object> alias : aliases.entrySet()) {
            if (alias.getValue() == cert) {
                return alias.getKey();
            }
        }
        
        return null;
    
public java.security.cert.Certificate[]engineGetCertificateChain(java.lang.String alias)

        return (Certificate[]) aliases.get(alias);
    
public java.util.DateengineGetCreationDate(java.lang.String alias)

        return new Date(42 * 1024 * 1024);
    
public java.security.KeyengineGetKey(java.lang.String alias, char[] password)

        if (engineContainsAlias(alias)) {
            if (!engineIsKeyEntry(alias)) {
                if (password == null) {
                    throw new NoSuchAlgorithmException("no such alg");
                } else {
                    throw new UnrecoverableKeyException();
                }
                
            }
            return (Key) aliases.get(alias);
        }
        
        throw new UnrecoverableKeyException();
    
public booleanengineIsCertificateEntry(java.lang.String alias)

        try {
            Certificate c = (Certificate) aliases.get(alias);
            return true;
        } catch (ClassCastException e) {
            return false;
        }
    
public booleanengineIsKeyEntry(java.lang.String alias)

        try {
            Key k = (Key) aliases.get(alias);
            return true;
        } catch (ClassCastException e) {
            return false;
        }
    
public voidengineLoad(java.io.InputStream stream, char[] password)

        if (stream != null) {
            if (stream.available() == 0)
            {
                throw new IOException();
            }
        }
        if (password == null) {
            throw new NoSuchAlgorithmException();
        } else if (password.length == 0) {
            throw new CertificateException();
        }
    
public voidengineLoad(java.security.KeyStore.LoadStoreParameter param)

        if (param == null) {
            engineLoad(null, null);
            return;
        }

        ProtectionParameter pParam = param.getProtectionParameter();
        if (pParam == null) {
            throw new NoSuchAlgorithmException();
        }

        if (pParam instanceof PasswordProtection) {
            char[] password = ((PasswordProtection) pParam).getPassword();
            if (password == null) {
                throw new NoSuchAlgorithmException();
            } else {
                return;
            }
        }
        throw new CertificateException();
    
public voidengineSetCertificateEntry(java.lang.String alias, java.security.cert.Certificate cert)

        if (engineContainsAlias(alias)) {
            if (!engineIsCertificateEntry(alias)) {
                throw new KeyStoreException("alias is not a cert entry");
            }
        }
        aliases.put(alias, cert);
    
public voidengineSetKeyEntry(java.lang.String alias, java.security.Key key, char[] password, java.security.cert.Certificate[] chain)

        if (engineContainsAlias(alias)) {
            if (!engineIsKeyEntry(alias)) {
                throw new KeyStoreException("alias is not a key enrty");
            }
        }
        
        if (key instanceof PrivateKey)
        {
            if (chain == null || chain.length == 0) {
                throw new IllegalArgumentException();
            }
        }
        
        aliases.put(alias, key);
    
public voidengineSetKeyEntry(java.lang.String alias, byte[] key, java.security.cert.Certificate[] chain)

        throw new KeyStoreException("set entry failed");
    
public intengineSize()

        return aliases.size();
    
public voidengineStore(java.io.OutputStream stream, char[] password)

        if (stream == null) {
            throw new IOException("store failed");
        }
        
        if (password == null) {
            throw new NoSuchAlgorithmException();
        } else if (password.length == 0) { 
            throw new CertificateException();
        }
    
public voidengineStore(java.security.KeyStore.LoadStoreParameter param)

        if (param == null) {
            throw new IOException();
        }
        
        ProtectionParameter pParam = param.getProtectionParameter();
        if (pParam instanceof PasswordProtection) {
            char[] password = ((PasswordProtection) pParam).getPassword();
            if (password == null) {
                throw new NoSuchAlgorithmException();
            } else if (password.length == 0) {
                throw new CertificateException();
            }
            return;
        }
        throw new UnsupportedOperationException();