harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r410788 [12/13] - in /incubator/harmony/enhanced/classlib/trunk/modules: auth/make/common/ auth/src/test/java/common/javax/security/auth/ auth/src/test/java/common/javax/security/auth/callback/serialization/ auth/src/test/java/common/javax/...
Date Thu, 01 Jun 2006 08:15:44 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestCertUtils.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestCertUtils.java?rev=410788&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestCertUtils.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestCertUtils.java Thu Jun  1 01:15:17 2006
@@ -0,0 +1,830 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Alexander V. Astapchuk
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.io.StreamCorruptedException;
+import java.math.BigInteger;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Principal;
+import java.security.Provider;
+import java.security.PublicKey;
+import java.security.Security;
+import java.security.SignatureException;
+
+import java.security.cert.*;
+import java.util.*;
+
+import javax.security.auth.x500.X500Principal;
+
+/**
+ * The class contains various utility methods used during the java.security
+ * classes testing.
+ * 
+ */
+
+public final class TestCertUtils {
+
+    private TestCertUtils() {
+        throw new Error("statics only");
+    }
+
+    /**
+     * Returns new instance of test certificate each time the method is called.
+     * 
+     * @return test ceritifcate
+     */
+    public static Certificate getCert() {
+        return new TestCertificate();
+    }
+
+    /**
+     * Returns an array of 3 test certificates. IMP: The array returned is not
+     * reall chain of certificates, it's just an array of 3 certs. The method
+     * returns new array each time it's called. The number of 3 was chosen
+     * arbitrarily and is subject to change.
+     * 
+     * @return an array of 3 certificates
+     */
+    public static Certificate[] getCertChain() {
+        Certificate[] chain = { new TestCertificate(), new TestCertificate(),
+                new TestCertificate() };
+        return chain;
+    }
+
+    /**
+     * Returns a test CertPath, which uses getCertChain() to obtain a list of
+     * certificates to store.
+     * 
+     * @return test cert path
+     */
+    public static CertPath getCertPath() {
+        return new TestCertPath();
+    }
+
+    /**
+     * Generates and returns an instance of TestCertPath.<br>
+     * TestCertificate-s included in the CertPath will be uniq (will have 
+     * diffrent numbers passed to their ctor-s).<br> 
+     * The second arguments shows which number will have the first Certificate
+     * in the CertPath. The second sertificate will have (startID+1) nubmber 
+     * and so on.
+     * 
+     * @param howMany - shows how many TestCerts must contain the CertPath generated
+     * @param startID - specifies the starting ID which the first certificate will have  
+     * @return TestCertPath
+     */
+    public static CertPath genCertPath(int howMany, int startID) {
+        Certificate[] certs = new Certificate[howMany];
+        for (int i = 0; i < howMany; i++) {
+            certs[i] = new TestCertificate(Integer.toString(startID + i));
+        }
+        return new TestCertPath(certs);
+    }
+
+    private static Provider provider = null;
+
+    private static final String providerName = "TstPrvdr";
+
+    /**
+     * A Principal used to form rootCA's certificate
+     */
+    public static final X500Principal rootPrincipal = new X500Principal(
+            UniGen.rootName);
+
+    /**
+     * Some fake rootCA's certificate.
+     */
+    public static final X509Certificate rootCA = new TestX509Certificate(
+            rootPrincipal, rootPrincipal);
+
+    public static void install_test_x509_factory() {
+        if (provider == null) {
+            provider = new TestProvider(providerName, 0.01,
+                    "Test provider for serialization testing");
+            Security.insertProviderAt(provider, 1);
+        }
+    }
+
+    public static void uninstall_test_x509_factory() {
+        if (provider != null) {
+            Security.removeProvider(providerName);
+            provider = null;
+        }
+    }
+
+    /**
+     * The class represents test certificate path.
+     * 
+     */
+
+    public static final class TestCertPath extends CertPath implements
+            Serializable {
+
+        private static final byte[] encoded = new byte[] { 1, 2, 3, 4, 5, 6, 7,
+                8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
+
+        private static final String serializedData = "Just a dummy string to be serialized instead of real data";
+
+        private Certificate[] certs;
+
+        /**
+         * Default ctor for TestCertPath. Uses {@link TestCertUtils#getCertChain()} 
+         * to obtain list of certificates.<br>
+         * All TestCertPath-s constructed via this ctor will be equals() to each 
+         * other.
+         */
+        public TestCertPath() {
+            super("testCertPath");
+            certs = getCertChain();
+        }
+
+        /**
+         * Constructs TestCertPath and keeps the given array of certificates.<br> 
+         * The TestCertPaths constructed via this ctor may be different (if they 
+         * have different set of certificates)<br>
+         * @see TestCertUtils#genCertPath(int, int)
+         * @param certs
+         */
+        public TestCertPath(Certificate[] certs) {
+            super("testCertPath");
+            this.certs = certs;
+        }
+
+        /** 
+         * @see java.security.cert.CertPath#getCertificates()
+         */
+        public List getCertificates() {
+            return Arrays.asList(certs);
+        }
+
+        /** 
+         * @see java.security.cert.CertPath#getEncoded()
+         */
+        public byte[] getEncoded() throws CertificateEncodingException {
+            return encoded.clone();
+        }
+
+        /**
+         * @see java.security.cert.CertPath#getEncoded(java.lang.String)
+         */
+        public byte[] getEncoded(String encoding)
+                throws CertificateEncodingException {
+            return encoded.clone();
+        }
+
+        /**
+         * @see java.security.cert.CertPath#getEncodings()
+         */
+        public Iterator getEncodings() {
+            Vector v = new Vector();
+            v.add("myTestEncoding");
+            return v.iterator();
+        }
+        
+        public String toString() {
+            StringBuffer buf = new StringBuffer(200);
+            buf.append("TestCertPath. certs count=");
+            if( certs == null ) {
+                buf.append("0\n");
+            }
+            else {
+                buf.append(certs.length).append("\n");
+                for( int i=0; i<certs.length; i++) {
+                    buf.append("\t").append(i).append(" ");
+                    buf.append(certs[i]).append("\n");
+                }
+            }
+            return buf.toString();
+        }
+
+        /**
+         * Writes<br>
+         * (String) serializedData<br>
+         * (int) number of certificates in this CertPath<br>
+         * <array of certificates>
+         * 
+         * @param out
+         * @throws IOException
+         */
+        private void writeObject(ObjectOutputStream out) throws IOException {
+            out.writeUTF(serializedData);
+            if (certs == null) {
+                out.writeInt(0);
+            } else {
+                out.writeInt(certs.length);
+                for (int i = 0; i < certs.length; i++) {
+                    out.writeObject(certs[i]);
+                }
+            }
+        }
+
+        private void readObject(ObjectInputStream in) throws IOException,
+                ClassNotFoundException {
+            String s = in.readUTF();
+            if (!serializedData.equals(s)) {
+                throw new StreamCorruptedException("expect [" + serializedData
+                        + "] got [" + s + "]");
+            }
+            int count = in.readInt();
+            certs = new Certificate[count];
+            for (int i = 0; i < count; i++) {
+                certs[i] = (Certificate) in.readObject();
+            }
+        }
+
+        protected Object writeReplace() {
+            return this;
+        }
+
+        protected Object readResolve() {
+            return this;
+        }
+    }
+
+    /**
+     * The class represents empty PublicKey.
+     * 
+     */
+
+    public static final class TestPublicKey implements PublicKey {
+        private static final String algo = "testPublicKeyAlgorithm";
+
+        private static final byte[] encoded = new byte[] { 1, 2, 3, 4, 5, 6, 7,
+                8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
+
+        private static final String format = "testPublicKeyFormat";
+
+        public String getAlgorithm() {
+            return algo;
+        }
+
+        public byte[] getEncoded() {
+            return encoded.clone();
+        }
+
+        public String getFormat() {
+            return format;
+        }
+    }
+
+    /**
+     * The class represents test certificate.
+     * 
+     */
+
+    public static class TestCertificate extends Certificate implements
+            Serializable {
+
+        private static final byte[] encoded = new byte[] { 1, 2, 3, 4, 5, 6, 7,
+                8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
+
+        public static final String TYPE = "Test";
+
+        // 
+        // A String that makes different TestCertificates to be different.
+        //
+        private String diff = null;
+
+        /**
+         * Default ctor. All the TestCertificate-s created with this ctor are equals() to each other.
+         * Use TestCertificate(String) if you need non equal TestCertificate-s.
+         */
+        public TestCertificate() {
+            super(TYPE);
+        }
+
+        /**
+         * A special purpose ctor. Pass different String-s to hava different TestCertificates.
+         * TestCertificate-s with the same String passed to this ctor are considered equal. 
+         */
+        public TestCertificate(String diff) {
+            super(TYPE);
+            this.diff = diff;
+        }
+
+        /**
+         * A ctor that allows to specify both the TYPE of certificate and the 
+         * diff. Leave the <code>diff</code> null when no difference needed. 
+         * 
+         * @param diff
+         * @param type
+         */
+        public TestCertificate(String diff, String type) {
+            super(type);
+            this.diff = diff;
+        }
+
+        public byte[] getEncoded() throws CertificateEncodingException {
+            return encoded.clone();
+        }
+
+        public void verify(PublicKey key) throws CertificateException,
+                NoSuchAlgorithmException, InvalidKeyException,
+                NoSuchProviderException, SignatureException {
+            // do nothing
+        }
+
+        public void verify(PublicKey key, String sigProvider)
+                throws CertificateException, NoSuchAlgorithmException,
+                InvalidKeyException, NoSuchProviderException,
+                SignatureException {
+            // do nothing
+
+        }
+
+        public String toString() {
+            return "Test certificate - for unit testing only";
+        }
+
+        public boolean equals(Object obj) {
+            if (obj == null || !(obj instanceof TestCertificate)) {
+                return false;
+            }
+            TestCertificate that = (TestCertificate) obj;
+            if (this == that) {
+                return true;
+            }
+            if (this.diff == null) {
+                return that.diff == null;
+            }
+            return this.diff.equals(that.diff);
+        }
+
+        public PublicKey getPublicKey() {
+            return new TestPublicKey();
+        }
+
+        /**
+         * Writes:<br>
+         * boolean - true if this certificate has a diff string, 
+         * false otherwise, followed by <br>
+         * writeUTF() of string (if presented)  
+         *
+         * @param out
+         * @throws IOException
+         */
+        private void writeObject(ObjectOutputStream out) throws IOException {
+            if (diff == null) {
+                out.writeBoolean(false);
+            } else {
+                out.writeBoolean(false);
+                out.writeUTF(diff);
+            }
+        }
+
+        private void readObject(ObjectInputStream in) throws IOException,
+                ClassNotFoundException {
+            boolean hasDiffString = in.readBoolean();
+            if (hasDiffString) {
+                diff = in.readUTF();
+            }
+        }
+
+        protected Object writeReplace() {
+            return this;
+        }
+
+        protected Object readResolve() {
+            return this;
+        }
+    }
+
+    public static class TestInvalidX509Certificate extends TestX509Certificate {
+        public TestInvalidX509Certificate(X500Principal subj,
+                X500Principal issuer) {
+            super(subj, issuer);
+        }
+    }
+
+    /**
+     * 
+     * TestX509CErtificate.<br>
+     * Does nothing interesting, but<br> 
+     * a) is not abstract, so it can be instantiated<br>
+     * b) returns Encoded form<br>
+     * 
+     */
+    public static class TestX509Certificate extends X509Certificate {
+        private X500Principal subject;
+
+        private X500Principal issuer;
+
+        public TestX509Certificate(X500Principal subj, X500Principal issuer) {
+            this.subject = subj;
+            this.issuer = issuer;
+        }
+
+        public X500Principal getIssuerX500Principal() {
+            return issuer;
+        }
+
+        public X500Principal getSubjectX500Principal() {
+            return subject;
+        }
+
+        /**
+         * The encoded for of this X509Certificate is a byte array where
+         * first are bytes of encoded form of Subject (as X500Principal), 
+         * followed by one zero byte
+         * and followed by the encoded form of Issuer (as X500Principal)
+         * 
+         */
+        public byte[] getEncoded() throws CertificateEncodingException {
+            byte[] asubj = subject.getEncoded();
+            byte[] aissuer = issuer.getEncoded();
+            byte[] data = new byte[asubj.length + aissuer.length + 1];
+
+            System.arraycopy(asubj, 0, data, 0, asubj.length);
+            //data[asubj.length] = 0;
+            System
+                    .arraycopy(aissuer, 0, data, asubj.length + 1,
+                            aissuer.length);
+            return data;
+        }
+
+        public void checkValidity() throws CertificateExpiredException,
+                CertificateNotYetValidException {
+        }
+
+        public void checkValidity(Date date)
+                throws CertificateExpiredException,
+                CertificateNotYetValidException {
+        }
+
+        public int getBasicConstraints() {
+            return 0;
+        }
+
+        public Principal getIssuerDN() {
+            return null;
+        }
+
+        public boolean[] getIssuerUniqueID() {
+            return null;
+        }
+
+        public boolean[] getKeyUsage() {
+            return null;
+        }
+
+        public Date getNotAfter() {
+            return null;
+        }
+
+        public Date getNotBefore() {
+            return null;
+        }
+
+        public BigInteger getSerialNumber() {
+            return null;
+        }
+
+        public String getSigAlgName() {
+            return null;
+        }
+
+        public String getSigAlgOID() {
+            return null;
+        }
+
+        public byte[] getSigAlgParams() {
+            return null;
+        }
+
+        public byte[] getSignature() {
+            return null;
+        }
+
+        public Principal getSubjectDN() {
+            return null;
+        }
+
+        public boolean[] getSubjectUniqueID() {
+            return null;
+        }
+
+        public byte[] getTBSCertificate() throws CertificateEncodingException {
+            return null;
+        }
+
+        public int getVersion() {
+            return 0;
+        }
+
+        public Set getCriticalExtensionOIDs() {
+            return null;
+        }
+
+        public byte[] getExtensionValue(String oid) {
+            return null;
+        }
+
+        public Set getNonCriticalExtensionOIDs() {
+            return null;
+        }
+
+        public boolean hasUnsupportedCriticalExtension() {
+            return false;
+        }
+
+        public PublicKey getPublicKey() {
+            return null;
+        }
+
+        public String toString() {
+            return null;
+        }
+
+        public void verify(PublicKey key, String sigProvider)
+                throws CertificateException, NoSuchAlgorithmException,
+                InvalidKeyException, NoSuchProviderException,
+                SignatureException {
+
+        }
+
+        public void verify(PublicKey key) throws CertificateException,
+                NoSuchAlgorithmException, InvalidKeyException,
+                NoSuchProviderException, SignatureException {
+
+        }
+    }
+
+    /**
+     * TestProvider. Does nothing, but pretends to 
+     * implement X.509 CertificateFactory.
+     */
+    public static class TestProvider extends Provider {
+
+        private Provider.Service serv;
+
+        public TestProvider(String name, double version, String info) {
+            super(name, version, info);
+            serv = new Provider.Service(this, "CertificateFactory", "X.509",
+                    TestFactorySpi.class.getName(), new ArrayList(), null);
+        }
+
+        public synchronized Set getServices() {
+            HashSet s = new HashSet();
+            s.add(serv);
+            return s;
+        }
+    }
+
+    /**
+     * Some kind of Certificate Factory, used during unit testing.
+     * 
+     * 
+     */
+    public static class TestFactorySpi extends CertificateFactorySpi {
+
+        /**
+         * Tries to create an instance of TestX509Certificate, basing 
+         * on the presumption that its {@link TestX509Certificate#getEncoded() 
+         * encoded} form is stored.<br>
+         * @throws CertificateException is the presumtion is not met or if 
+         * any IO problem occurs.
+         */
+        public Certificate engineGenerateCertificate(InputStream is)
+                throws CertificateException {
+            byte[] data = new byte[0];
+            byte[] chunk = new byte[1024];
+            int len;
+            try {
+                while ((len = is.read(chunk)) > 0) {
+                    byte[] tmp = new byte[data.length + len];
+                    System.arraycopy(data, 0, tmp, 0, data.length);
+                    System.arraycopy(chunk, 0, tmp, data.length, len);
+                    data = tmp;
+                }
+            } catch (IOException ex) {
+                throw new CertificateException("IO problem", ex);
+            }
+            int pos = Arrays.binarySearch(data, (byte) 0);
+            if (pos < 0) {
+                throw new CertificateException("invalid format");
+            }
+            byte[] subjNameData = new byte[pos];
+            System.arraycopy(data, 0, subjNameData, 0, subjNameData.length);
+            byte[] issNameData = new byte[data.length - pos - 1];
+            System.arraycopy(data, pos + 1, issNameData, 0, issNameData.length);
+            X500Principal subjName = new X500Principal(subjNameData);
+            X500Principal issName = new X500Principal(issNameData);
+            return new TestX509Certificate(subjName, issName);
+        }
+
+        /**
+         * Not supported yet.
+         * @throws UnsupportedOperationException
+         */
+        public Collection engineGenerateCertificates(InputStream inStream)
+                throws CertificateException {
+            throw new UnsupportedOperationException("not yet.");
+        }
+
+        /**
+         * Not supported yet.
+         * @throws UnsupportedOperationException
+         */
+        public CRL engineGenerateCRL(InputStream inStream) throws CRLException {
+            throw new UnsupportedOperationException("not yet.");
+        }
+
+        /**
+         * Not supported yet.
+         * @throws UnsupportedOperationException
+         */
+        public Collection engineGenerateCRLs(InputStream inStream)
+                throws CRLException {
+            throw new UnsupportedOperationException("not yet.");
+        }
+
+        /**
+         * Returns an instance of TestCertPath.<br>
+         * @throws CertificateException if 
+         * a) any of Certificates passed is not an instance of X509Certificate
+         * b) any of Certificates passed is an instance of TestInvalidX509Certificate
+         */
+        public CertPath engineGenerateCertPath(List certs)
+                throws CertificateException {
+            ArrayList validCerts = new ArrayList();
+            for (Iterator i = certs.iterator(); i.hasNext();) {
+                Certificate c = (Certificate) i.next();
+                if (!(c instanceof X509Certificate)) {
+                    throw new CertificateException("Not X509: " + c);
+                }
+                if (c instanceof TestInvalidX509Certificate) {
+                    throw new CertificateException("Invalid (test) X509: " + c);
+                }
+                validCerts.add(c);
+            }
+            Certificate[] acerts = new Certificate[validCerts.size()];
+            validCerts.toArray(acerts);
+            return new TestCertPath(acerts);
+        }
+    }
+
+    /**
+     * Utility class used to generate some amount of uniq names.
+     */
+    public static class UniGen {
+        public static final String rootName = "CN=Alex Astapchuk, OU=SSG, O=Intel ZAO, C=RU";
+
+        private static final String datasNames[] = { "CN", "OU", "O", "C" };
+
+        private static final String datas[][] = {
+        // Names database
+                { "Alex Astapchuk", null, null, null },
+                { "John Doe", null, null, null },
+                // 'organisation unit'-s
+                { null, "SSG", null, null }, { null, "SSG/DRL", null, null },
+                // organisations
+                { null, null, "Intel ZAO", null },
+                { null, null, "Intel Inc", null },
+                // countries
+                { null, null, null, "RU" }, { null, null, null, "US" },
+                { null, null, null, "GB" }, { null, null, null, "JA" },
+                { null, null, null, "KO" }, { null, null, null, "TW" }, };
+
+        //
+        // Returns a string from <code>data</code> from a given column and 
+        // position. The positions are looked for first non-null entry. If there
+        // are no non empty items left, then it scans column starting from the 
+        // beginning.
+        //  
+        // @param col
+        // @param startRow
+        // @return
+        //
+        private static String getData(int col, int startRow) {
+            startRow = startRow % datas.length;
+            for (int i = startRow; i < datas.length; i++) {
+                if (datas[i][col] != null) {
+                    return datas[i][col];
+                }
+            }
+            // no non-null entries left, check from the beginning 
+            for (int i = 0; i < datas.length; i++) {
+                if (datas[i][col] != null) {
+                    return datas[i][col];
+                }
+            }
+            // can't be
+            throw new Error();
+        }
+
+        //
+        // Increments a num.<br>
+        // <code>num</code> is interpreted as a number with a base of 
+        // <code>base</code> and each digit of this number is stored as a  
+        // separate num's element.
+        // 
+        // @param num
+        // @param base
+        // @return <b>true</b> if overflow happened 
+        //
+        private static boolean inc(int[] num, int base) {
+            for (int i = 0; i < num.length; i++) {
+                if ((++num[i]) >= base) {
+                    num[i] = 0;
+                } else {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        /**
+         * Generates some amount of uniq names, none of which is equals to 
+         * {@link #rootName}.
+         * @param howMany
+         * @return
+         */
+        public static String[] genNames(int howMany) {
+            int counts[] = new int[datasNames.length];
+            ArrayList al = new ArrayList();
+
+            // not really the thrifty algorithm... 
+            for (int i = 0; i < howMany;) {
+
+                //                System.out.print("#"+i+": ");
+                //                for( int j=0; j<counts.length; j++) {
+                //                    System.out.print(""+counts[j]+"|");
+                //                }
+                //                System.out.println();
+
+                StringBuffer buf = new StringBuffer();
+                int j = 0;
+                for (; j < datasNames.length - 1; j++) {
+                    String name = datasNames[j];
+                    String val = getData(j, counts[j]);
+                    buf.append(name).append('=').append(val).append(",");
+                }
+                String name = datasNames[j];
+                String val = getData(j, counts[j]);
+                buf.append(name).append('=').append(val);
+
+                name = buf.toString();
+
+                if (!(rootName.equals(name) || al.contains(name))) {
+                    ++i;
+                    al.add(name);
+                    //                    System.out.println("generated: "+name);
+                } else {
+                    //                    System.out.println("rejected: "+name);
+                }
+
+                if (inc(counts, datas.length)) {
+                    // if this happened, then just add some data into 'datas'
+                    throw new Error(
+                            "cant generate so many uniq names. sorry. add some more data.");
+                }
+            }
+            return (String[]) al.toArray(new String[al.size()]);
+        }
+
+        /**
+         * Generates some amount of uniq X500Principals, none of which is equals 
+         * has a string equals to {@link #rootName}.
+         * @param howMany
+         * @return
+         */
+        public static X500Principal[] genX500s(int howMany) {
+            String names[] = genNames(howMany);
+            X500Principal[] ps = new X500Principal[howMany];
+            for (int i = 0; i < howMany; i++) {
+                ps[i] = new X500Principal(names[i]);
+            }
+            return ps;
+        }
+
+    }
+
+}
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestKeyPair.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestKeyPair.java?rev=410788&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestKeyPair.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestKeyPair.java Thu Jun  1 01:15:17 2006
@@ -0,0 +1,601 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.X509EncodedKeySpec;
+import java.util.HashMap;
+
+/**
+ * Generates key pairs based on their encodings for some algorithms.
+ * Encodings generated using
+ * BEA JRockit j2sdk1.4.2_04 (http://www.bea.com)
+ */
+public class TestKeyPair {
+    private static final HashMap privateKeyEncoding = new HashMap();
+    private static final HashMap publicKeyEncoding = new HashMap();
+    private final String algorithmName;
+    private final KeyFactory kf;
+    static {
+        privateKeyEncoding.put("RSA", new byte[] {
+                (byte)0x30, (byte)0x82, (byte)0x02, (byte)0x77, 
+                (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x30, 
+                (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, 
+                (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, 
+                (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, 
+                (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x82, 
+                (byte)0x02, (byte)0x61, (byte)0x30, (byte)0x82, 
+                (byte)0x02, (byte)0x5d, (byte)0x02, (byte)0x01, 
+                (byte)0x00, (byte)0x02, (byte)0x81, (byte)0x81, 
+                (byte)0x00, (byte)0xb2, (byte)0x4a, (byte)0x9b, 
+                (byte)0x5b, (byte)0xba, (byte)0x01, (byte)0xc0, 
+                (byte)0xcd, (byte)0x65, (byte)0x09, (byte)0x63, 
+                (byte)0x70, (byte)0x0b, (byte)0x5a, (byte)0x1b, 
+                (byte)0x92, (byte)0x08, (byte)0xf8, (byte)0x55, 
+                (byte)0x5e, (byte)0x7c, (byte)0x1b, (byte)0x50, 
+                (byte)0x17, (byte)0xec, (byte)0x44, (byte)0x4c, 
+                (byte)0x58, (byte)0x42, (byte)0x2b, (byte)0x41, 
+                (byte)0x09, (byte)0x59, (byte)0xf2, (byte)0xe1, 
+                (byte)0x5d, (byte)0x43, (byte)0x71, (byte)0x4d, 
+                (byte)0x92, (byte)0x03, (byte)0x1d, (byte)0xb6, 
+                (byte)0x6c, (byte)0x7f, (byte)0x5d, (byte)0x48, 
+                (byte)0xcd, (byte)0x17, (byte)0xec, (byte)0xd7, 
+                (byte)0x4c, (byte)0x39, (byte)0xb1, (byte)0x7b, 
+                (byte)0xe2, (byte)0xbf, (byte)0x96, (byte)0x77, 
+                (byte)0xbe, (byte)0xd0, (byte)0xa0, (byte)0xf0, 
+                (byte)0x2d, (byte)0x6b, (byte)0x24, (byte)0xaa, 
+                (byte)0x14, (byte)0xba, (byte)0x82, (byte)0x79, 
+                (byte)0x10, (byte)0x9b, (byte)0x16, (byte)0x68, 
+                (byte)0x47, (byte)0x81, (byte)0x54, (byte)0xa2, 
+                (byte)0xfa, (byte)0x91, (byte)0x9e, (byte)0x0a, 
+                (byte)0x2a, (byte)0x53, (byte)0xa6, (byte)0xe7, 
+                (byte)0x9e, (byte)0x7d, (byte)0x29, (byte)0x33, 
+                (byte)0xd8, (byte)0x05, (byte)0xfc, (byte)0x02, 
+                (byte)0x3f, (byte)0xbd, (byte)0xc7, (byte)0x6e, 
+                (byte)0xed, (byte)0xaa, (byte)0x30, (byte)0x6c, 
+                (byte)0x5f, (byte)0x52, (byte)0xed, (byte)0x35, 
+                (byte)0x65, (byte)0x4b, (byte)0x0e, (byte)0xc8, 
+                (byte)0xa7, (byte)0x12, (byte)0x10, (byte)0x56, 
+                (byte)0x37, (byte)0xaf, (byte)0x11, (byte)0xfa, 
+                (byte)0x21, (byte)0x0e, (byte)0x99, (byte)0xff, 
+                (byte)0xfa, (byte)0x8c, (byte)0x65, (byte)0x8e, 
+                (byte)0x6d, (byte)0x02, (byte)0x03, (byte)0x01, 
+                (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x81, 
+                (byte)0x80, (byte)0x78, (byte)0x41, (byte)0x72, 
+                (byte)0x40, (byte)0x90, (byte)0x59, (byte)0x96, 
+                (byte)0x5d, (byte)0xf3, (byte)0x84, (byte)0x3d, 
+                (byte)0x99, (byte)0xd9, (byte)0x4e, (byte)0x51, 
+                (byte)0xc2, (byte)0x52, (byte)0x62, (byte)0x8d, 
+                (byte)0xd2, (byte)0x49, (byte)0x0b, (byte)0x73, 
+                (byte)0x1e, (byte)0x6f, (byte)0xb2, (byte)0x31, 
+                (byte)0x7c, (byte)0x66, (byte)0x45, (byte)0x1e, 
+                (byte)0x7c, (byte)0xdc, (byte)0x3a, (byte)0xc2, 
+                (byte)0x5f, (byte)0x51, (byte)0x9a, (byte)0x1e, 
+                (byte)0xa4, (byte)0x19, (byte)0x8d, (byte)0xf4, 
+                (byte)0xf9, (byte)0x81, (byte)0x7e, (byte)0xbe, 
+                (byte)0x17, (byte)0xf7, (byte)0xc7, (byte)0x3c, 
+                (byte)0x00, (byte)0xa1, (byte)0xf9, (byte)0x60, 
+                (byte)0x82, (byte)0x34, (byte)0x8f, (byte)0x9c, 
+                (byte)0xfd, (byte)0x0b, (byte)0x63, (byte)0x42, 
+                (byte)0x1b, (byte)0x7f, (byte)0x45, (byte)0xf1, 
+                (byte)0x31, (byte)0xc3, (byte)0x63, (byte)0x47, 
+                (byte)0x5c, (byte)0xc1, (byte)0xb2, (byte)0x5f, 
+                (byte)0x57, (byte)0xee, (byte)0x02, (byte)0x9f, 
+                (byte)0x5e, (byte)0x08, (byte)0x48, (byte)0xba, 
+                (byte)0x74, (byte)0xba, (byte)0x81, (byte)0xb7, 
+                (byte)0x30, (byte)0xac, (byte)0x4c, (byte)0x01, 
+                (byte)0x35, (byte)0xce, (byte)0x46, (byte)0x47, 
+                (byte)0x8c, (byte)0xe4, (byte)0x62, (byte)0x36, 
+                (byte)0x1a, (byte)0x65, (byte)0x0e, (byte)0x33, 
+                (byte)0x56, (byte)0xf9, (byte)0xb7, (byte)0xa0, 
+                (byte)0xc4, (byte)0xb6, (byte)0x82, (byte)0x55, 
+                (byte)0x7d, (byte)0x36, (byte)0x55, (byte)0xc0, 
+                (byte)0x52, (byte)0x5e, (byte)0x35, (byte)0x54, 
+                (byte)0xbd, (byte)0x97, (byte)0x01, (byte)0x00, 
+                (byte)0xbf, (byte)0x10, (byte)0xdc, (byte)0x1b, 
+                (byte)0x51, (byte)0x02, (byte)0x41, (byte)0x00, 
+                (byte)0xe7, (byte)0x68, (byte)0x03, (byte)0x3e, 
+                (byte)0x21, (byte)0x64, (byte)0x68, (byte)0x24, 
+                (byte)0x7b, (byte)0xd0, (byte)0x31, (byte)0xa0, 
+                (byte)0xa2, (byte)0xd9, (byte)0x87, (byte)0x6d, 
+                (byte)0x79, (byte)0x81, (byte)0x8f, (byte)0x8f, 
+                (byte)0x2d, (byte)0x7a, (byte)0x95, (byte)0x2e, 
+                (byte)0x55, (byte)0x9f, (byte)0xd7, (byte)0x86, 
+                (byte)0x29, (byte)0x93, (byte)0xbd, (byte)0x04, 
+                (byte)0x7e, (byte)0x4f, (byte)0xdb, (byte)0x56, 
+                (byte)0xf1, (byte)0x75, (byte)0xd0, (byte)0x4b, 
+                (byte)0x00, (byte)0x3a, (byte)0xe0, (byte)0x26, 
+                (byte)0xf6, (byte)0xab, (byte)0x9e, (byte)0x0b, 
+                (byte)0x2a, (byte)0xf4, (byte)0xa8, (byte)0xd7, 
+                (byte)0xff, (byte)0xbe, (byte)0x01, (byte)0xeb, 
+                (byte)0x9b, (byte)0x81, (byte)0xc7, (byte)0x5f, 
+                (byte)0x02, (byte)0x73, (byte)0xe1, (byte)0x2b, 
+                (byte)0x02, (byte)0x41, (byte)0x00, (byte)0xc5, 
+                (byte)0x3d, (byte)0x78, (byte)0xab, (byte)0xe6, 
+                (byte)0xab, (byte)0x3e, (byte)0x29, (byte)0xfd, 
+                (byte)0x98, (byte)0xd0, (byte)0xa4, (byte)0x3e, 
+                (byte)0x58, (byte)0xee, (byte)0x48, (byte)0x45, 
+                (byte)0xa3, (byte)0x66, (byte)0xac, (byte)0xe9, 
+                (byte)0x4d, (byte)0xbd, (byte)0x60, (byte)0xea, 
+                (byte)0x24, (byte)0xff, (byte)0xed, (byte)0x0c, 
+                (byte)0x67, (byte)0xc5, (byte)0xfd, (byte)0x36, 
+                (byte)0x28, (byte)0xea, (byte)0x74, (byte)0x88, 
+                (byte)0xd1, (byte)0xd1, (byte)0xad, (byte)0x58, 
+                (byte)0xd7, (byte)0xf0, (byte)0x67, (byte)0x20, 
+                (byte)0xc1, (byte)0xe3, (byte)0xb3, (byte)0xdb, 
+                (byte)0x52, (byte)0xad, (byte)0xf3, (byte)0xc4, 
+                (byte)0x21, (byte)0xd8, (byte)0x8c, (byte)0x4c, 
+                (byte)0x41, (byte)0x27, (byte)0xdb, (byte)0xd0, 
+                (byte)0x35, (byte)0x92, (byte)0xc7, (byte)0x02, 
+                (byte)0x41, (byte)0x00, (byte)0xe0, (byte)0x99, 
+                (byte)0x42, (byte)0xb4, (byte)0x76, (byte)0x02, 
+                (byte)0x97, (byte)0x55, (byte)0xf9, (byte)0xda, 
+                (byte)0x3b, (byte)0xa0, (byte)0xd7, (byte)0x0e, 
+                (byte)0xdc, (byte)0xf4, (byte)0x33, (byte)0x7f, 
+                (byte)0xbd, (byte)0xcf, (byte)0xd0, (byte)0xeb, 
+                (byte)0x6e, (byte)0x89, (byte)0xf7, (byte)0x4f, 
+                (byte)0x5a, (byte)0x07, (byte)0x7c, (byte)0xa9, 
+                (byte)0x49, (byte)0x47, (byte)0x68, (byte)0x35, 
+                (byte)0xa8, (byte)0x05, (byte)0x3d, (byte)0xfd, 
+                (byte)0x04, (byte)0x7b, (byte)0x17, (byte)0x31, 
+                (byte)0x0d, (byte)0xc8, (byte)0xa3, (byte)0x98, 
+                (byte)0x34, (byte)0xa0, (byte)0x50, (byte)0x44, 
+                (byte)0x00, (byte)0xf1, (byte)0x0c, (byte)0xe6, 
+                (byte)0xe5, (byte)0xc4, (byte)0x41, (byte)0x3d, 
+                (byte)0xf8, (byte)0x3d, (byte)0x4e, (byte)0x0b, 
+                (byte)0x1c, (byte)0xdb, (byte)0x02, (byte)0x41, 
+                (byte)0x00, (byte)0x82, (byte)0x9b, (byte)0x8a, 
+                (byte)0xfd, (byte)0xa1, (byte)0x98, (byte)0x41, 
+                (byte)0x68, (byte)0xc2, (byte)0xd1, (byte)0xdf, 
+                (byte)0x4e, (byte)0xf3, (byte)0x2e, (byte)0x26, 
+                (byte)0x53, (byte)0x5b, (byte)0x31, (byte)0xb1, 
+                (byte)0x7a, (byte)0xcc, (byte)0x5e, (byte)0xbb, 
+                (byte)0x09, (byte)0xa2, (byte)0xe2, (byte)0x6f, 
+                (byte)0x4a, (byte)0x04, (byte)0x0d, (byte)0xef, 
+                (byte)0x90, (byte)0x15, (byte)0xbe, (byte)0x10, 
+                (byte)0x4a, (byte)0xac, (byte)0x92, (byte)0xeb, 
+                (byte)0xda, (byte)0x72, (byte)0xdb, (byte)0x43, 
+                (byte)0x08, (byte)0xb7, (byte)0x2b, (byte)0x4c, 
+                (byte)0xe1, (byte)0xbb, (byte)0x58, (byte)0xcb, 
+                (byte)0x71, (byte)0x80, (byte)0xad, (byte)0xbc, 
+                (byte)0xdc, (byte)0x62, (byte)0x5e, (byte)0x3e, 
+                (byte)0xcb, (byte)0x92, (byte)0xda, (byte)0xf6, 
+                (byte)0xdf, (byte)0x02, (byte)0x40, (byte)0x4d, 
+                (byte)0x81, (byte)0x90, (byte)0xc5, (byte)0x77, 
+                (byte)0x30, (byte)0xb7, (byte)0x29, (byte)0x00, 
+                (byte)0xa8, (byte)0xf1, (byte)0xb4, (byte)0xae, 
+                (byte)0x52, (byte)0x63, (byte)0x00, (byte)0xb2, 
+                (byte)0x2d, (byte)0x3e, (byte)0x7d, (byte)0xd6, 
+                (byte)0x4d, (byte)0xf9, (byte)0x8a, (byte)0xc1, 
+                (byte)0xb1, (byte)0x98, (byte)0x89, (byte)0x52, 
+                (byte)0x40, (byte)0x14, (byte)0x1b, (byte)0x0e, 
+                (byte)0x61, (byte)0x8f, (byte)0xf4, (byte)0xbe, 
+                (byte)0x59, (byte)0x79, (byte)0x79, (byte)0x95, 
+                (byte)0x19, (byte)0x5c, (byte)0x51, (byte)0x08, 
+                (byte)0x66, (byte)0xc1, (byte)0x42, (byte)0x30, 
+                (byte)0xb3, (byte)0x7a, (byte)0x86, (byte)0x9f, 
+                (byte)0x3e, (byte)0xf5, (byte)0x19, (byte)0xa3, 
+                (byte)0xae, (byte)0x64, (byte)0x69, (byte)0x14, 
+                (byte)0x07, (byte)0x50, (byte)0x97
+        });        
+        publicKeyEncoding.put("RSA", new byte[] {
+                (byte)0x30, (byte)0x81, (byte)0x9f, (byte)0x30, 
+                (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a, 
+                (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7, 
+                (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01, 
+                (byte)0x05, (byte)0x00, (byte)0x03, (byte)0x81, 
+                (byte)0x8d, (byte)0x00, (byte)0x30, (byte)0x81, 
+                (byte)0x89, (byte)0x02, (byte)0x81, (byte)0x81, 
+                (byte)0x00, (byte)0xb2, (byte)0x4a, (byte)0x9b, 
+                (byte)0x5b, (byte)0xba, (byte)0x01, (byte)0xc0, 
+                (byte)0xcd, (byte)0x65, (byte)0x09, (byte)0x63, 
+                (byte)0x70, (byte)0x0b, (byte)0x5a, (byte)0x1b, 
+                (byte)0x92, (byte)0x08, (byte)0xf8, (byte)0x55, 
+                (byte)0x5e, (byte)0x7c, (byte)0x1b, (byte)0x50, 
+                (byte)0x17, (byte)0xec, (byte)0x44, (byte)0x4c, 
+                (byte)0x58, (byte)0x42, (byte)0x2b, (byte)0x41, 
+                (byte)0x09, (byte)0x59, (byte)0xf2, (byte)0xe1, 
+                (byte)0x5d, (byte)0x43, (byte)0x71, (byte)0x4d, 
+                (byte)0x92, (byte)0x03, (byte)0x1d, (byte)0xb6, 
+                (byte)0x6c, (byte)0x7f, (byte)0x5d, (byte)0x48, 
+                (byte)0xcd, (byte)0x17, (byte)0xec, (byte)0xd7, 
+                (byte)0x4c, (byte)0x39, (byte)0xb1, (byte)0x7b, 
+                (byte)0xe2, (byte)0xbf, (byte)0x96, (byte)0x77, 
+                (byte)0xbe, (byte)0xd0, (byte)0xa0, (byte)0xf0, 
+                (byte)0x2d, (byte)0x6b, (byte)0x24, (byte)0xaa, 
+                (byte)0x14, (byte)0xba, (byte)0x82, (byte)0x79, 
+                (byte)0x10, (byte)0x9b, (byte)0x16, (byte)0x68, 
+                (byte)0x47, (byte)0x81, (byte)0x54, (byte)0xa2, 
+                (byte)0xfa, (byte)0x91, (byte)0x9e, (byte)0x0a, 
+                (byte)0x2a, (byte)0x53, (byte)0xa6, (byte)0xe7, 
+                (byte)0x9e, (byte)0x7d, (byte)0x29, (byte)0x33, 
+                (byte)0xd8, (byte)0x05, (byte)0xfc, (byte)0x02, 
+                (byte)0x3f, (byte)0xbd, (byte)0xc7, (byte)0x6e, 
+                (byte)0xed, (byte)0xaa, (byte)0x30, (byte)0x6c, 
+                (byte)0x5f, (byte)0x52, (byte)0xed, (byte)0x35, 
+                (byte)0x65, (byte)0x4b, (byte)0x0e, (byte)0xc8, 
+                (byte)0xa7, (byte)0x12, (byte)0x10, (byte)0x56, 
+                (byte)0x37, (byte)0xaf, (byte)0x11, (byte)0xfa, 
+                (byte)0x21, (byte)0x0e, (byte)0x99, (byte)0xff, 
+                (byte)0xfa, (byte)0x8c, (byte)0x65, (byte)0x8e, 
+                (byte)0x6d, (byte)0x02, (byte)0x03, (byte)0x01, 
+                (byte)0x00, (byte)0x01
+        });        
+        privateKeyEncoding.put("DSA", new byte[] {
+                (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x4a, 
+                (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x30, 
+                (byte)0x82, (byte)0x01, (byte)0x2b, (byte)0x06, 
+                (byte)0x07, (byte)0x2a, (byte)0x86, (byte)0x48, 
+                (byte)0xce, (byte)0x38, (byte)0x04, (byte)0x01, 
+                (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x1e, 
+                (byte)0x02, (byte)0x81, (byte)0x81, (byte)0x00, 
+                (byte)0xca, (byte)0x84, (byte)0x1d, (byte)0xa3, 
+                (byte)0xab, (byte)0xb9, (byte)0x98, (byte)0xf4, 
+                (byte)0x61, (byte)0x8b, (byte)0x66, (byte)0xdb, 
+                (byte)0x4e, (byte)0x3a, (byte)0xb2, (byte)0x11, 
+                (byte)0x4e, (byte)0xa9, (byte)0xda, (byte)0x35, 
+                (byte)0x91, (byte)0xc9, (byte)0x4e, (byte)0xc3, 
+                (byte)0x16, (byte)0xa7, (byte)0xed, (byte)0xb8, 
+                (byte)0x8f, (byte)0xd7, (byte)0xea, (byte)0xea, 
+                (byte)0xdb, (byte)0x77, (byte)0xe1, (byte)0x77, 
+                (byte)0x7a, (byte)0xc9, (byte)0xf3, (byte)0x37, 
+                (byte)0x33, (byte)0x01, (byte)0x72, (byte)0xbc, 
+                (byte)0xd0, (byte)0x89, (byte)0x9b, (byte)0x18, 
+                (byte)0xfd, (byte)0x84, (byte)0xd6, (byte)0xe9, 
+                (byte)0xbf, (byte)0x13, (byte)0x35, (byte)0x5e, 
+                (byte)0x40, (byte)0xf6, (byte)0x9d, (byte)0xd9, 
+                (byte)0x1a, (byte)0xba, (byte)0xa9, (byte)0xc3, 
+                (byte)0x8c, (byte)0xe3, (byte)0x95, (byte)0xc8, 
+                (byte)0xdf, (byte)0x2e, (byte)0x41, (byte)0xa1, 
+                (byte)0xbf, (byte)0xde, (byte)0x5d, (byte)0xad, 
+                (byte)0x21, (byte)0xcc, (byte)0x0d, (byte)0x42, 
+                (byte)0x56, (byte)0xa0, (byte)0x32, (byte)0xc0, 
+                (byte)0x90, (byte)0x73, (byte)0x3e, (byte)0xa4, 
+                (byte)0x0e, (byte)0x58, (byte)0xe4, (byte)0x64, 
+                (byte)0x00, (byte)0xa3, (byte)0x27, (byte)0x49, 
+                (byte)0x56, (byte)0xb2, (byte)0x43, (byte)0xbc, 
+                (byte)0x72, (byte)0xa8, (byte)0xd2, (byte)0x26, 
+                (byte)0x89, (byte)0x35, (byte)0x37, (byte)0x29, 
+                (byte)0x8d, (byte)0x21, (byte)0xb5, (byte)0x8e, 
+                (byte)0x59, (byte)0xfa, (byte)0x9e, (byte)0xdf, 
+                (byte)0x37, (byte)0x0d, (byte)0x9e, (byte)0xab, 
+                (byte)0xfd, (byte)0xbf, (byte)0x1a, (byte)0x9e, 
+                (byte)0xf3, (byte)0xe8, (byte)0x3a, (byte)0xfb, 
+                (byte)0x02, (byte)0x15, (byte)0x00, (byte)0xa2, 
+                (byte)0x4e, (byte)0x5d, (byte)0xe3, (byte)0x10, 
+                (byte)0x5d, (byte)0xa9, (byte)0x3a, (byte)0x6a, 
+                (byte)0x4d, (byte)0x07, (byte)0x3b, (byte)0xab, 
+                (byte)0xca, (byte)0x7d, (byte)0x09, (byte)0xd6, 
+                (byte)0x06, (byte)0x79, (byte)0x49, (byte)0x02, 
+                (byte)0x81, (byte)0x80, (byte)0x5a, (byte)0x91, 
+                (byte)0x83, (byte)0x1c, (byte)0x04, (byte)0x33, 
+                (byte)0xca, (byte)0x25, (byte)0xb0, (byte)0x68, 
+                (byte)0xb3, (byte)0xb3, (byte)0xab, (byte)0x55, 
+                (byte)0x29, (byte)0x33, (byte)0x4d, (byte)0xa9, 
+                (byte)0x33, (byte)0x39, (byte)0xef, (byte)0x71, 
+                (byte)0xca, (byte)0x95, (byte)0xf3, (byte)0xd8, 
+                (byte)0x27, (byte)0x56, (byte)0x5f, (byte)0x42, 
+                (byte)0xda, (byte)0x36, (byte)0x83, (byte)0xc5, 
+                (byte)0xf1, (byte)0x53, (byte)0x62, (byte)0xa5, 
+                (byte)0xdc, (byte)0xe6, (byte)0x4e, (byte)0x69, 
+                (byte)0x45, (byte)0x71, (byte)0x1a, (byte)0x4a, 
+                (byte)0xc3, (byte)0xf4, (byte)0x7f, (byte)0x0a, 
+                (byte)0xd1, (byte)0x78, (byte)0xed, (byte)0xbe, 
+                (byte)0x6e, (byte)0xa6, (byte)0x36, (byte)0x34, 
+                (byte)0x4e, (byte)0xc3, (byte)0x1b, (byte)0x17, 
+                (byte)0xaa, (byte)0xa4, (byte)0x76, (byte)0x44, 
+                (byte)0x46, (byte)0xaf, (byte)0x26, (byte)0x16, 
+                (byte)0x14, (byte)0xfb, (byte)0x9f, (byte)0x5d, 
+                (byte)0x08, (byte)0xaf, (byte)0x92, (byte)0xdb, 
+                (byte)0xba, (byte)0xd0, (byte)0xcb, (byte)0x8b, 
+                (byte)0x1e, (byte)0xc3, (byte)0x8b, (byte)0x36, 
+                (byte)0x3b, (byte)0x4c, (byte)0x02, (byte)0xc3, 
+                (byte)0x66, (byte)0x28, (byte)0x69, (byte)0xd0, 
+                (byte)0x74, (byte)0x4f, (byte)0x1c, (byte)0x4f, 
+                (byte)0x97, (byte)0x75, (byte)0x7f, (byte)0x9e, 
+                (byte)0x89, (byte)0x80, (byte)0xcf, (byte)0xb2, 
+                (byte)0x17, (byte)0xd6, (byte)0x66, (byte)0x91, 
+                (byte)0x12, (byte)0x3a, (byte)0xb0, (byte)0x3c, 
+                (byte)0x3c, (byte)0xc2, (byte)0x31, (byte)0xd1, 
+                (byte)0x31, (byte)0x2a, (byte)0x35, (byte)0xbe, 
+                (byte)0x9d, (byte)0x54, (byte)0x71, (byte)0x03, 
+                (byte)0xcb, (byte)0xcc, (byte)0x04, (byte)0x16, 
+                (byte)0x02, (byte)0x14, (byte)0x52, (byte)0xfb, 
+                (byte)0xf9, (byte)0x12, (byte)0x40, (byte)0x05, 
+                (byte)0x59, (byte)0x8f, (byte)0xde, (byte)0x9d, 
+                (byte)0xac, (byte)0xa1, (byte)0xe2, (byte)0xed, 
+                (byte)0x56, (byte)0x62, (byte)0x5f, (byte)0x56, 
+                (byte)0x67, (byte)0x74
+        });
+        publicKeyEncoding.put("DSA", new byte[] {
+                (byte)0x30, (byte)0x82, (byte)0x01, (byte)0xb7, 
+                (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x2b, 
+                (byte)0x06, (byte)0x07, (byte)0x2a, (byte)0x86, 
+                (byte)0x48, (byte)0xce, (byte)0x38, (byte)0x04, 
+                (byte)0x01, (byte)0x30, (byte)0x82, (byte)0x01, 
+                (byte)0x1e, (byte)0x02, (byte)0x81, (byte)0x81, 
+                (byte)0x00, (byte)0xca, (byte)0x84, (byte)0x1d, 
+                (byte)0xa3, (byte)0xab, (byte)0xb9, (byte)0x98, 
+                (byte)0xf4, (byte)0x61, (byte)0x8b, (byte)0x66, 
+                (byte)0xdb, (byte)0x4e, (byte)0x3a, (byte)0xb2, 
+                (byte)0x11, (byte)0x4e, (byte)0xa9, (byte)0xda, 
+                (byte)0x35, (byte)0x91, (byte)0xc9, (byte)0x4e, 
+                (byte)0xc3, (byte)0x16, (byte)0xa7, (byte)0xed, 
+                (byte)0xb8, (byte)0x8f, (byte)0xd7, (byte)0xea, 
+                (byte)0xea, (byte)0xdb, (byte)0x77, (byte)0xe1, 
+                (byte)0x77, (byte)0x7a, (byte)0xc9, (byte)0xf3, 
+                (byte)0x37, (byte)0x33, (byte)0x01, (byte)0x72, 
+                (byte)0xbc, (byte)0xd0, (byte)0x89, (byte)0x9b, 
+                (byte)0x18, (byte)0xfd, (byte)0x84, (byte)0xd6, 
+                (byte)0xe9, (byte)0xbf, (byte)0x13, (byte)0x35, 
+                (byte)0x5e, (byte)0x40, (byte)0xf6, (byte)0x9d, 
+                (byte)0xd9, (byte)0x1a, (byte)0xba, (byte)0xa9, 
+                (byte)0xc3, (byte)0x8c, (byte)0xe3, (byte)0x95, 
+                (byte)0xc8, (byte)0xdf, (byte)0x2e, (byte)0x41, 
+                (byte)0xa1, (byte)0xbf, (byte)0xde, (byte)0x5d, 
+                (byte)0xad, (byte)0x21, (byte)0xcc, (byte)0x0d, 
+                (byte)0x42, (byte)0x56, (byte)0xa0, (byte)0x32, 
+                (byte)0xc0, (byte)0x90, (byte)0x73, (byte)0x3e, 
+                (byte)0xa4, (byte)0x0e, (byte)0x58, (byte)0xe4, 
+                (byte)0x64, (byte)0x00, (byte)0xa3, (byte)0x27, 
+                (byte)0x49, (byte)0x56, (byte)0xb2, (byte)0x43, 
+                (byte)0xbc, (byte)0x72, (byte)0xa8, (byte)0xd2, 
+                (byte)0x26, (byte)0x89, (byte)0x35, (byte)0x37, 
+                (byte)0x29, (byte)0x8d, (byte)0x21, (byte)0xb5, 
+                (byte)0x8e, (byte)0x59, (byte)0xfa, (byte)0x9e, 
+                (byte)0xdf, (byte)0x37, (byte)0x0d, (byte)0x9e, 
+                (byte)0xab, (byte)0xfd, (byte)0xbf, (byte)0x1a, 
+                (byte)0x9e, (byte)0xf3, (byte)0xe8, (byte)0x3a, 
+                (byte)0xfb, (byte)0x02, (byte)0x15, (byte)0x00, 
+                (byte)0xa2, (byte)0x4e, (byte)0x5d, (byte)0xe3, 
+                (byte)0x10, (byte)0x5d, (byte)0xa9, (byte)0x3a, 
+                (byte)0x6a, (byte)0x4d, (byte)0x07, (byte)0x3b, 
+                (byte)0xab, (byte)0xca, (byte)0x7d, (byte)0x09, 
+                (byte)0xd6, (byte)0x06, (byte)0x79, (byte)0x49, 
+                (byte)0x02, (byte)0x81, (byte)0x80, (byte)0x5a, 
+                (byte)0x91, (byte)0x83, (byte)0x1c, (byte)0x04, 
+                (byte)0x33, (byte)0xca, (byte)0x25, (byte)0xb0, 
+                (byte)0x68, (byte)0xb3, (byte)0xb3, (byte)0xab, 
+                (byte)0x55, (byte)0x29, (byte)0x33, (byte)0x4d, 
+                (byte)0xa9, (byte)0x33, (byte)0x39, (byte)0xef, 
+                (byte)0x71, (byte)0xca, (byte)0x95, (byte)0xf3, 
+                (byte)0xd8, (byte)0x27, (byte)0x56, (byte)0x5f, 
+                (byte)0x42, (byte)0xda, (byte)0x36, (byte)0x83, 
+                (byte)0xc5, (byte)0xf1, (byte)0x53, (byte)0x62, 
+                (byte)0xa5, (byte)0xdc, (byte)0xe6, (byte)0x4e, 
+                (byte)0x69, (byte)0x45, (byte)0x71, (byte)0x1a, 
+                (byte)0x4a, (byte)0xc3, (byte)0xf4, (byte)0x7f, 
+                (byte)0x0a, (byte)0xd1, (byte)0x78, (byte)0xed, 
+                (byte)0xbe, (byte)0x6e, (byte)0xa6, (byte)0x36, 
+                (byte)0x34, (byte)0x4e, (byte)0xc3, (byte)0x1b, 
+                (byte)0x17, (byte)0xaa, (byte)0xa4, (byte)0x76, 
+                (byte)0x44, (byte)0x46, (byte)0xaf, (byte)0x26, 
+                (byte)0x16, (byte)0x14, (byte)0xfb, (byte)0x9f, 
+                (byte)0x5d, (byte)0x08, (byte)0xaf, (byte)0x92, 
+                (byte)0xdb, (byte)0xba, (byte)0xd0, (byte)0xcb, 
+                (byte)0x8b, (byte)0x1e, (byte)0xc3, (byte)0x8b, 
+                (byte)0x36, (byte)0x3b, (byte)0x4c, (byte)0x02, 
+                (byte)0xc3, (byte)0x66, (byte)0x28, (byte)0x69, 
+                (byte)0xd0, (byte)0x74, (byte)0x4f, (byte)0x1c, 
+                (byte)0x4f, (byte)0x97, (byte)0x75, (byte)0x7f, 
+                (byte)0x9e, (byte)0x89, (byte)0x80, (byte)0xcf, 
+                (byte)0xb2, (byte)0x17, (byte)0xd6, (byte)0x66, 
+                (byte)0x91, (byte)0x12, (byte)0x3a, (byte)0xb0, 
+                (byte)0x3c, (byte)0x3c, (byte)0xc2, (byte)0x31, 
+                (byte)0xd1, (byte)0x31, (byte)0x2a, (byte)0x35, 
+                (byte)0xbe, (byte)0x9d, (byte)0x54, (byte)0x71, 
+                (byte)0x03, (byte)0xcb, (byte)0xcc, (byte)0x03, 
+                (byte)0x81, (byte)0x85, (byte)0x00, (byte)0x02, 
+                (byte)0x81, (byte)0x81, (byte)0x00, (byte)0x95, 
+                (byte)0xcc, (byte)0x11, (byte)0xd4, (byte)0x53, 
+                (byte)0x3d, (byte)0x9c, (byte)0x5c, (byte)0x73, 
+                (byte)0xf4, (byte)0x70, (byte)0xf0, (byte)0xe1, 
+                (byte)0xac, (byte)0xe3, (byte)0x2c, (byte)0x32, 
+                (byte)0x16, (byte)0x1d, (byte)0x34, (byte)0x1a, 
+                (byte)0x38, (byte)0x63, (byte)0x69, (byte)0x1a, 
+                (byte)0x72, (byte)0x39, (byte)0x4e, (byte)0x41, 
+                (byte)0x50, (byte)0xfa, (byte)0xdc, (byte)0x78, 
+                (byte)0xa4, (byte)0xb8, (byte)0x17, (byte)0x5a, 
+                (byte)0xe4, (byte)0xf9, (byte)0xa2, (byte)0x52, 
+                (byte)0x41, (byte)0x85, (byte)0xab, (byte)0x3f, 
+                (byte)0xf4, (byte)0x73, (byte)0x2e, (byte)0xae, 
+                (byte)0xa9, (byte)0x21, (byte)0x8b, (byte)0x5e, 
+                (byte)0x95, (byte)0x15, (byte)0xa2, (byte)0x86, 
+                (byte)0x63, (byte)0x0d, (byte)0xba, (byte)0x01, 
+                (byte)0xcb, (byte)0xe3, (byte)0x68, (byte)0xc6, 
+                (byte)0xaf, (byte)0x56, (byte)0x51, (byte)0x7b, 
+                (byte)0xa8, (byte)0x85, (byte)0x3f, (byte)0x01, 
+                (byte)0x80, (byte)0x8b, (byte)0x1f, (byte)0xb4, 
+                (byte)0x4c, (byte)0x93, (byte)0x6b, (byte)0x42, 
+                (byte)0xa6, (byte)0xbd, (byte)0x67, (byte)0x2a, 
+                (byte)0x95, (byte)0x05, (byte)0xff, (byte)0x03, 
+                (byte)0x2e, (byte)0x6f, (byte)0xd4, (byte)0xd3, 
+                (byte)0xf0, (byte)0x17, (byte)0xde, (byte)0xcb, 
+                (byte)0x7d, (byte)0xd9, (byte)0x42, (byte)0x4d, 
+                (byte)0x97, (byte)0x2c, (byte)0x53, (byte)0xe6, 
+                (byte)0x39, (byte)0x61, (byte)0xd2, (byte)0x69, 
+                (byte)0xd1, (byte)0x1c, (byte)0x9a, (byte)0x8b, 
+                (byte)0x5b, (byte)0x9c, (byte)0xfa, (byte)0xfa, 
+                (byte)0x50, (byte)0x50, (byte)0xbb, (byte)0xe4, 
+                (byte)0x2e, (byte)0x83, (byte)0x06, (byte)0x08, 
+                (byte)0x96, (byte)0x2a, (byte)0x68
+        });
+        privateKeyEncoding.put("DH", new byte[] {
+                (byte) 0x30, (byte) 0xffffff81, (byte) 0xffffffe1, (byte) 0x2,
+                (byte) 0x1, (byte) 0x0, (byte) 0x30, (byte) 0xffffff81,
+                (byte) 0xffffff97, (byte) 0x6, (byte) 0x9, (byte) 0x2a,
+                (byte) 0xffffff86, (byte) 0x48, (byte) 0xffffff86,
+                (byte) 0xfffffff7, (byte) 0xd, (byte) 0x1, (byte) 0x3,
+                (byte) 0x1, (byte) 0x30, (byte) 0xffffff81, (byte) 0xffffff89,
+                (byte) 0x2, (byte) 0x41, (byte) 0x0, (byte) 0xfffffff0,
+                (byte) 0xffffffaa, (byte) 0x22, (byte) 0x5a, (byte) 0x29,
+                (byte) 0xffffffb2, (byte) 0x3f, (byte) 0xffffffc9, (byte) 0xb,
+                (byte) 0xffffff87, (byte) 0x5d, (byte) 0xffffff91, (byte) 0x51,
+                (byte) 0x1, (byte) 0xffffffa4, (byte) 0xffffffb9, (byte) 0x4e,
+                (byte) 0x1e, (byte) 0xffffff85, (byte) 0xfffffffc,
+                (byte) 0xffffffa6, (byte) 0x5a, (byte) 0xffffff96,
+                (byte) 0xffffffb1, (byte) 0xffffffcb, (byte) 0xffffff81,
+                (byte) 0xffffffa3, (byte) 0x6e, (byte) 0xffffff90,
+                (byte) 0xffffffbd, (byte) 0xffffffa2, (byte) 0xe,
+                (byte) 0xffffffb4, (byte) 0xffffffba, (byte) 0x2c, (byte) 0x45,
+                (byte) 0x9, (byte) 0x1c, (byte) 0xffffff98, (byte) 0x39,
+                (byte) 0x26, (byte) 0x24, (byte) 0x40, (byte) 0xffffff80,
+                (byte) 0xffffffce, (byte) 0x15, (byte) 0xffffff8b,
+                (byte) 0xffffffe1, (byte) 0x67, (byte) 0x48, (byte) 0xfffffff3,
+                (byte) 0x70, (byte) 0xffffff98, (byte) 0xffffffca,
+                (byte) 0xffffffa7, (byte) 0x71, (byte) 0x33, (byte) 0xffffffb6,
+                (byte) 0x4, (byte) 0x13, (byte) 0xffffffe5, (byte) 0x61,
+                (byte) 0x3c, (byte) 0x1f, (byte) 0x2, (byte) 0x40, (byte) 0x1e,
+                (byte) 0xffffffd8, (byte) 0x6f, (byte) 0xffffffce, (byte) 0x23,
+                (byte) 0x71, (byte) 0x6a, (byte) 0x2a, (byte) 0xffffffa3,
+                (byte) 0x4d, (byte) 0x62, (byte) 0xffffffe9, (byte) 0x5f,
+                (byte) 0x17, (byte) 0xffffffa8, (byte) 0xffffffe8,
+                (byte) 0xffffffaa, (byte) 0xffffff8a, (byte) 0xffffff95,
+                (byte) 0x26, (byte) 0x7c, (byte) 0x38, (byte) 0xffffffa9,
+                (byte) 0x2b, (byte) 0x48, (byte) 0x5a, (byte) 0x16,
+                (byte) 0x19, (byte) 0xfffffffa, (byte) 0xffffff83,
+                (byte) 0xffffffb8, (byte) 0x76, (byte) 0xffffffaf,
+                (byte) 0xffffffb8, (byte) 0x62, (byte) 0x72, (byte) 0x45,
+                (byte) 0xffffff9f, (byte) 0xffffff95, (byte) 0x1e, (byte) 0x62,
+                (byte) 0x36, (byte) 0xffffff97, (byte) 0xffffffbf,
+                (byte) 0xffffffab, (byte) 0x20, (byte) 0xffffffb0, (byte) 0x61,
+                (byte) 0xffffffc5, (byte) 0x21, (byte) 0xffffff9e,
+                (byte) 0xffffffe4, (byte) 0xffffffde, (byte) 0xffffff91,
+                (byte) 0x1c, (byte) 0x6a, (byte) 0x7, (byte) 0x48, (byte) 0x77,
+                (byte) 0x70, (byte) 0x1d, (byte) 0xffffffff, (byte) 0x58,
+                (byte) 0x23, (byte) 0x2, (byte) 0x2, (byte) 0x1,
+                (byte) 0xffffffff, (byte) 0x4, (byte) 0x42, (byte) 0x2,
+                (byte) 0x40, (byte) 0x69, (byte) 0xffffff86, (byte) 0x48,
+                (byte) 0x57, (byte) 0xffffffbf, (byte) 0xffffffde, (byte) 0x8,
+                (byte) 0xffffffc6, (byte) 0x24, (byte) 0x6d, (byte) 0xf,
+                (byte) 0x20, (byte) 0xffffff94, (byte) 0x4a, (byte) 0x22,
+                (byte) 0x6e, (byte) 0x24, (byte) 0x60, (byte) 0xffffffd9,
+                (byte) 0xffffffa9, (byte) 0xffffffbd, (byte) 0x1e, (byte) 0x64,
+                (byte) 0xffffff89, (byte) 0xffffff83, (byte) 0x3c,
+                (byte) 0xffffffe7, (byte) 0x70, (byte) 0x24, (byte) 0xffffffe1,
+                (byte) 0xffffff8f, (byte) 0x3c, (byte) 0x4d, (byte) 0x39,
+                (byte) 0x5f, (byte) 0xffffff9e, (byte) 0xffffff93, (byte) 0x13,
+                (byte) 0xffffff86, (byte) 0xffffffe9, (byte) 0xffffff80,
+                (byte) 0xf, (byte) 0xffffffc4, (byte) 0x41, (byte) 0xffffff8b,
+                (byte) 0xfffffff4, (byte) 0xffffff8b, (byte) 0x65,
+                (byte) 0xffffffa4, (byte) 0x1b, (byte) 0xd, (byte) 0x4,
+                (byte) 0x48, (byte) 0x40, (byte) 0xffffffd6, (byte) 0xffffffa2,
+                (byte) 0x0, (byte) 0xffffff85, (byte) 0xffffffe9,
+                (byte) 0xffffffc4, (byte) 0x77, (byte) 0xffffffb2, (byte) 0x25,
+                (byte) 0xffffffd8 
+        });
+        publicKeyEncoding.put("DH", new byte[] { 
+                (byte) 0x30, (byte) 0xffffff81, (byte) 0xffffffe0, (byte) 0x30,
+                (byte) 0xffffff81, (byte) 0xffffff97, (byte) 0x6, (byte) 0x9,
+                (byte) 0x2a, (byte) 0xffffff86, (byte) 0x48, (byte) 0xffffff86,
+                (byte) 0xfffffff7, (byte) 0xd, (byte) 0x1, (byte) 0x3,
+                (byte) 0x1, (byte) 0x30, (byte) 0xffffff81, (byte) 0xffffff89,
+                (byte) 0x2, (byte) 0x41, (byte) 0x0, (byte) 0xfffffff0,
+                (byte) 0xffffffaa, (byte) 0x22, (byte) 0x5a, (byte) 0x29,
+                (byte) 0xffffffb2, (byte) 0x3f, (byte) 0xffffffc9, (byte) 0xb,
+                (byte) 0xffffff87, (byte) 0x5d, (byte) 0xffffff91, (byte) 0x51,
+                (byte) 0x1, (byte) 0xffffffa4, (byte) 0xffffffb9, (byte) 0x4e,
+                (byte) 0x1e, (byte) 0xffffff85, (byte) 0xfffffffc,
+                (byte) 0xffffffa6, (byte) 0x5a, (byte) 0xffffff96,
+                (byte) 0xffffffb1, (byte) 0xffffffcb, (byte) 0xffffff81,
+                (byte) 0xffffffa3, (byte) 0x6e, (byte) 0xffffff90,
+                (byte) 0xffffffbd, (byte) 0xffffffa2, (byte) 0xe,
+                (byte) 0xffffffb4, (byte) 0xffffffba, (byte) 0x2c, (byte) 0x45,
+                (byte) 0x9, (byte) 0x1c, (byte) 0xffffff98, (byte) 0x39,
+                (byte) 0x26, (byte) 0x24, (byte) 0x40, (byte) 0xffffff80,
+                (byte) 0xffffffce, (byte) 0x15, (byte) 0xffffff8b,
+                (byte) 0xffffffe1, (byte) 0x67, (byte) 0x48, (byte) 0xfffffff3,
+                (byte) 0x70, (byte) 0xffffff98, (byte) 0xffffffca,
+                (byte) 0xffffffa7, (byte) 0x71, (byte) 0x33, (byte) 0xffffffb6,
+                (byte) 0x4, (byte) 0x13, (byte) 0xffffffe5, (byte) 0x61,
+                (byte) 0x3c, (byte) 0x1f, (byte) 0x2, (byte) 0x40, (byte) 0x1e,
+                (byte) 0xffffffd8, (byte) 0x6f, (byte) 0xffffffce, (byte) 0x23,
+                (byte) 0x71, (byte) 0x6a, (byte) 0x2a, (byte) 0xffffffa3,
+                (byte) 0x4d, (byte) 0x62, (byte) 0xffffffe9, (byte) 0x5f,
+                (byte) 0x17, (byte) 0xffffffa8, (byte) 0xffffffe8,
+                (byte) 0xffffffaa, (byte) 0xffffff8a, (byte) 0xffffff95,
+                (byte) 0x26, (byte) 0x7c, (byte) 0x38, (byte) 0xffffffa9,
+                (byte) 0x2b, (byte) 0x48, (byte) 0x5a, (byte) 0x16,
+                (byte) 0x19, (byte) 0xfffffffa, (byte) 0xffffff83,
+                (byte) 0xffffffb8, (byte) 0x76, (byte) 0xffffffaf,
+                (byte) 0xffffffb8, (byte) 0x62, (byte) 0x72, (byte) 0x45,
+                (byte) 0xffffff9f, (byte) 0xffffff95, (byte) 0x1e, (byte) 0x62,
+                (byte) 0x36, (byte) 0xffffff97, (byte) 0xffffffbf,
+                (byte) 0xffffffab, (byte) 0x20, (byte) 0xffffffb0, (byte) 0x61,
+                (byte) 0xffffffc5, (byte) 0x21, (byte) 0xffffff9e,
+                (byte) 0xffffffe4, (byte) 0xffffffde, (byte) 0xffffff91,
+                (byte) 0x1c, (byte) 0x6a, (byte) 0x7, (byte) 0x48, (byte) 0x77,
+                (byte) 0x70, (byte) 0x1d, (byte) 0xffffffff, (byte) 0x58,
+                (byte) 0x23, (byte) 0x2, (byte) 0x2, (byte) 0x1,
+                (byte) 0xffffffff, (byte) 0x3, (byte) 0x44, (byte) 0x0,
+                (byte) 0x2, (byte) 0x41, (byte) 0x0, (byte) 0xffffff9d,
+                (byte) 0xffffffc4, (byte) 0xffffffcd, (byte) 0x10,
+                (byte) 0xffffffdf, (byte) 0x66, (byte) 0xffffff92,
+                (byte) 0xffffffe1, (byte) 0x33, (byte) 0xffffffb1,
+                (byte) 0xffffffc9, (byte) 0xffffff9f, (byte) 0xffffffb7,
+                (byte) 0xffffffdd, (byte) 0xffffff84, (byte) 0x4b,
+                (byte) 0xffffffe5, (byte) 0xffffff86, (byte) 0xfffffff0,
+                (byte) 0x53, (byte) 0x2a, (byte) 0xffffffd5, (byte) 0xffffffc6,
+                (byte) 0x15, (byte) 0xffffff94, (byte) 0xffffffae, (byte) 0x13,
+                (byte) 0x7b, (byte) 0xffffff9d, (byte) 0x37, (byte) 0xffffff8b,
+                (byte) 0xffffffc6, (byte) 0xffffffc6, (byte) 0x78,
+                (byte) 0xffffff9c, (byte) 0x60, (byte) 0xffffff8a, (byte) 0x6f,
+                (byte) 0x35, (byte) 0x39, (byte) 0xffffffe0, (byte) 0x78,
+                (byte) 0x33, (byte) 0x60, (byte) 0xffffff89, (byte) 0x30,
+                (byte) 0x61, (byte) 0xffffff84, (byte) 0xffffff8a,
+                (byte) 0xffffffbc, (byte) 0xffffff80, (byte) 0x6c, (byte) 0x1c,
+                (byte) 0x55, (byte) 0xffffff96, (byte) 0x50, (byte) 0xffffffb1,
+                (byte) 0xffffff96, (byte) 0x5, (byte) 0x21, (byte) 0x65,
+                (byte) 0x55, (byte) 0xffffffbb, (byte) 0xffffffa4
+        });
+    }
+
+    public TestKeyPair(String algorithmName) throws
+            NoSuchAlgorithmException {
+        this.algorithmName = algorithmName;
+        if (!privateKeyEncoding.containsKey(this.algorithmName)) {
+            throw new NoSuchAlgorithmException("Encoded form not available for " +
+                    this.algorithmName);
+        }
+        kf = KeyFactory.getInstance(this.algorithmName);
+    }
+
+    public PublicKey getPublic() throws
+            InvalidKeySpecException {
+        return kf.generatePublic(
+                new X509EncodedKeySpec(
+                        (byte[])publicKeyEncoding.get(algorithmName)));
+    }
+
+    public PrivateKey getPrivate() throws
+            InvalidKeySpecException {
+        return kf.generatePrivate(
+                new PKCS8EncodedKeySpec(
+                        (byte[])privateKeyEncoding.get(algorithmName)));
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestUtils.java?rev=410788&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestUtils.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/TestUtils.java Thu Jun  1 01:15:17 2006
@@ -0,0 +1,85 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * Test utility class
+ * 
+ */
+public class TestUtils {
+    /**
+     * Relative (to the project home) test root path
+     */
+    public static final String TEST_ROOT = System.getProperty("RESOURCE_DIR", "test/common/unit")+ File.separator;
+
+    /**
+     * No need to instantiate
+     */
+    private TestUtils() {
+    }
+
+    /**
+     * Prints byte array <code>data</code> as hex to the
+     * <code>System.out</code> in the customizable form.
+     *
+     * @param perLine how many numbers put on single line
+     * @param prefix custom output number prefix
+     * @param delimiter custom output number delimiter
+     * @param data data to be printed
+     */
+    public static void printAsHex(int perLine,
+                                  String prefix,
+                                  String delimiter,
+                                  byte[] data) {
+        for (int i=0; i<data.length; i++) {
+            String tail = Integer.toHexString(0x000000ff & data[i]);
+            if (tail.length() == 1) {
+                tail = "0" + tail; 
+            }
+            System.out.print(prefix + "0x" + tail + delimiter);
+
+            if (((i+1)%perLine) == 0) {
+                System.out.println("");
+            }
+        }
+        System.out.println("");
+    }
+    
+    /**
+     * Sets system property
+     *
+     * @param key - the name of the system property.
+     * @param value - the value to be set
+     */
+    public static void setSystemProperty(String key, String value) {
+        Properties properties = System.getProperties();
+        if (value == null) {
+            properties.remove(key);
+        } else {
+            properties.setProperty(key, value);
+        }
+        System.setProperties(properties);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCRL.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCRL.java?rev=410788&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCRL.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCRL.java Thu Jun  1 01:15:17 2006
@@ -0,0 +1,59 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.cert.CRL;
+import java.security.cert.Certificate;
+
+/**
+ * Stub class for <code>java.security.cert.CRL</code> tests
+ * 
+ */
+public class MyCRL extends CRL {
+
+    /**
+     * Constructor
+     * 
+     * @param type
+     */
+    public MyCRL(String type) {
+        super(type);
+    }
+
+    /**
+     * @return <code>String</code> representation
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return "MyCRL: [" + getType() + "]";
+    }
+
+    /**
+     * @param cert <code>Certificate</code> to be checked
+     * @return always <code>false</code>
+     * @see java.security.cert.CRL#isRevoked(java.security.cert.Certificate)
+     */
+    public boolean isRevoked(Certificate cert) {
+        return false;
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java?rev=410788&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java Thu Jun  1 01:15:17 2006
@@ -0,0 +1,105 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.cert.CertPath;
+import java.security.cert.CertificateEncodingException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+
+/**
+ * Stub class for <code>java.security.cert.CertPath</code> tests
+ * 
+ */
+public class MyCertPath extends CertPath {
+    /**
+     * my certificates list
+     */
+    private final Vector certificates;
+    /**
+     * List of encodings supported
+     */
+    private final Vector encodingNames;
+    /**
+     * my cert path the only encoding
+     */
+    private final byte[] encoding;
+
+    /**
+     * Constucts new instance of <code>MyCertPath</code>
+     * 
+     * @param type
+     * @param encoding
+     */
+    public MyCertPath(byte[] encoding) {
+        super("MyEncoding");
+        this.encoding = encoding;
+        certificates = new Vector();
+        certificates.add(new MyCertificate("MyEncoding", encoding));
+        encodingNames = new Vector();
+        encodingNames.add("MyEncoding");
+    }
+
+    /**
+     * @return certificates list
+     * @see java.security.cert.CertPath#getCertificates()
+     */
+    public List getCertificates() {
+        return Collections.unmodifiableList(certificates);
+    }
+
+    /**
+     * @return default encoded form of this cert path
+     * @see java.security.cert.CertPath#getEncoded()
+     */
+    public byte[] getEncoded() throws CertificateEncodingException {
+        return encoding.clone();
+    }
+
+    /**
+     * @return encoded form of this cert path as specified by
+     * <code>encoding</code> parameter
+     * @throws CertificateEncodingException if <code>encoding</code>
+     * not equals "MyEncoding" 
+     * @see java.security.cert.CertPath#getEncoded(java.lang.String)
+     */
+    public byte[] getEncoded(String encoding)
+            throws CertificateEncodingException {
+        if (getType().equals(encoding)) {
+            return this.encoding.clone();
+        }
+        throw new CertificateEncodingException("Encoding not supported: " +
+                encoding);
+    }
+
+    /**
+     * @return iterator through encodings supported
+     * @see java.security.cert.CertPath#getEncodings()
+     */
+    public Iterator getEncodings() {
+        return Collections.unmodifiableCollection(encodingNames).iterator();
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java?rev=410788&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/support/common/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java Thu Jun  1 01:15:17 2006
@@ -0,0 +1,102 @@
+/*
+ *  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.
+ */
+
+/**
+* @author Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+
+/**
+ * Stub class for <code>java.security.cert.Certificate</code> tests
+ */
+public class MyCertificate extends Certificate {
+
+    // MyCertificate encoding
+    private final byte[] encoding;
+
+    /**
+     * Constructs new object of class <code>MyCertificate</code>
+     * 
+     * @param type
+     * @param encoding
+     */
+    public MyCertificate(String type, byte[] encoding) {
+        super(type);
+        // don't copy to allow null parameter in test
+        this.encoding = encoding;
+    }
+
+    /**
+     * Returns <code>MyCertificate</code> encoding
+     */
+    public byte[] getEncoded() throws CertificateEncodingException {
+        // do copy to force NPE in test
+        return encoding.clone();
+    }
+
+    /**
+     * Does nothing
+     */
+    public void verify(PublicKey key) throws CertificateException,
+            NoSuchAlgorithmException, InvalidKeyException,
+            NoSuchProviderException, SignatureException {
+    }
+
+    /**
+     * Does nothing
+     */
+    public void verify(PublicKey key, String sigProvider)
+            throws CertificateException, NoSuchAlgorithmException,
+            InvalidKeyException, NoSuchProviderException, SignatureException {
+    }
+
+    /**
+     * Returns formatted <code>String</code>
+     * describing <code>MyCertificate</code> object
+     */
+    public String toString() {
+        return "[My test Certificate, type: " + getType() + "]";
+    }
+
+    /**
+     * Returns public key (stub) from <code>MyCertificate</code> object
+     */
+    public PublicKey getPublicKey() {
+        return new PublicKey() {
+            public String getAlgorithm() {
+                return "TEST";
+            }
+            public byte[] getEncoded() {
+                return new byte[] {(byte)1, (byte)2, (byte)3};
+            }
+            public String getFormat() {
+                return "TEST_FORMAT";
+            }
+        };
+    }
+
+}



Mime
View raw message