001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Vladimir N. Molotkov
020: * @version $Revision$
021: */package org.apache.harmony.security.tests.java.security;
022:
023: import junit.framework.TestCase;
024:
025: /**
026: *
027: *
028: */
029: public class KeyRepTest extends TestCase {
030: //
031: // private static final Set<String> keyFactoryAlgorithm;
032: // static {
033: // keyFactoryAlgorithm = Security.getAlgorithms("KeyFactory");
034: // }
035: //
036: public final void testKeyRep01() {
037: // KeyRep kr = new KeyRep(KeyRep.Type.SECRET, "", "", new byte[] {});
038: // kr = new KeyRep(KeyRep.Type.PUBLIC, "", "", new byte[] {});
039: // kr = new KeyRep(KeyRep.Type.PRIVATE, "", "", new byte[] {});
040: }
041: //
042: // public final void testKeyRep02() {
043: // try {
044: // KeyRep kr = new KeyRep(null, "", "", new byte[] {});
045: // fail("NullPointerException has not been thrown (type)");
046: // } catch (NullPointerException ok) {
047: // System.out.println(getName() + ": " + ok);
048: // }
049: // try {
050: // KeyRep kr = new KeyRep(KeyRep.Type.SECRET, null, "", new byte[] {});
051: // fail("NullPointerException has not been thrown (alg)");
052: // } catch (NullPointerException ok) {
053: // System.out.println(getName() + ": " + ok);
054: // }
055: // try {
056: // KeyRep kr = new KeyRep(KeyRep.Type.PRIVATE, "", null, new byte[] {});
057: // fail("NullPointerException has not been thrown (format)");
058: // } catch (NullPointerException ok) {
059: // System.out.println(getName() + ": " + ok);
060: // }
061: // try {
062: // KeyRep kr = new KeyRep(KeyRep.Type.PUBLIC, "", "", null);
063: // fail("NullPointerException has not been thrown (encoding)");
064: // } catch (NullPointerException ok) {
065: // System.out.println(getName() + ": " + ok);
066: // }
067: // }
068: //
069: // public final void testReadResolve01() throws ObjectStreamException {
070: // KeyRep kr = new KeyRep(KeyRep.Type.SECRET, "", "", new byte[] {});
071: // try {
072: // kr.readResolve();
073: // fail("NotSerializableException has not been thrown (no format)");
074: // } catch (NotSerializableException ok) {
075: // System.out.println(getName() + ": " + ok);
076: // }
077: //
078: // kr = new KeyRep(KeyRep.Type.SECRET, "", "X.509", new byte[] {});
079: // try {
080: // kr.readResolve();
081: // fail("NotSerializableException has not been thrown (unacceptable format)");
082: // } catch (NotSerializableException ok) {
083: // System.out.println(getName() + ": " + ok);
084: // }
085: //
086: // kr = new KeyRep(KeyRep.Type.SECRET, "", "RAW", new byte[] {});
087: // try {
088: // kr.readResolve();
089: // fail("NotSerializableException has not been thrown (empty key)");
090: // } catch (NotSerializableException ok) {
091: // System.out.println(getName() + ": " + ok);
092: // }
093: // }
094: //
095: // public final void testReadResolve02() throws ObjectStreamException {
096: // KeyRep kr = new KeyRep(KeyRep.Type.PUBLIC, "", "", new byte[] {});
097: // try {
098: // kr.readResolve();
099: // fail("NotSerializableException has not been thrown (no format)");
100: // } catch (NotSerializableException ok) {
101: // System.out.println(getName() + ": " + ok);
102: // }
103: //
104: // kr = new KeyRep(KeyRep.Type.PUBLIC, "", "RAW", new byte[] {});
105: // try {
106: // kr.readResolve();
107: // fail("NotSerializableException has not been thrown (unacceptable format)");
108: // } catch (NotSerializableException ok) {
109: // System.out.println(getName() + ": " + ok);
110: // }
111: //
112: // kr = new KeyRep(KeyRep.Type.PUBLIC, "bla-bla", "X.509", new byte[] {});
113: // try {
114: // kr.readResolve();
115: // fail("NotSerializableException has not been thrown (unknown KeyFactory algorithm)");
116: // } catch (NotSerializableException ok) {
117: // System.out.println(getName() + ": " + ok);
118: // }
119: // }
120: //
121: // public final void testReadResolve03() throws ObjectStreamException {
122: // KeyRep kr = new KeyRep(KeyRep.Type.PRIVATE, "", "", new byte[] {});
123: // try {
124: // kr.readResolve();
125: // fail("NotSerializableException has not been thrown (no format)");
126: // } catch (NotSerializableException ok) {
127: // System.out.println(getName() + ": " + ok);
128: // }
129: //
130: // kr = new KeyRep(KeyRep.Type.PRIVATE, "", "RAW", new byte[] {});
131: // try {
132: // kr.readResolve();
133: // fail("NotSerializableException has not been thrown (unacceptable format)");
134: // } catch (NotSerializableException ok) {
135: // System.out.println(getName() + ": " + ok);
136: // }
137: //
138: // kr = new KeyRep(KeyRep.Type.PRIVATE, "bla-bla", "PKCS#8", new byte[] {});
139: // try {
140: // kr.readResolve();
141: // fail("NotSerializableException has not been thrown (unknown KeyFactory algorithm)");
142: // } catch (NotSerializableException ok) {
143: // System.out.println(getName() + ": " + ok);
144: // }
145: // }
146: //
147: // public final void testReadResolve04() throws ObjectStreamException {
148: // if (keyFactoryAlgorithm.isEmpty()) {
149: // System.err.println(getName() + ": skipped - no KeyFactory algorithms available");
150: // return;
151: // } else {
152: // System.out.println(getName() + ": available algorithms - " +
153: // keyFactoryAlgorithm);
154: // }
155: // for (Iterator<String> i = keyFactoryAlgorithm.iterator(); i.hasNext();) {
156: // KeyRep kr = new KeyRep(KeyRep.Type.PUBLIC,
157: // i.next(), "X.509", new byte[] {1,2,3});
158: // try {
159: // kr.readResolve();
160: // fail("NotSerializableException has not been thrown (no format)");
161: // } catch (NotSerializableException ok) {
162: // System.out.println(getName() + ": " + ok);
163: // }
164: // }
165: // }
166: //
167: // public final void testReadResolve05() throws ObjectStreamException {
168: // if (keyFactoryAlgorithm.isEmpty()) {
169: // System.err.println(getName() + ": skipped - no KeyFactory algorithms available");
170: // return;
171: // } else {
172: // System.out.println(getName() + ": available algorithms - " +
173: // keyFactoryAlgorithm);
174: // }
175: // for (Iterator<String> i = keyFactoryAlgorithm.iterator(); i.hasNext();) {
176: // KeyRep kr = new KeyRep(KeyRep.Type.PRIVATE,
177: // i.next(), "PKCS#8", new byte[] {1,2,3});
178: // try {
179: // kr.readResolve();
180: // fail("NotSerializableException has not been thrown (no format)");
181: // } catch (NotSerializableException ok) {
182: // System.out.println(getName() + ": " + ok);
183: // }
184: // }
185: // }
186: }
|