harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r443539 [11/29] - in /incubator/harmony/enhanced/classlib/trunk/modules/security: ./ .settings/ META-INF/ make/ src/main/java/common/java/security/ src/main/java/common/java/security/acl/ src/main/java/common/java/security/cert/ src/main/ja...
Date Fri, 15 Sep 2006 01:18:16 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java?view=diff&rev=443539&r1=443538&r2=443539
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java Thu Sep 14 18:17:39 2006
@@ -1,604 +1,604 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.security.tests.java.security;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.security.KeyPair;
-import java.security.KeyPairGenerator;
-import java.security.KeyStore;
-import java.security.PrivateKey;
-import java.security.Provider;
-import java.security.PublicKey;
-import java.security.SecureRandom;
-import java.security.Security;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Set;
-
-import tests.support.Support_TestProvider;
-import tests.support.resource.Support_Resources;
-
-public class KeyStore2Test extends junit.framework.TestCase {
-    static PrivateKey privateKey;
-    static {
-        try {
-            KeyPairGenerator keyPairGenerator = KeyPairGenerator
-                    .getInstance("DSA");
-
-            SecureRandom secureRandom = new SecureRandom();
-            keyPairGenerator.initialize(1024, secureRandom);
-            KeyPair keyPair = keyPairGenerator.genKeyPair();
-            privateKey = keyPair.getPrivate();
-        } catch (Exception e) {
-            fail("initialization failed: " + e);
-        }
-    }
-
-	final char[] pssWord = { 'a', 'b', 'c' };
-        private Provider support_TestProvider;
-
-	// creating a certificate
-	String certificate = "-----BEGIN CERTIFICATE-----\n"
-			+ "MIICZTCCAdICBQL3AAC2MA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw\n"
-			+ "HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl\n"
-			+ "IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NzAyMjAwMDAwMDBa\n"
-			+ "Fw05ODAyMjAyMzU5NTlaMIGWMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv\n"
-			+ "cm5pYTESMBAGA1UEBxMJUGFsbyBBbHRvMR8wHQYDVQQKExZTdW4gTWljcm9zeXN0\n"
-			+ "ZW1zLCBJbmMuMSEwHwYDVQQLExhUZXN0IGFuZCBFdmFsdWF0aW9uIE9ubHkxGjAY\n"
-			+ "BgNVBAMTEWFyZ29uLmVuZy5zdW4uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n"
-			+ "iQKBgQCofmdY+PiUWN01FOzEewf+GaG+lFf132UpzATmYJkA4AEA/juW7jSi+LJk\n"
-			+ "wJKi5GO4RyZoyimAL/5yIWDV6l1KlvxyKslr0REhMBaD/3Z3EsLTTEf5gVrQS6sT\n"
-			+ "WMoSZAyzB39kFfsB6oUXNtV8+UKKxSxKbxvhQn267PeCz5VX2QIDAQABMA0GCSqG\n"
-			+ "SIb3DQEBAgUAA34AXl3at6luiV/7I9MN5CXYoPJYI8Bcdc1hBagJvTMcmlqL2uOZ\n"
-			+ "H9T5hNMEL9Tk6aI7yZPXcw/xI2K6pOR/FrMp0UwJmdxX7ljV6ZtUZf7pY492UqwC\n"
-			+ "1777XQ9UEZyrKJvF5ntleeO0ayBqLGVKCWzWZX9YsXCpv47FNLZbupE=\n"
-			+ "-----END CERTIFICATE-----\n";
-
-	ByteArrayInputStream certArray = new ByteArrayInputStream(certificate
-			.getBytes());
-
-	String certificate2 = "-----BEGIN CERTIFICATE-----\n"
-			+ "MIICZzCCAdCgAwIBAgIBGzANBgkqhkiG9w0BAQUFADBhMQswCQYDVQQGEwJVUzEY\n"
-			+ "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n"
-			+ "A1BLSTEcMBoGA1UEAxMTRG9EIFBLSSBNZWQgUm9vdCBDQTAeFw05ODA4MDMyMjAy\n"
-			+ "MjlaFw0wODA4MDQyMjAyMjlaMGExCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9VLlMu\n"
-			+ "IEdvdmVybm1lbnQxDDAKBgNVBAsTA0RvRDEMMAoGA1UECxMDUEtJMRwwGgYDVQQD\n"
-			+ "ExNEb0QgUEtJIE1lZCBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n"
-			+ "gQDbrM/J9FrJSX+zxFUbsI9Vw5QbguVBIa95rwW/0M8+sM0r5gd+DY6iubm6wnXk\n"
-			+ "CSvbfQlFEDSKr4WYeeGp+d9WlDnQdtDFLdA45tCi5SHjnW+hGAmZnld0rz6wQekF\n"
-			+ "5xQaa5A6wjhMlLOjbh27zyscrorMJ1O5FBOWnEHcRv6xqQIDAQABoy8wLTAdBgNV\n"
-			+ "HQ4EFgQUVrmYR6m9701cHQ3r5kXyG7zsCN0wDAYDVR0TBAUwAwEB/zANBgkqhkiG\n"
-			+ "9w0BAQUFAAOBgQDVX1Y0YqC7vekeZjVxtyuC8Mnxbrz6D109AX07LEIRzNYzwZ0w\n"
-			+ "MTImSp9sEzWW+3FueBIU7AxGys2O7X0qmN3zgszPfSiocBuQuXIYQctJhKjF5KVc\n"
-			+ "VGQRYYlt+myhl2vy6yPzEVCjiKwMEb1Spu0irCf+lFW2hsdjvmSQMtZvOw==\n"
-			+ "-----END CERTIFICATE-----\n";
-
-	ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2
-			.getBytes());
-
-	String certificate3 = "-----BEGIN CERTIFICATE-----\n"
-			+ "MIIDXDCCAsWgAwIBAgIBSjANBgkqhkiG9w0BAQUFADBWMQswCQYDVQQGEwJVUzEY\n"
-			+ "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n"
-			+ "A1BLSTERMA8GA1UEAxMITWVkIENBLTEwHhcNOTgwODAyMTgwMjQwWhcNMDEwODAy\n"
-			+ "MTgwMjQwWjB0MQswCQYDVQQGEwJVUzEYMBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50\n"
-			+ "MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsTA1BLSTENMAsGA1UECxMEVVNBRjEgMB4G\n"
-			+ "A1UEAxMXR3VtYnkuSm9zZXBoLjAwMDAwMDUwNDQwgZ8wDQYJKoZIhvcNAQEBBQAD\n"
-			+ "gY0AMIGJAoGBALT/R7bPqs1c1YqXAg5HNpZLgW2HuAc7RCaP06cE4R44GBLw/fQc\n"
-			+ "VRNLn5pgbTXsDnjiZVd8qEgYqjKFQka4/tNhaF7No2tBZB+oYL/eP0IWtP+h/W6D\n"
-			+ "KR5+UvIIdgmx7k3t9jp2Q51JpHhhKEb9WN54trCO9Yu7PYU+LI85jEIBAgMBAAGj\n"
-			+ "ggEaMIIBFjAWBgNVHSAEDzANMAsGCWCGSAFlAgELAzAfBgNVHSMEGDAWgBQzOhTo\n"
-			+ "CWdhiGUkIOx5cELXppMe9jAdBgNVHQ4EFgQUkLBJl+ayKgzOp/wwBX9M1lSkCg4w\n"
-			+ "DgYDVR0PAQH/BAQDAgbAMAwGA1UdEwEB/wQCMAAwgZ0GA1UdHwSBlTCBkjCBj6CB\n"
-			+ "jKCBiYaBhmxkYXA6Ly9kcy0xLmNoYW1iLmRpc2EubWlsL2NuJTNkTWVkJTIwQ0El\n"
-			+ "MmQxJTJjb3UlM2RQS0klMmNvdSUzZERvRCUyY28lM2RVLlMuJTIwR292ZXJubWVu\n"
-			+ "dCUyY2MlM2RVUz9jZXJ0aWZpY2F0ZVJldm9jYXRpb25MaXN0JTNiYmluYXJ5MA0G\n"
-			+ "CSqGSIb3DQEBBQUAA4GBAFjapuDHMvIdUeYRyEYdShBR1JZC20tJ3MQnyBQveddz\n"
-			+ "LGFDGpIkRAQU7T/5/ne8lMexyxViC21xOlK9LdbJCbVyywvb9uEm/1je9wieQQtr\n"
-			+ "kjykuB+WB6qTCIslAO/eUmgzfzIENvnH8O+fH7QTr2PdkFkiPIqBJYHvw7F3XDqy\n"
-			+ "-----END CERTIFICATE-----\n";
-
-	ByteArrayInputStream certArray3 = new ByteArrayInputStream(certificate3
-			.getBytes());
-
-	private byte[] creatCertificate() throws Exception {
-		ByteArrayOutputStream out = null;
-
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-		// alias 1
-		keyTest.setCertificateEntry("alias1", cert[0]);
-
-		// alias 2
-        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
-
-		// alias 3
-		keyTest.setCertificateEntry("alias3", cert[1]);
-
-		out = new ByteArrayOutputStream();
-		keyTest.store(out, pssWord);
-		out.close();
-
-		return out.toByteArray();
-	}
-
-	/**
-	 * @tests java.security.KeyStore#aliases()
-	 */
-	public void test_aliases() throws Exception {
-		// Test for method java.util.Enumeration
-		// java.security.KeyStore.aliases()
-		// NOT COMPATIBLE WITH PCS#12
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-
-		// KeyStore keyTest =
-		// KeyStore.getInstance(KeyStore.getDefaultType());
-		// alias 1
-		keyTest.setCertificateEntry("alias1", cert[0]);
-
-		// alias 2
-		keyTest.setCertificateEntry("alias2", cert[0]);
-
-		// alias 3
-		keyTest.setCertificateEntry("alias3", cert[0]);
-
-		// obtaining the aliase
-		Enumeration aliase = keyTest.aliases();
-		Set alia = new HashSet();
-		int i = 0;
-		while (aliase.hasMoreElements()) {
-			alia.add(aliase.nextElement());
-			i++;
-		}
-		assertTrue("the alias names were returned wrong", i == 3
-				&& alia.contains("alias1") && alia.contains("alias2")
-				&& alia.contains("alias3"));
-	}
-
-	/**
-	 * @tests java.security.KeyStore#containsAlias(java.lang.String)
-	 */
-	public void test_containsAliasLjava_lang_String() throws Exception {
-		// Test for method boolean
-		// java.security.KeyStore.containsAlias(java.lang.String)
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-
-		// alias 1
-		keyTest.setCertificateEntry("alias1", cert[0]);
-
-		// alias 2
-		keyTest.setCertificateEntry("alias2", cert[0]);
-
-		assertTrue("alias1 does not exist", keyTest.containsAlias("alias1"));
-		assertTrue("alias2 does not exist", keyTest.containsAlias("alias2"));
-		assertFalse("alias3 exists", keyTest.containsAlias("alias3"));
-	}
-
-	/**
-	 * @tests java.security.KeyStore#getCertificate(java.lang.String)
-	 */
-	public void test_getCertificateLjava_lang_String() throws Exception {
-		// Test for method java.security.cert.Certificate
-		// java.security.KeyStore.getCertificate(java.lang.String)
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-
-		// alias 1
-		PublicKey pub = cert[0].getPublicKey();
-		keyTest.setCertificateEntry("alias1", cert[0]);
-
-		java.security.cert.Certificate certRes = keyTest
-				.getCertificate("alias1");
-		assertTrue("the public key of the certificate from getCertificate() "
-				+ "did not equal the original certificate", certRes
-				.getPublicKey() == pub);
-
-		// alias 2
-		keyTest.setCertificateEntry("alias2", cert[0]);
-
-		// testing for a certificate chain
-		java.security.cert.Certificate cert2 = keyTest.getCertificate("alias2");
-		assertTrue("the certificate for alias2 is supposed to exist",
-				cert2 != null && cert2.equals(cert[0]));
-
-	}
-
-	/**
-	 * @tests java.security.KeyStore#getCertificateAlias(java.security.cert.Certificate)
-	 */
-	public void test_getCertificateAliasLjava_security_cert_Certificate()
-			throws Exception {
-		// Test for method java.lang.String
-		// java.security.KeyStore.getCertificateAlias(java.security.cert.Certificate)
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-
-		// certificate entry
-		keyTest.setCertificateEntry("alias1", cert[1]);
-		String alias = keyTest.getCertificateAlias(cert[1]);
-		assertTrue("certificate entry - the alias returned for this "
-				+ "certificate was wrong", alias.equals("alias1"));
-
-		// key entry
-
-        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
-		alias = keyTest.getCertificateAlias(cert[0]);
-		assertTrue("key entry - the alias returned for this "
-				+ "certificate was wrong", alias.equals("alias2"));
-
-		// testing case with a nonexistant certificate
-		X509Certificate cert2 = (X509Certificate) cf
-				.generateCertificate(certArray3);
-		String aliasNull = keyTest.getCertificateAlias(cert2);
-		assertNull("the alias returned for the nonexist certificate "
-				+ "was NOT null", aliasNull);
-	}
-
-	/**
-	 * @tests java.security.KeyStore#getCertificateChain(java.lang.String)
-	 */
-	public void test_getCertificateChainLjava_lang_String() throws Exception {
-		// Test for method java.security.cert.Certificate []
-		// java.security.KeyStore.getCertificateChain(java.lang.String)
-		// creatCertificate();
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-
-		// alias 1
-		keyTest.setCertificateEntry("alias1", cert[0]);
-
-		// alias 2
-        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
-
-		java.security.cert.Certificate[] certRes = keyTest
-				.getCertificateChain("alias2");
-		assertTrue("there are more than two certificate returned "
-				+ "from getCertificateChain", certRes.length == 2);
-		assertTrue("the certificates returned from getCertificateChain "
-				+ "is not correct", cert[0].getPublicKey() == certRes[0]
-				.getPublicKey()
-				&& cert[1].getPublicKey() == certRes[1].getPublicKey());
-		java.security.cert.Certificate[] certResNull = keyTest
-				.getCertificateChain("alias1");
-		assertNull("the certificate chain returned from "
-				+ "getCertificateChain is NOT null", certResNull);
-	}
-
-	/**
-	 * @tests java.security.KeyStore#getInstance(java.lang.String)
-	 */
-	public void test_getInstanceLjava_lang_String() throws Exception {
-		// Test for method java.security.KeyStore
-		// java.security.KeyStore.getInstance(java.lang.String)
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		assertTrue("the method getInstance did not obtain "
-				+ "the correct type", keyTest.getType().equals(
-				KeyStore.getDefaultType()));
-	}
-
-	/**
-	 * @tests java.security.KeyStore#getInstance(java.lang.String,
-	 *        java.lang.String)
-	 */
-	public void test_getInstanceLjava_lang_StringLjava_lang_String()
-			throws Exception {
-		// Test for method java.security.KeyStore
-		// java.security.KeyStore.getInstance(java.lang.String,
-		// java.lang.String)
-		KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
-				"TestProvider");
-		assertTrue("the method getInstance did not obtain the "
-				+ "correct provider and type", keyTest.getProvider().getName()
-				.equals("TestProvider")
-				&& keyTest.getType().equals("PKCS#12/Netscape"));
-	}
-
-	/**
-	 * @tests java.security.KeyStore#getKey(java.lang.String, char[])
-	 */
-	public void test_getKeyLjava_lang_String$C() throws Exception {
-
-		// Test for method java.security.Key
-		// java.security.KeyStore.getKey(java.lang.String, char [])
-		// creatCertificate();
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-
-		keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
-		PrivateKey returnedKey = (PrivateKey) keyTest.getKey("alias2", pssWord);
-		byte[] retB = returnedKey.getEncoded();
-		byte[] priB = privateKey.getEncoded();
-		boolean equality = Arrays.equals(retB, priB);
-		equality &= returnedKey.getAlgorithm()
-				.equals(privateKey.getAlgorithm());
-		equality &= returnedKey.getFormat().equals(privateKey.getFormat());
-		assertTrue("the private key returned from getKey for a "
-				+ "key entry did not equal the original key", equality);
-
-		try {
-			keyTest.getKey("alias2", "wrong".toCharArray());
-			fail("Should have thrown UnrecoverableKeyException");
-		} catch (UnrecoverableKeyException e) {
-			// expected
-		}
-
-		keyTest.setCertificateEntry("alias1", cert[1]);
-		assertNull("the private key returned from getKey for "
-				+ "a certificate entry is not null", keyTest.getKey("alias1",
-				pssWord));
-	}
-
-	/**
-	 * @tests java.security.KeyStore#getProvider()
-	 */
-	public void test_getProvider() throws Exception {
-		// Test for method java.security.Provider
-		// java.security.KeyStore.getProvider()
-		KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
-				"TestProvider");
-		Provider provKeyStore = keyTest.getProvider();
-		assertEquals("the provider should be TestProvider", "TestProvider",
-				provKeyStore.getName());
-	}
-
-	/**
-	 * @tests java.security.KeyStore#getType()
-	 */
-	public void test_getType() throws Exception {
-		// Test for method java.lang.String java.security.KeyStore.getType()
-		KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
-				"TestProvider");
-		assertEquals(
-				"type should be PKCS#12/Netscape for provider TestProvider",
-				"PKCS#12/Netscape", keyTest.getType());
-	}
-
-	/**
-	 * @tests java.security.KeyStore#isCertificateEntry(java.lang.String)
-	 */
-	public void test_isCertificateEntryLjava_lang_String() throws Exception {
-		// Test for method boolean
-		// java.security.KeyStore.isCertificateEntry(java.lang.String)
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-		// alias 1
-		keyTest.setCertificateEntry("alias1", cert[0]);
-
-		// alias 2
-        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
-
-		assertTrue("isCertificateEntry method returns false for a certificate",
-				keyTest.isCertificateEntry("alias1") == true);
-		assertTrue("isCertificateEntry method returns true for noncertificate",
-				keyTest.isCertificateEntry("alias2") == false);
-	}
-
-	/**
-	 * @tests java.security.KeyStore#isKeyEntry(java.lang.String)
-	 */
-	public void test_isKeyEntryLjava_lang_String() throws Exception {
-		// Test for method boolean
-		// java.security.KeyStore.isKeyEntry(java.lang.String)
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-		// alias 1
-		keyTest.setCertificateEntry("alias1", cert[0]);
-
-		// alias 2
-        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
-
-		assertTrue("isKeyEntry method returns false for a certificate", keyTest
-				.isKeyEntry("alias2") == true);
-		assertTrue("isKeyEntry method returns true for noncertificate", keyTest
-				.isKeyEntry("alias1") == false);
-	}
-
-	/**
-	 * @tests java.security.KeyStore#load(java.io.InputStream, char[])
-	 */
-	public void test_loadLjava_io_InputStream$C() throws Exception {
-		// Test for method void java.security.KeyStore.load(java.io.InputStream,
-		// char [])
-		byte[] keyStore = creatCertificate();
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		InputStream in = new ByteArrayInputStream(keyStore);
-		keyTest.load(in, pssWord);
-		in.close();
-		assertTrue("alias1 is not a certificate", keyTest
-				.isCertificateEntry("alias1") == true);
-		assertTrue("alias2 is not a keyEntry",
-				keyTest.isKeyEntry("alias2") == true);
-		assertTrue("alias3 is not a certificate", keyTest
-				.isCertificateEntry("alias3") == true);
-
-		// test with null password
-		keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		in = new ByteArrayInputStream(keyStore);
-		keyTest.load(in, null);
-		in.close();
-		assertTrue("alias1 is not a certificate", keyTest
-				.isCertificateEntry("alias1") == true);
-		assertTrue("alias2 is not a keyEntry",
-				keyTest.isKeyEntry("alias2") == true);
-		assertTrue("alias3 is not a certificate", keyTest
-				.isCertificateEntry("alias3") == true);
-
-		keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		InputStream v1in = Support_Resources.getStream("hyts_ks.bks");
-		char[] pass = "abcdef".toCharArray();
-		keyTest.load(v1in, pass);
-		v1in.close();
-		keyTest.getKey("mykey", pass);
-	}
-
-	/**
-	 * @tests java.security.KeyStore#setCertificateEntry(java.lang.String,
-	 *        java.security.cert.Certificate)
-	 */
-	public void test_setCertificateEntryLjava_lang_StringLjava_security_cert_Certificate()
-			throws Exception {
-		// Test for method void
-		// java.security.KeyStore.setCertificateEntry(java.lang.String,
-		// java.security.cert.Certificate)
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert = (X509Certificate) cf
-				.generateCertificate(certArray);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-
-		PublicKey pub = cert.getPublicKey();
-		keyTest.setCertificateEntry("alias1", cert);
-		assertTrue(
-				"the entry specified by the alias alias1 is not a certificate",
-				keyTest.isCertificateEntry("alias1") == true);
-		java.security.cert.Certificate resultCert = keyTest
-				.getCertificate("alias1");
-		assertTrue(
-				"the public key of the certificate from getCertificate() did not equal the original certificate",
-				resultCert.getPublicKey() == pub);
-	}
-
-	/**
-	 * @tests java.security.KeyStore#setKeyEntry(java.lang.String, byte[],
-	 *        java.security.cert.Certificate[])
-	 */
-	public void test_setKeyEntryLjava_lang_String$B$Ljava_security_cert_Certificate()
-			throws Exception {
-
-//		fail("Test hangs - requires a full math implementation ??");
-
-		// Test for method void
-		// java.security.KeyStore.setKeyEntry(java.lang.String, byte [],
-		// java.security.cert.Certificate [])
-
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-
-		// set the same alias as keyEntry
-		keyTest.setKeyEntry("alias2", privateKey.getEncoded(), cert);
-		assertTrue("the entry specified by the alias alias2 is not a keyEntry",
-				keyTest.isKeyEntry("alias2"));
-	}
-
-	/**
-	 * @tests java.security.KeyStore#setKeyEntry(java.lang.String,
-	 *        java.security.Key, char[], java.security.cert.Certificate[])
-	 */
-	public void test_setKeyEntryLjava_lang_StringLjava_security_Key$C$Ljava_security_cert_Certificate()
-			throws Exception {
-
-		// Test for method void
-		// java.security.KeyStore.setKeyEntry(java.lang.String,
-		// java.security.Key, char [], java.security.cert.Certificate [])
-
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-
-		keyTest.setKeyEntry("alias3", privateKey, pssWord, cert);
-		assertTrue("the entry specified by the alias alias3 is not a keyEntry",
-				keyTest.isKeyEntry("alias3"));
-	}
-
-	/**
-	 * @tests java.security.KeyStore#size()
-	 */
-	public void test_size() throws Exception {
-		// Test for method int java.security.KeyStore.size()
-
-		CertificateFactory cf = CertificateFactory.getInstance("X.509");
-		X509Certificate cert[] = new X509Certificate[2];
-		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-		keyTest.load(null, null);
-		// alias 1
-		keyTest.setCertificateEntry("alias1", cert[0]);
-
-		// alias 2
-        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
-
-		// alias 3
-		keyTest.setCertificateEntry("alias3", cert[1]);
-
-		assertEquals("the size of the keyStore is not 3", 3, keyTest.size());
-	}
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() throws Exception {
-        super.setUp();
-        support_TestProvider = new Support_TestProvider();
-        Security.addProvider(support_TestProvider);
-    }
-
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        Security.removeProvider(support_TestProvider.getName());
-    }
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.Provider;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+import tests.support.Support_TestProvider;
+import tests.support.resource.Support_Resources;
+
+public class KeyStore2Test extends junit.framework.TestCase {
+    static PrivateKey privateKey;
+    static {
+        try {
+            KeyPairGenerator keyPairGenerator = KeyPairGenerator
+                    .getInstance("DSA");
+
+            SecureRandom secureRandom = new SecureRandom();
+            keyPairGenerator.initialize(1024, secureRandom);
+            KeyPair keyPair = keyPairGenerator.genKeyPair();
+            privateKey = keyPair.getPrivate();
+        } catch (Exception e) {
+            fail("initialization failed: " + e);
+        }
+    }
+
+	final char[] pssWord = { 'a', 'b', 'c' };
+        private Provider support_TestProvider;
+
+	// creating a certificate
+	String certificate = "-----BEGIN CERTIFICATE-----\n"
+			+ "MIICZTCCAdICBQL3AAC2MA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw\n"
+			+ "HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl\n"
+			+ "IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NzAyMjAwMDAwMDBa\n"
+			+ "Fw05ODAyMjAyMzU5NTlaMIGWMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv\n"
+			+ "cm5pYTESMBAGA1UEBxMJUGFsbyBBbHRvMR8wHQYDVQQKExZTdW4gTWljcm9zeXN0\n"
+			+ "ZW1zLCBJbmMuMSEwHwYDVQQLExhUZXN0IGFuZCBFdmFsdWF0aW9uIE9ubHkxGjAY\n"
+			+ "BgNVBAMTEWFyZ29uLmVuZy5zdW4uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n"
+			+ "iQKBgQCofmdY+PiUWN01FOzEewf+GaG+lFf132UpzATmYJkA4AEA/juW7jSi+LJk\n"
+			+ "wJKi5GO4RyZoyimAL/5yIWDV6l1KlvxyKslr0REhMBaD/3Z3EsLTTEf5gVrQS6sT\n"
+			+ "WMoSZAyzB39kFfsB6oUXNtV8+UKKxSxKbxvhQn267PeCz5VX2QIDAQABMA0GCSqG\n"
+			+ "SIb3DQEBAgUAA34AXl3at6luiV/7I9MN5CXYoPJYI8Bcdc1hBagJvTMcmlqL2uOZ\n"
+			+ "H9T5hNMEL9Tk6aI7yZPXcw/xI2K6pOR/FrMp0UwJmdxX7ljV6ZtUZf7pY492UqwC\n"
+			+ "1777XQ9UEZyrKJvF5ntleeO0ayBqLGVKCWzWZX9YsXCpv47FNLZbupE=\n"
+			+ "-----END CERTIFICATE-----\n";
+
+	ByteArrayInputStream certArray = new ByteArrayInputStream(certificate
+			.getBytes());
+
+	String certificate2 = "-----BEGIN CERTIFICATE-----\n"
+			+ "MIICZzCCAdCgAwIBAgIBGzANBgkqhkiG9w0BAQUFADBhMQswCQYDVQQGEwJVUzEY\n"
+			+ "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n"
+			+ "A1BLSTEcMBoGA1UEAxMTRG9EIFBLSSBNZWQgUm9vdCBDQTAeFw05ODA4MDMyMjAy\n"
+			+ "MjlaFw0wODA4MDQyMjAyMjlaMGExCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9VLlMu\n"
+			+ "IEdvdmVybm1lbnQxDDAKBgNVBAsTA0RvRDEMMAoGA1UECxMDUEtJMRwwGgYDVQQD\n"
+			+ "ExNEb0QgUEtJIE1lZCBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n"
+			+ "gQDbrM/J9FrJSX+zxFUbsI9Vw5QbguVBIa95rwW/0M8+sM0r5gd+DY6iubm6wnXk\n"
+			+ "CSvbfQlFEDSKr4WYeeGp+d9WlDnQdtDFLdA45tCi5SHjnW+hGAmZnld0rz6wQekF\n"
+			+ "5xQaa5A6wjhMlLOjbh27zyscrorMJ1O5FBOWnEHcRv6xqQIDAQABoy8wLTAdBgNV\n"
+			+ "HQ4EFgQUVrmYR6m9701cHQ3r5kXyG7zsCN0wDAYDVR0TBAUwAwEB/zANBgkqhkiG\n"
+			+ "9w0BAQUFAAOBgQDVX1Y0YqC7vekeZjVxtyuC8Mnxbrz6D109AX07LEIRzNYzwZ0w\n"
+			+ "MTImSp9sEzWW+3FueBIU7AxGys2O7X0qmN3zgszPfSiocBuQuXIYQctJhKjF5KVc\n"
+			+ "VGQRYYlt+myhl2vy6yPzEVCjiKwMEb1Spu0irCf+lFW2hsdjvmSQMtZvOw==\n"
+			+ "-----END CERTIFICATE-----\n";
+
+	ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2
+			.getBytes());
+
+	String certificate3 = "-----BEGIN CERTIFICATE-----\n"
+			+ "MIIDXDCCAsWgAwIBAgIBSjANBgkqhkiG9w0BAQUFADBWMQswCQYDVQQGEwJVUzEY\n"
+			+ "MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsT\n"
+			+ "A1BLSTERMA8GA1UEAxMITWVkIENBLTEwHhcNOTgwODAyMTgwMjQwWhcNMDEwODAy\n"
+			+ "MTgwMjQwWjB0MQswCQYDVQQGEwJVUzEYMBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50\n"
+			+ "MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsTA1BLSTENMAsGA1UECxMEVVNBRjEgMB4G\n"
+			+ "A1UEAxMXR3VtYnkuSm9zZXBoLjAwMDAwMDUwNDQwgZ8wDQYJKoZIhvcNAQEBBQAD\n"
+			+ "gY0AMIGJAoGBALT/R7bPqs1c1YqXAg5HNpZLgW2HuAc7RCaP06cE4R44GBLw/fQc\n"
+			+ "VRNLn5pgbTXsDnjiZVd8qEgYqjKFQka4/tNhaF7No2tBZB+oYL/eP0IWtP+h/W6D\n"
+			+ "KR5+UvIIdgmx7k3t9jp2Q51JpHhhKEb9WN54trCO9Yu7PYU+LI85jEIBAgMBAAGj\n"
+			+ "ggEaMIIBFjAWBgNVHSAEDzANMAsGCWCGSAFlAgELAzAfBgNVHSMEGDAWgBQzOhTo\n"
+			+ "CWdhiGUkIOx5cELXppMe9jAdBgNVHQ4EFgQUkLBJl+ayKgzOp/wwBX9M1lSkCg4w\n"
+			+ "DgYDVR0PAQH/BAQDAgbAMAwGA1UdEwEB/wQCMAAwgZ0GA1UdHwSBlTCBkjCBj6CB\n"
+			+ "jKCBiYaBhmxkYXA6Ly9kcy0xLmNoYW1iLmRpc2EubWlsL2NuJTNkTWVkJTIwQ0El\n"
+			+ "MmQxJTJjb3UlM2RQS0klMmNvdSUzZERvRCUyY28lM2RVLlMuJTIwR292ZXJubWVu\n"
+			+ "dCUyY2MlM2RVUz9jZXJ0aWZpY2F0ZVJldm9jYXRpb25MaXN0JTNiYmluYXJ5MA0G\n"
+			+ "CSqGSIb3DQEBBQUAA4GBAFjapuDHMvIdUeYRyEYdShBR1JZC20tJ3MQnyBQveddz\n"
+			+ "LGFDGpIkRAQU7T/5/ne8lMexyxViC21xOlK9LdbJCbVyywvb9uEm/1je9wieQQtr\n"
+			+ "kjykuB+WB6qTCIslAO/eUmgzfzIENvnH8O+fH7QTr2PdkFkiPIqBJYHvw7F3XDqy\n"
+			+ "-----END CERTIFICATE-----\n";
+
+	ByteArrayInputStream certArray3 = new ByteArrayInputStream(certificate3
+			.getBytes());
+
+	private byte[] creatCertificate() throws Exception {
+		ByteArrayOutputStream out = null;
+
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// alias 1
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
+
+		// alias 3
+		keyTest.setCertificateEntry("alias3", cert[1]);
+
+		out = new ByteArrayOutputStream();
+		keyTest.store(out, pssWord);
+		out.close();
+
+		return out.toByteArray();
+	}
+
+	/**
+	 * @tests java.security.KeyStore#aliases()
+	 */
+	public void test_aliases() throws Exception {
+		// Test for method java.util.Enumeration
+		// java.security.KeyStore.aliases()
+		// NOT COMPATIBLE WITH PCS#12
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// KeyStore keyTest =
+		// KeyStore.getInstance(KeyStore.getDefaultType());
+		// alias 1
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+
+		// alias 3
+		keyTest.setCertificateEntry("alias3", cert[0]);
+
+		// obtaining the aliase
+		Enumeration aliase = keyTest.aliases();
+		Set alia = new HashSet();
+		int i = 0;
+		while (aliase.hasMoreElements()) {
+			alia.add(aliase.nextElement());
+			i++;
+		}
+		assertTrue("the alias names were returned wrong", i == 3
+				&& alia.contains("alias1") && alia.contains("alias2")
+				&& alia.contains("alias3"));
+	}
+
+	/**
+	 * @tests java.security.KeyStore#containsAlias(java.lang.String)
+	 */
+	public void test_containsAliasLjava_lang_String() throws Exception {
+		// Test for method boolean
+		// java.security.KeyStore.containsAlias(java.lang.String)
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// alias 1
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+
+		assertTrue("alias1 does not exist", keyTest.containsAlias("alias1"));
+		assertTrue("alias2 does not exist", keyTest.containsAlias("alias2"));
+		assertFalse("alias3 exists", keyTest.containsAlias("alias3"));
+	}
+
+	/**
+	 * @tests java.security.KeyStore#getCertificate(java.lang.String)
+	 */
+	public void test_getCertificateLjava_lang_String() throws Exception {
+		// Test for method java.security.cert.Certificate
+		// java.security.KeyStore.getCertificate(java.lang.String)
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// alias 1
+		PublicKey pub = cert[0].getPublicKey();
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		java.security.cert.Certificate certRes = keyTest
+				.getCertificate("alias1");
+		assertTrue("the public key of the certificate from getCertificate() "
+				+ "did not equal the original certificate", certRes
+				.getPublicKey() == pub);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+
+		// testing for a certificate chain
+		java.security.cert.Certificate cert2 = keyTest.getCertificate("alias2");
+		assertTrue("the certificate for alias2 is supposed to exist",
+				cert2 != null && cert2.equals(cert[0]));
+
+	}
+
+	/**
+	 * @tests java.security.KeyStore#getCertificateAlias(java.security.cert.Certificate)
+	 */
+	public void test_getCertificateAliasLjava_security_cert_Certificate()
+			throws Exception {
+		// Test for method java.lang.String
+		// java.security.KeyStore.getCertificateAlias(java.security.cert.Certificate)
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// certificate entry
+		keyTest.setCertificateEntry("alias1", cert[1]);
+		String alias = keyTest.getCertificateAlias(cert[1]);
+		assertTrue("certificate entry - the alias returned for this "
+				+ "certificate was wrong", alias.equals("alias1"));
+
+		// key entry
+
+        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
+		alias = keyTest.getCertificateAlias(cert[0]);
+		assertTrue("key entry - the alias returned for this "
+				+ "certificate was wrong", alias.equals("alias2"));
+
+		// testing case with a nonexistant certificate
+		X509Certificate cert2 = (X509Certificate) cf
+				.generateCertificate(certArray3);
+		String aliasNull = keyTest.getCertificateAlias(cert2);
+		assertNull("the alias returned for the nonexist certificate "
+				+ "was NOT null", aliasNull);
+	}
+
+	/**
+	 * @tests java.security.KeyStore#getCertificateChain(java.lang.String)
+	 */
+	public void test_getCertificateChainLjava_lang_String() throws Exception {
+		// Test for method java.security.cert.Certificate []
+		// java.security.KeyStore.getCertificateChain(java.lang.String)
+		// creatCertificate();
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// alias 1
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
+
+		java.security.cert.Certificate[] certRes = keyTest
+				.getCertificateChain("alias2");
+		assertTrue("there are more than two certificate returned "
+				+ "from getCertificateChain", certRes.length == 2);
+		assertTrue("the certificates returned from getCertificateChain "
+				+ "is not correct", cert[0].getPublicKey() == certRes[0]
+				.getPublicKey()
+				&& cert[1].getPublicKey() == certRes[1].getPublicKey());
+		java.security.cert.Certificate[] certResNull = keyTest
+				.getCertificateChain("alias1");
+		assertNull("the certificate chain returned from "
+				+ "getCertificateChain is NOT null", certResNull);
+	}
+
+	/**
+	 * @tests java.security.KeyStore#getInstance(java.lang.String)
+	 */
+	public void test_getInstanceLjava_lang_String() throws Exception {
+		// Test for method java.security.KeyStore
+		// java.security.KeyStore.getInstance(java.lang.String)
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		assertTrue("the method getInstance did not obtain "
+				+ "the correct type", keyTest.getType().equals(
+				KeyStore.getDefaultType()));
+	}
+
+	/**
+	 * @tests java.security.KeyStore#getInstance(java.lang.String,
+	 *        java.lang.String)
+	 */
+	public void test_getInstanceLjava_lang_StringLjava_lang_String()
+			throws Exception {
+		// Test for method java.security.KeyStore
+		// java.security.KeyStore.getInstance(java.lang.String,
+		// java.lang.String)
+		KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
+				"TestProvider");
+		assertTrue("the method getInstance did not obtain the "
+				+ "correct provider and type", keyTest.getProvider().getName()
+				.equals("TestProvider")
+				&& keyTest.getType().equals("PKCS#12/Netscape"));
+	}
+
+	/**
+	 * @tests java.security.KeyStore#getKey(java.lang.String, char[])
+	 */
+	public void test_getKeyLjava_lang_String$C() throws Exception {
+
+		// Test for method java.security.Key
+		// java.security.KeyStore.getKey(java.lang.String, char [])
+		// creatCertificate();
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
+		PrivateKey returnedKey = (PrivateKey) keyTest.getKey("alias2", pssWord);
+		byte[] retB = returnedKey.getEncoded();
+		byte[] priB = privateKey.getEncoded();
+		boolean equality = Arrays.equals(retB, priB);
+		equality &= returnedKey.getAlgorithm()
+				.equals(privateKey.getAlgorithm());
+		equality &= returnedKey.getFormat().equals(privateKey.getFormat());
+		assertTrue("the private key returned from getKey for a "
+				+ "key entry did not equal the original key", equality);
+
+		try {
+			keyTest.getKey("alias2", "wrong".toCharArray());
+			fail("Should have thrown UnrecoverableKeyException");
+		} catch (UnrecoverableKeyException e) {
+			// expected
+		}
+
+		keyTest.setCertificateEntry("alias1", cert[1]);
+		assertNull("the private key returned from getKey for "
+				+ "a certificate entry is not null", keyTest.getKey("alias1",
+				pssWord));
+	}
+
+	/**
+	 * @tests java.security.KeyStore#getProvider()
+	 */
+	public void test_getProvider() throws Exception {
+		// Test for method java.security.Provider
+		// java.security.KeyStore.getProvider()
+		KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
+				"TestProvider");
+		Provider provKeyStore = keyTest.getProvider();
+		assertEquals("the provider should be TestProvider", "TestProvider",
+				provKeyStore.getName());
+	}
+
+	/**
+	 * @tests java.security.KeyStore#getType()
+	 */
+	public void test_getType() throws Exception {
+		// Test for method java.lang.String java.security.KeyStore.getType()
+		KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
+				"TestProvider");
+		assertEquals(
+				"type should be PKCS#12/Netscape for provider TestProvider",
+				"PKCS#12/Netscape", keyTest.getType());
+	}
+
+	/**
+	 * @tests java.security.KeyStore#isCertificateEntry(java.lang.String)
+	 */
+	public void test_isCertificateEntryLjava_lang_String() throws Exception {
+		// Test for method boolean
+		// java.security.KeyStore.isCertificateEntry(java.lang.String)
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// alias 1
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
+
+		assertTrue("isCertificateEntry method returns false for a certificate",
+				keyTest.isCertificateEntry("alias1") == true);
+		assertTrue("isCertificateEntry method returns true for noncertificate",
+				keyTest.isCertificateEntry("alias2") == false);
+	}
+
+	/**
+	 * @tests java.security.KeyStore#isKeyEntry(java.lang.String)
+	 */
+	public void test_isKeyEntryLjava_lang_String() throws Exception {
+		// Test for method boolean
+		// java.security.KeyStore.isKeyEntry(java.lang.String)
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// alias 1
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
+
+		assertTrue("isKeyEntry method returns false for a certificate", keyTest
+				.isKeyEntry("alias2") == true);
+		assertTrue("isKeyEntry method returns true for noncertificate", keyTest
+				.isKeyEntry("alias1") == false);
+	}
+
+	/**
+	 * @tests java.security.KeyStore#load(java.io.InputStream, char[])
+	 */
+	public void test_loadLjava_io_InputStream$C() throws Exception {
+		// Test for method void java.security.KeyStore.load(java.io.InputStream,
+		// char [])
+		byte[] keyStore = creatCertificate();
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		InputStream in = new ByteArrayInputStream(keyStore);
+		keyTest.load(in, pssWord);
+		in.close();
+		assertTrue("alias1 is not a certificate", keyTest
+				.isCertificateEntry("alias1") == true);
+		assertTrue("alias2 is not a keyEntry",
+				keyTest.isKeyEntry("alias2") == true);
+		assertTrue("alias3 is not a certificate", keyTest
+				.isCertificateEntry("alias3") == true);
+
+		// test with null password
+		keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		in = new ByteArrayInputStream(keyStore);
+		keyTest.load(in, null);
+		in.close();
+		assertTrue("alias1 is not a certificate", keyTest
+				.isCertificateEntry("alias1") == true);
+		assertTrue("alias2 is not a keyEntry",
+				keyTest.isKeyEntry("alias2") == true);
+		assertTrue("alias3 is not a certificate", keyTest
+				.isCertificateEntry("alias3") == true);
+
+		keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		InputStream v1in = Support_Resources.getStream("hyts_ks.bks");
+		char[] pass = "abcdef".toCharArray();
+		keyTest.load(v1in, pass);
+		v1in.close();
+		keyTest.getKey("mykey", pass);
+	}
+
+	/**
+	 * @tests java.security.KeyStore#setCertificateEntry(java.lang.String,
+	 *        java.security.cert.Certificate)
+	 */
+	public void test_setCertificateEntryLjava_lang_StringLjava_security_cert_Certificate()
+			throws Exception {
+		// Test for method void
+		// java.security.KeyStore.setCertificateEntry(java.lang.String,
+		// java.security.cert.Certificate)
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert = (X509Certificate) cf
+				.generateCertificate(certArray);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		PublicKey pub = cert.getPublicKey();
+		keyTest.setCertificateEntry("alias1", cert);
+		assertTrue(
+				"the entry specified by the alias alias1 is not a certificate",
+				keyTest.isCertificateEntry("alias1") == true);
+		java.security.cert.Certificate resultCert = keyTest
+				.getCertificate("alias1");
+		assertTrue(
+				"the public key of the certificate from getCertificate() did not equal the original certificate",
+				resultCert.getPublicKey() == pub);
+	}
+
+	/**
+	 * @tests java.security.KeyStore#setKeyEntry(java.lang.String, byte[],
+	 *        java.security.cert.Certificate[])
+	 */
+	public void test_setKeyEntryLjava_lang_String$B$Ljava_security_cert_Certificate()
+			throws Exception {
+
+//		fail("Test hangs - requires a full math implementation ??");
+
+		// Test for method void
+		// java.security.KeyStore.setKeyEntry(java.lang.String, byte [],
+		// java.security.cert.Certificate [])
+
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// set the same alias as keyEntry
+		keyTest.setKeyEntry("alias2", privateKey.getEncoded(), cert);
+		assertTrue("the entry specified by the alias alias2 is not a keyEntry",
+				keyTest.isKeyEntry("alias2"));
+	}
+
+	/**
+	 * @tests java.security.KeyStore#setKeyEntry(java.lang.String,
+	 *        java.security.Key, char[], java.security.cert.Certificate[])
+	 */
+	public void test_setKeyEntryLjava_lang_StringLjava_security_Key$C$Ljava_security_cert_Certificate()
+			throws Exception {
+
+		// Test for method void
+		// java.security.KeyStore.setKeyEntry(java.lang.String,
+		// java.security.Key, char [], java.security.cert.Certificate [])
+
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		keyTest.setKeyEntry("alias3", privateKey, pssWord, cert);
+		assertTrue("the entry specified by the alias alias3 is not a keyEntry",
+				keyTest.isKeyEntry("alias3"));
+	}
+
+	/**
+	 * @tests java.security.KeyStore#size()
+	 */
+	public void test_size() throws Exception {
+		// Test for method int java.security.KeyStore.size()
+
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// alias 1
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+        keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
+
+		// alias 3
+		keyTest.setCertificateEntry("alias3", cert[1]);
+
+		assertEquals("the size of the keyStore is not 3", 3, keyTest.size());
+	}
+
+	/**
+	 * Sets up the fixture, for example, open a network connection. This method
+	 * is called before a test is executed.
+	 */
+	protected void setUp() throws Exception {
+        super.setUp();
+        support_TestProvider = new Support_TestProvider();
+        Security.addProvider(support_TestProvider);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        Security.removeProvider(support_TestProvider.getName());
+    }
 }

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreException2Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreException2Test.java?view=diff&rev=443539&r1=443538&r2=443539
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreException2Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreException2Test.java Thu Sep 14 18:17:39 2006
@@ -1,42 +1,42 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.security.tests.java.security;
-
-import java.security.KeyStoreException;
-
-public class KeyStoreException2Test extends junit.framework.TestCase {
-
-	/**
-	 * @tests java.security.KeyStoreException#KeyStoreException()
-	 */
-	public void test_Constructor() {
-		// Test for method java.security.KeyStoreException()
-		KeyStoreException e = new KeyStoreException();
-		assertEquals("Failed toString test for constructed instance", "java.security.KeyStoreException", e
-				.toString());
-	}
-
-	/**
-	 * @tests java.security.KeyStoreException#KeyStoreException(java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_String() {
-		// Test for method java.security.KeyStoreException(java.lang.String)
-		KeyStoreException e = new KeyStoreException("test message");
-		assertEquals("Failed toString test for constructed instance", 
-						"java.security.KeyStoreException: test message", e
-				.toString());
-	}
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.security.KeyStoreException;
+
+public class KeyStoreException2Test extends junit.framework.TestCase {
+
+	/**
+	 * @tests java.security.KeyStoreException#KeyStoreException()
+	 */
+	public void test_Constructor() {
+		// Test for method java.security.KeyStoreException()
+		KeyStoreException e = new KeyStoreException();
+		assertEquals("Failed toString test for constructed instance", "java.security.KeyStoreException", e
+				.toString());
+	}
+
+	/**
+	 * @tests java.security.KeyStoreException#KeyStoreException(java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		// Test for method java.security.KeyStoreException(java.lang.String)
+		KeyStoreException e = new KeyStoreException("test message");
+		assertEquals("Failed toString test for constructed instance", 
+						"java.security.KeyStoreException: test message", e
+				.toString());
+	}
 }

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreException2Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreSpiTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyStoreTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/KeyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest1Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest2Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest2Test.java?view=diff&rev=443539&r1=443538&r2=443539
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest2Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest2Test.java Thu Sep 14 18:17:39 2006
@@ -1,451 +1,451 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.security.tests.java.security;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.security.DigestException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
-import java.security.Security;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Vector;
-
-public class MessageDigest2Test extends junit.framework.TestCase {
-
-	private static final String MESSAGEDIGEST_ID = "MessageDigest.";
-
-	private String[] digestAlgs = null;
-
-	private String providerName = null;
-
-	private static final byte[] AR1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
-
-	private static final byte[] AR2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
-
-	private static final String MESSAGE = "abc";
-
-	private static final byte[] MESSAGE_DIGEST = { -87, -103, 62, 54, 71, 6,
-			-127, 106, -70, 62, 37, 113, 120, 80, -62, 108, -100, -48, -40,
-			-99, };
-
-	private static final byte[] MESSAGE_DIGEST_63_As = { 3, -16, -97, 91, 21,
-			-118, 122, -116, -38, -39, 32, -67, -36, 41, -72, 28, 24, -91, 81,
-			-11, };
-
-	private static final byte[] MESSAGE_DIGEST_64_As = { 0, -104, -70, -126,
-			75, 92, 22, 66, 123, -41, -95, 18, 42, 90, 68, 42, 37, -20, 100,
-			77, };
-
-	private static final byte[] MESSAGE_DIGEST_65_As = { 17, 101, 83, 38, -57,
-			8, -41, 3, 25, -66, 38, 16, -24, -91, 125, -102, 91, -107, -99, 59, };
-
-	/**
-	 * @tests java.security.MessageDigest#clone()
-	 */
-	public void test_clone() {
-		for (int i = 0; i < digestAlgs.length; i++) {
-			try {
-				MessageDigest d1 = MessageDigest.getInstance(digestAlgs[i],
-						providerName);
-				for (byte b = 0; b < 84; b++) {
-					d1.update(b);
-				}
-
-				MessageDigest d2 = (MessageDigest) d1.clone();
-				d1.update((byte) 1);
-				d2.update((byte) 1);
-
-				assertTrue("cloned hash differs from original for algorithm "
-						+ digestAlgs[i], MessageDigest.isEqual(d1.digest(), d2
-						.digest()));
-			} catch (CloneNotSupportedException e) {
-				// Expected - a Signature may not be cloneable
-			} catch (NoSuchAlgorithmException e) {
-				fail("getInstance did not find algorithm " + digestAlgs[i]);
-			} catch (NoSuchProviderException e) {
-				fail("getInstance did not find provider " + providerName);
-			}
-		}
-	}
-
-	private static final byte[] SHA_DATA_2 = { 70, -54, 124, 120, -29, 57, 56,
-			119, -108, -54, -97, -76, -97, -50, -63, -73, 2, 85, -53, -79, };
-
-	private void testSerializationSHA_DATA_2(MessageDigest sha) {
-		try {
-			sha.reset();
-			ByteArrayOutputStream out = new ByteArrayOutputStream();
-			DataOutputStream output = new DataOutputStream(out);
-			// -----------------------------------------------------------------------
-
-			// Made up data
-			output
-					.writeUTF("tests.api.java.security.MessageDigestTest$InitializerFieldsTest3");
-			output.writeInt(0); // class modifiers
-			output.writeUTF("java.io.Serializable"); // interfaces
-
-			// Fields
-			output.writeUTF("sub_toBeNotSerialized"); // name
-			output.writeInt(9); // modifiers
-			output.writeUTF("Ljava/lang/String;"); // signature
-
-			output.writeUTF("sub_toBeNotSerialized2"); // name
-			output.writeInt(9); // modifiers
-			output.writeUTF("Ljava/lang/String;"); // signature
-
-			output.writeUTF("sub_toBeSerialized"); // name
-			output.writeInt(1); // modifiers
-			output.writeUTF("Ljava/lang/String;"); // signature
-
-			output.writeUTF("sub_toBeSerialized3"); // name
-			output.writeInt(1); // modifiers
-			output.writeUTF("Ljava/lang/String;"); // signature
-
-			output.writeUTF("sub_toBeSerialized4"); // name
-			output.writeInt(1); // modifiers
-			output.writeUTF("Ljava/lang/String;"); // signature
-
-			output.writeUTF("sub_toBeSerialized5"); // name
-			output.writeInt(1); // modifiers
-			output.writeUTF("Ljava/lang/String;"); // signature
-
-			// clinit
-			output.writeUTF("<clinit>"); // name
-			output.writeInt(8); // modifiers
-			output.writeUTF("()V"); // signature
-
-			// constructors
-			output.writeUTF("<init>"); // name
-			output.writeInt(0); // modifiers
-			output.writeUTF("()V"); // signature
-
-			// methods
-			output.writeUTF("equals"); // name
-			output.writeInt(1); // modifiers
-			output.writeUTF("(Ljava.lang.Object;)Z"); // signature
-
-			// -----------------------------------------------------------------------
-
-			output.flush();
-
-			byte[] data = out.toByteArray();
-			byte[] hash = sha.digest(data);
-			assertTrue("SHA_DATA_2 NOT ok", Arrays.equals(hash, SHA_DATA_2));
-		} catch (IOException e) {
-			fail("SHA_DATA_2 NOT ok");
-		}
-	}
-
-	private static final byte[] SHA_DATA_1 = { 90, 36, 111, 106, -32, 38, 4,
-			126, 21, -51, 107, 45, -64, -68, -109, 112, -31, -46, 34, 115, };
-
-	private void testSerializationSHA_DATA_1(MessageDigest sha) {
-		try {
-			sha.reset();
-			ByteArrayOutputStream out = new ByteArrayOutputStream();
-			DataOutputStream output = new DataOutputStream(out);
-			// -----------------------------------------------------------------------
-
-			// Made up data
-			output
-					.writeUTF("tests.api.java.security.MessageDigestTest$OptionalDataNotRead");
-			// name
-			output.writeInt(0); // class modifiers
-			output.writeUTF("java.io.Serializable"); // interfaces
-
-			// Fields
-			output.writeUTF("class$0"); // name
-			output.writeInt(8); // modifiers
-			output.writeUTF("Ljava/lang/Class;"); // signature
-
-			output.writeUTF("field1"); // name
-			output.writeInt(2); // modifiers
-			output.writeUTF("I"); // signature
-
-			output.writeUTF("field2"); // name
-			output.writeInt(2); // modifiers
-			output.writeUTF("I"); // signature
-
-			// clinit
-			output.writeUTF("<clinit>"); // name
-			output.writeInt(8); // modifiers
-			output.writeUTF("()V"); // signature
-
-			// constructors
-			output.writeUTF("<init>"); // name
-			output.writeInt(1); // modifiers
-			output.writeUTF("()V"); // signature
-			// -----------------------------------------------------------------------
-
-			output.flush();
-			byte[] data = out.toByteArray();
-			byte[] hash = sha.digest(data);
-			assertTrue("SHA_DATA_1 NOT ok", Arrays.equals(hash, SHA_DATA_1));
-		} catch (IOException e) {
-			fail("SHA_DATA_1 NOT ok");
-		}
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#digest()
-	 */
-	public void test_digest() {
-		MessageDigest sha = null;
-		try {
-			sha = MessageDigest.getInstance("SHA");
-			assertNotNull(sha);
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
-		}
-		sha.update(MESSAGE.getBytes());
-		byte[] digest = sha.digest();
-		assertTrue("bug in SHA", MessageDigest.isEqual(digest, MESSAGE_DIGEST));
-
-		sha.reset();
-		for (int i = 0; i < 63; i++) {
-			// just under buffer capacity
-			sha.update((byte) 'a');
-		}
-		digest = sha.digest();
-		assertTrue("bug in SHA", MessageDigest.isEqual(digest,
-				MESSAGE_DIGEST_63_As));
-
-		sha.reset();
-		for (int i = 0; i < 64; i++) {
-			// exact SHA buffer capacity
-			sha.update((byte) 'a');
-		}
-		digest = sha.digest();
-		assertTrue("bug in SHA", MessageDigest.isEqual(digest,
-				MESSAGE_DIGEST_64_As));
-
-		sha.reset();
-		for (int i = 0; i < 65; i++) {
-			// just above SHA buffer capacity
-			sha.update((byte) 'a');
-		}
-		digest = sha.digest();
-		assertTrue("bug in SHA", MessageDigest.isEqual(digest,
-				MESSAGE_DIGEST_65_As));
-
-		testSerializationSHA_DATA_1(sha);
-		testSerializationSHA_DATA_2(sha);
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#digest(byte[])
-	 */
-	public void test_digest$B() {
-		for (int i = 0; i < digestAlgs.length; i++) {
-			try {
-				MessageDigest digest = MessageDigest.getInstance(digestAlgs[i],
-						providerName);
-				assertNotNull(digest);
-				digest.digest(AR1);
-			} catch (NoSuchAlgorithmException e) {
-				fail("getInstance did not find algorithm " + digestAlgs[i]);
-			} catch (NoSuchProviderException e) {
-				fail("getInstance did not find provider " + providerName);
-			}
-		}
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#digest(byte[], int, int)
-	 */
-	public void test_digest$BII() {
-		for (int i = 0; i < digestAlgs.length; i++) {
-			try {
-				MessageDigest digest = MessageDigest.getInstance(digestAlgs[i],
-						providerName);
-				assertNotNull(digest);
-				int len = digest.getDigestLength();
-				byte[] digestBytes = new byte[len];
-				digest.digest(digestBytes, 0, digestBytes.length);
-			} catch (NoSuchAlgorithmException e) {
-				fail("getInstance did not find algorithm " + digestAlgs[i]);
-			} catch (NoSuchProviderException e) {
-				fail("getInstance did not find provider " + providerName);
-			} catch (DigestException e) {
-				fail("digest caused exception for algorithm " + digestAlgs[i]
-						+ " : " + e);
-			}
-		}
-        try {                
-            MessageDigest.getInstance("SHA").digest(new byte[] {}, Integer.MAX_VALUE, 755);                                            
-        } catch (NoSuchAlgorithmException e) {
-        	//allowed
-        } catch (DigestException e) {
-        	//allowed
-        } catch (IllegalArgumentException e) {
-        	//expected
-        }
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#update(byte[], int, int)
-	 */
-	public void test_update$BII() {
-        try {                
-        	MessageDigest.getInstance("SHA").update(new byte[] {},Integer.MAX_VALUE,Integer.MAX_VALUE);
-		} catch (NoSuchAlgorithmException e) {
-        	//allowed
-        } catch (IllegalArgumentException e) {
-        	//expected
-        }
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#getAlgorithm()
-	 */
-	public void test_getAlgorithm() {
-		for (int i = 0; i < digestAlgs.length; i++) {
-			try {
-				String alg = MessageDigest.getInstance(digestAlgs[i],
-						providerName).getAlgorithm();
-				assertTrue("getAlgorithm ok", alg.equals(digestAlgs[i]));
-			} catch (NoSuchAlgorithmException e) {
-				fail("getInstance did not find algorithm " + digestAlgs[i]);
-			} catch (NoSuchProviderException e) {
-				fail("getInstance did not find provider " + providerName);
-			}
-		}
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#getDigestLength()
-	 */
-	public void test_getDigestLength() {
-		for (int i = 0; i < digestAlgs.length; i++) {
-			try {
-				int len = MessageDigest
-						.getInstance(digestAlgs[i], providerName)
-						.getDigestLength();
-				assertTrue("length not ok", len > 0);
-			} catch (NoSuchAlgorithmException e) {
-				fail("getInstance did not find algorithm " + digestAlgs[i]);
-			} catch (NoSuchProviderException e) {
-				fail("getInstance did not find provider " + providerName);
-			}
-		}// end for
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#getInstance(java.lang.String)
-	 */
-	public void test_getInstanceLjava_lang_String() {
-		for (int i = 0; i < digestAlgs.length; i++) {
-			try {
-				MessageDigest.getInstance(digestAlgs[i]);
-			} catch (NoSuchAlgorithmException e) {
-				fail("getInstance did not find algorithm " + digestAlgs[i]);
-			}
-		}
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#getInstance(java.lang.String,
-	 *        java.lang.String)
-	 */
-	public void test_getInstanceLjava_lang_StringLjava_lang_String() {
-		for (int i = 0; i < digestAlgs.length; i++) {
-			try {
-				MessageDigest.getInstance(digestAlgs[i], providerName);
-			} catch (NoSuchAlgorithmException e) {
-				fail("getInstance did not find algorithm " + digestAlgs[i]);
-			} catch (NoSuchProviderException e) {
-				fail("getInstance did not find provider " + providerName);
-			}
-		}
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#getProvider()
-	 */
-	public void test_getProvider() {
-		for (int i = 0; i < digestAlgs.length; i++) {
-			try {
-				Provider p = MessageDigest.getInstance(digestAlgs[i],
-						providerName).getProvider();
-				assertNotNull("provider is null", p);
-			} catch (NoSuchAlgorithmException e) {
-				fail("getInstance did not find algorithm " + digestAlgs[i]);
-			} catch (NoSuchProviderException e) {
-				fail("getInstance did not find provider " + providerName);
-			}
-		}
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#isEqual(byte[], byte[])
-	 */
-	public void test_isEqual$B$B() {
-		assertTrue("isEqual is not correct", MessageDigest.isEqual(AR1, AR2));
-	}
-
-	/**
-	 * @tests java.security.MessageDigest#toString()
-	 */
-	public void test_toString() {
-		try {
-			String str = MessageDigest.getInstance("SHA").toString();
-			assertNotNull("toString is null", str);
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
-		}
-	}
-
-	protected void setUp() {
-		if (digestAlgs == null) {
-			Provider[] providers = Security.getProviders("MessageDigest.SHA");
-			if (providers == null) {
-				fail("No providers available for test");
-			}
-
-			// Arbitrarily select the first available provider
-			providerName = providers[0].getName();
-			digestAlgs = getDigestAlgorithms(providerName);
-			if (digestAlgs == null || digestAlgs.length == 0) {
-				fail("No digest algorithms were found");
-			}
-		}
-	}
-
-	/*
-	 * Returns the digest algorithms that the given provider supports.
-	 */
-	private String[] getDigestAlgorithms(String providerName) {
-		Vector algs = new Vector();
-
-		Provider provider = Security.getProvider(providerName);
-		if (provider == null)
-			return new String[0];
-		Enumeration e = provider.keys();
-		while (e.hasMoreElements()) {
-			String algorithm = (String) e.nextElement();
-			if (algorithm.startsWith(MESSAGEDIGEST_ID) && !algorithm.contains(" ")) {
-				algs.addElement(algorithm.substring(MESSAGEDIGEST_ID.length()));
-			}
-		}// end while
-
-		return (String[]) algs.toArray(new String[algs.size()]);
-	}
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.security.DigestException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.Security;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Vector;
+
+public class MessageDigest2Test extends junit.framework.TestCase {
+
+	private static final String MESSAGEDIGEST_ID = "MessageDigest.";
+
+	private String[] digestAlgs = null;
+
+	private String providerName = null;
+
+	private static final byte[] AR1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+
+	private static final byte[] AR2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+
+	private static final String MESSAGE = "abc";
+
+	private static final byte[] MESSAGE_DIGEST = { -87, -103, 62, 54, 71, 6,
+			-127, 106, -70, 62, 37, 113, 120, 80, -62, 108, -100, -48, -40,
+			-99, };
+
+	private static final byte[] MESSAGE_DIGEST_63_As = { 3, -16, -97, 91, 21,
+			-118, 122, -116, -38, -39, 32, -67, -36, 41, -72, 28, 24, -91, 81,
+			-11, };
+
+	private static final byte[] MESSAGE_DIGEST_64_As = { 0, -104, -70, -126,
+			75, 92, 22, 66, 123, -41, -95, 18, 42, 90, 68, 42, 37, -20, 100,
+			77, };
+
+	private static final byte[] MESSAGE_DIGEST_65_As = { 17, 101, 83, 38, -57,
+			8, -41, 3, 25, -66, 38, 16, -24, -91, 125, -102, 91, -107, -99, 59, };
+
+	/**
+	 * @tests java.security.MessageDigest#clone()
+	 */
+	public void test_clone() {
+		for (int i = 0; i < digestAlgs.length; i++) {
+			try {
+				MessageDigest d1 = MessageDigest.getInstance(digestAlgs[i],
+						providerName);
+				for (byte b = 0; b < 84; b++) {
+					d1.update(b);
+				}
+
+				MessageDigest d2 = (MessageDigest) d1.clone();
+				d1.update((byte) 1);
+				d2.update((byte) 1);
+
+				assertTrue("cloned hash differs from original for algorithm "
+						+ digestAlgs[i], MessageDigest.isEqual(d1.digest(), d2
+						.digest()));
+			} catch (CloneNotSupportedException e) {
+				// Expected - a Signature may not be cloneable
+			} catch (NoSuchAlgorithmException e) {
+				fail("getInstance did not find algorithm " + digestAlgs[i]);
+			} catch (NoSuchProviderException e) {
+				fail("getInstance did not find provider " + providerName);
+			}
+		}
+	}
+
+	private static final byte[] SHA_DATA_2 = { 70, -54, 124, 120, -29, 57, 56,
+			119, -108, -54, -97, -76, -97, -50, -63, -73, 2, 85, -53, -79, };
+
+	private void testSerializationSHA_DATA_2(MessageDigest sha) {
+		try {
+			sha.reset();
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			DataOutputStream output = new DataOutputStream(out);
+			// -----------------------------------------------------------------------
+
+			// Made up data
+			output
+					.writeUTF("tests.api.java.security.MessageDigestTest$InitializerFieldsTest3");
+			output.writeInt(0); // class modifiers
+			output.writeUTF("java.io.Serializable"); // interfaces
+
+			// Fields
+			output.writeUTF("sub_toBeNotSerialized"); // name
+			output.writeInt(9); // modifiers
+			output.writeUTF("Ljava/lang/String;"); // signature
+
+			output.writeUTF("sub_toBeNotSerialized2"); // name
+			output.writeInt(9); // modifiers
+			output.writeUTF("Ljava/lang/String;"); // signature
+
+			output.writeUTF("sub_toBeSerialized"); // name
+			output.writeInt(1); // modifiers
+			output.writeUTF("Ljava/lang/String;"); // signature
+
+			output.writeUTF("sub_toBeSerialized3"); // name
+			output.writeInt(1); // modifiers
+			output.writeUTF("Ljava/lang/String;"); // signature
+
+			output.writeUTF("sub_toBeSerialized4"); // name
+			output.writeInt(1); // modifiers
+			output.writeUTF("Ljava/lang/String;"); // signature
+
+			output.writeUTF("sub_toBeSerialized5"); // name
+			output.writeInt(1); // modifiers
+			output.writeUTF("Ljava/lang/String;"); // signature
+
+			// clinit
+			output.writeUTF("<clinit>"); // name
+			output.writeInt(8); // modifiers
+			output.writeUTF("()V"); // signature
+
+			// constructors
+			output.writeUTF("<init>"); // name
+			output.writeInt(0); // modifiers
+			output.writeUTF("()V"); // signature
+
+			// methods
+			output.writeUTF("equals"); // name
+			output.writeInt(1); // modifiers
+			output.writeUTF("(Ljava.lang.Object;)Z"); // signature
+
+			// -----------------------------------------------------------------------
+
+			output.flush();
+
+			byte[] data = out.toByteArray();
+			byte[] hash = sha.digest(data);
+			assertTrue("SHA_DATA_2 NOT ok", Arrays.equals(hash, SHA_DATA_2));
+		} catch (IOException e) {
+			fail("SHA_DATA_2 NOT ok");
+		}
+	}
+
+	private static final byte[] SHA_DATA_1 = { 90, 36, 111, 106, -32, 38, 4,
+			126, 21, -51, 107, 45, -64, -68, -109, 112, -31, -46, 34, 115, };
+
+	private void testSerializationSHA_DATA_1(MessageDigest sha) {
+		try {
+			sha.reset();
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			DataOutputStream output = new DataOutputStream(out);
+			// -----------------------------------------------------------------------
+
+			// Made up data
+			output
+					.writeUTF("tests.api.java.security.MessageDigestTest$OptionalDataNotRead");
+			// name
+			output.writeInt(0); // class modifiers
+			output.writeUTF("java.io.Serializable"); // interfaces
+
+			// Fields
+			output.writeUTF("class$0"); // name
+			output.writeInt(8); // modifiers
+			output.writeUTF("Ljava/lang/Class;"); // signature
+
+			output.writeUTF("field1"); // name
+			output.writeInt(2); // modifiers
+			output.writeUTF("I"); // signature
+
+			output.writeUTF("field2"); // name
+			output.writeInt(2); // modifiers
+			output.writeUTF("I"); // signature
+
+			// clinit
+			output.writeUTF("<clinit>"); // name
+			output.writeInt(8); // modifiers
+			output.writeUTF("()V"); // signature
+
+			// constructors
+			output.writeUTF("<init>"); // name
+			output.writeInt(1); // modifiers
+			output.writeUTF("()V"); // signature
+			// -----------------------------------------------------------------------
+
+			output.flush();
+			byte[] data = out.toByteArray();
+			byte[] hash = sha.digest(data);
+			assertTrue("SHA_DATA_1 NOT ok", Arrays.equals(hash, SHA_DATA_1));
+		} catch (IOException e) {
+			fail("SHA_DATA_1 NOT ok");
+		}
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#digest()
+	 */
+	public void test_digest() {
+		MessageDigest sha = null;
+		try {
+			sha = MessageDigest.getInstance("SHA");
+			assertNotNull(sha);
+		} catch (NoSuchAlgorithmException e) {
+			fail("getInstance did not find algorithm");
+		}
+		sha.update(MESSAGE.getBytes());
+		byte[] digest = sha.digest();
+		assertTrue("bug in SHA", MessageDigest.isEqual(digest, MESSAGE_DIGEST));
+
+		sha.reset();
+		for (int i = 0; i < 63; i++) {
+			// just under buffer capacity
+			sha.update((byte) 'a');
+		}
+		digest = sha.digest();
+		assertTrue("bug in SHA", MessageDigest.isEqual(digest,
+				MESSAGE_DIGEST_63_As));
+
+		sha.reset();
+		for (int i = 0; i < 64; i++) {
+			// exact SHA buffer capacity
+			sha.update((byte) 'a');
+		}
+		digest = sha.digest();
+		assertTrue("bug in SHA", MessageDigest.isEqual(digest,
+				MESSAGE_DIGEST_64_As));
+
+		sha.reset();
+		for (int i = 0; i < 65; i++) {
+			// just above SHA buffer capacity
+			sha.update((byte) 'a');
+		}
+		digest = sha.digest();
+		assertTrue("bug in SHA", MessageDigest.isEqual(digest,
+				MESSAGE_DIGEST_65_As));
+
+		testSerializationSHA_DATA_1(sha);
+		testSerializationSHA_DATA_2(sha);
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#digest(byte[])
+	 */
+	public void test_digest$B() {
+		for (int i = 0; i < digestAlgs.length; i++) {
+			try {
+				MessageDigest digest = MessageDigest.getInstance(digestAlgs[i],
+						providerName);
+				assertNotNull(digest);
+				digest.digest(AR1);
+			} catch (NoSuchAlgorithmException e) {
+				fail("getInstance did not find algorithm " + digestAlgs[i]);
+			} catch (NoSuchProviderException e) {
+				fail("getInstance did not find provider " + providerName);
+			}
+		}
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#digest(byte[], int, int)
+	 */
+	public void test_digest$BII() {
+		for (int i = 0; i < digestAlgs.length; i++) {
+			try {
+				MessageDigest digest = MessageDigest.getInstance(digestAlgs[i],
+						providerName);
+				assertNotNull(digest);
+				int len = digest.getDigestLength();
+				byte[] digestBytes = new byte[len];
+				digest.digest(digestBytes, 0, digestBytes.length);
+			} catch (NoSuchAlgorithmException e) {
+				fail("getInstance did not find algorithm " + digestAlgs[i]);
+			} catch (NoSuchProviderException e) {
+				fail("getInstance did not find provider " + providerName);
+			} catch (DigestException e) {
+				fail("digest caused exception for algorithm " + digestAlgs[i]
+						+ " : " + e);
+			}
+		}
+        try {                
+            MessageDigest.getInstance("SHA").digest(new byte[] {}, Integer.MAX_VALUE, 755);                                            
+        } catch (NoSuchAlgorithmException e) {
+        	//allowed
+        } catch (DigestException e) {
+        	//allowed
+        } catch (IllegalArgumentException e) {
+        	//expected
+        }
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#update(byte[], int, int)
+	 */
+	public void test_update$BII() {
+        try {                
+        	MessageDigest.getInstance("SHA").update(new byte[] {},Integer.MAX_VALUE,Integer.MAX_VALUE);
+		} catch (NoSuchAlgorithmException e) {
+        	//allowed
+        } catch (IllegalArgumentException e) {
+        	//expected
+        }
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#getAlgorithm()
+	 */
+	public void test_getAlgorithm() {
+		for (int i = 0; i < digestAlgs.length; i++) {
+			try {
+				String alg = MessageDigest.getInstance(digestAlgs[i],
+						providerName).getAlgorithm();
+				assertTrue("getAlgorithm ok", alg.equals(digestAlgs[i]));
+			} catch (NoSuchAlgorithmException e) {
+				fail("getInstance did not find algorithm " + digestAlgs[i]);
+			} catch (NoSuchProviderException e) {
+				fail("getInstance did not find provider " + providerName);
+			}
+		}
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#getDigestLength()
+	 */
+	public void test_getDigestLength() {
+		for (int i = 0; i < digestAlgs.length; i++) {
+			try {
+				int len = MessageDigest
+						.getInstance(digestAlgs[i], providerName)
+						.getDigestLength();
+				assertTrue("length not ok", len > 0);
+			} catch (NoSuchAlgorithmException e) {
+				fail("getInstance did not find algorithm " + digestAlgs[i]);
+			} catch (NoSuchProviderException e) {
+				fail("getInstance did not find provider " + providerName);
+			}
+		}// end for
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#getInstance(java.lang.String)
+	 */
+	public void test_getInstanceLjava_lang_String() {
+		for (int i = 0; i < digestAlgs.length; i++) {
+			try {
+				MessageDigest.getInstance(digestAlgs[i]);
+			} catch (NoSuchAlgorithmException e) {
+				fail("getInstance did not find algorithm " + digestAlgs[i]);
+			}
+		}
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#getInstance(java.lang.String,
+	 *        java.lang.String)
+	 */
+	public void test_getInstanceLjava_lang_StringLjava_lang_String() {
+		for (int i = 0; i < digestAlgs.length; i++) {
+			try {
+				MessageDigest.getInstance(digestAlgs[i], providerName);
+			} catch (NoSuchAlgorithmException e) {
+				fail("getInstance did not find algorithm " + digestAlgs[i]);
+			} catch (NoSuchProviderException e) {
+				fail("getInstance did not find provider " + providerName);
+			}
+		}
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#getProvider()
+	 */
+	public void test_getProvider() {
+		for (int i = 0; i < digestAlgs.length; i++) {
+			try {
+				Provider p = MessageDigest.getInstance(digestAlgs[i],
+						providerName).getProvider();
+				assertNotNull("provider is null", p);
+			} catch (NoSuchAlgorithmException e) {
+				fail("getInstance did not find algorithm " + digestAlgs[i]);
+			} catch (NoSuchProviderException e) {
+				fail("getInstance did not find provider " + providerName);
+			}
+		}
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#isEqual(byte[], byte[])
+	 */
+	public void test_isEqual$B$B() {
+		assertTrue("isEqual is not correct", MessageDigest.isEqual(AR1, AR2));
+	}
+
+	/**
+	 * @tests java.security.MessageDigest#toString()
+	 */
+	public void test_toString() {
+		try {
+			String str = MessageDigest.getInstance("SHA").toString();
+			assertNotNull("toString is null", str);
+		} catch (NoSuchAlgorithmException e) {
+			fail("getInstance did not find algorithm");
+		}
+	}
+
+	protected void setUp() {
+		if (digestAlgs == null) {
+			Provider[] providers = Security.getProviders("MessageDigest.SHA");
+			if (providers == null) {
+				fail("No providers available for test");
+			}
+
+			// Arbitrarily select the first available provider
+			providerName = providers[0].getName();
+			digestAlgs = getDigestAlgorithms(providerName);
+			if (digestAlgs == null || digestAlgs.length == 0) {
+				fail("No digest algorithms were found");
+			}
+		}
+	}
+
+	/*
+	 * Returns the digest algorithms that the given provider supports.
+	 */
+	private String[] getDigestAlgorithms(String providerName) {
+		Vector algs = new Vector();
+
+		Provider provider = Security.getProvider(providerName);
+		if (provider == null)
+			return new String[0];
+		Enumeration e = provider.keys();
+		while (e.hasMoreElements()) {
+			String algorithm = (String) e.nextElement();
+			if (algorithm.startsWith(MESSAGEDIGEST_ID) && !algorithm.contains(" ")) {
+				algs.addElement(algorithm.substring(MESSAGEDIGEST_ID.length()));
+			}
+		}// end while
+
+		return (String[]) algs.toArray(new String[algs.size()]);
+	}
 }

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/MessageDigest2Test.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message