1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19 * @author Vladimir N. Molotkov 20 */ 21 22package org.apache.harmony.security.tests.java.security; 23 24import junit.framework.TestCase; 25 26/** 27 * 28 * 29 */ 30public class KeyRepTest extends TestCase { 31 // 32// private static final Set<String> keyFactoryAlgorithm; 33// static { 34// keyFactoryAlgorithm = Security.getAlgorithms("KeyFactory"); 35// } 36// 37 public final void testKeyRep01() { 38// KeyRep kr = new KeyRep(KeyRep.Type.SECRET, "", "", new byte[] {}); 39// kr = new KeyRep(KeyRep.Type.PUBLIC, "", "", new byte[] {}); 40// kr = new KeyRep(KeyRep.Type.PRIVATE, "", "", new byte[] {}); 41 } 42// 43// public final void testKeyRep02() { 44// try { 45// KeyRep kr = new KeyRep(null, "", "", new byte[] {}); 46// fail("NullPointerException has not been thrown (type)"); 47// } catch (NullPointerException ok) { 48// System.out.println(getName() + ": " + ok); 49// } 50// try { 51// KeyRep kr = new KeyRep(KeyRep.Type.SECRET, null, "", new byte[] {}); 52// fail("NullPointerException has not been thrown (alg)"); 53// } catch (NullPointerException ok) { 54// System.out.println(getName() + ": " + ok); 55// } 56// try { 57// KeyRep kr = new KeyRep(KeyRep.Type.PRIVATE, "", null, new byte[] {}); 58// fail("NullPointerException has not been thrown (format)"); 59// } catch (NullPointerException ok) { 60// System.out.println(getName() + ": " + ok); 61// } 62// try { 63// KeyRep kr = new KeyRep(KeyRep.Type.PUBLIC, "", "", null); 64// fail("NullPointerException has not been thrown (encoding)"); 65// } catch (NullPointerException ok) { 66// System.out.println(getName() + ": " + ok); 67// } 68// } 69// 70// public final void testReadResolve01() throws ObjectStreamException { 71// KeyRep kr = new KeyRep(KeyRep.Type.SECRET, "", "", new byte[] {}); 72// try { 73// kr.readResolve(); 74// fail("NotSerializableException has not been thrown (no format)"); 75// } catch (NotSerializableException ok) { 76// System.out.println(getName() + ": " + ok); 77// } 78// 79// kr = new KeyRep(KeyRep.Type.SECRET, "", "X.509", new byte[] {}); 80// try { 81// kr.readResolve(); 82// fail("NotSerializableException has not been thrown (unacceptable format)"); 83// } catch (NotSerializableException ok) { 84// System.out.println(getName() + ": " + ok); 85// } 86// 87// kr = new KeyRep(KeyRep.Type.SECRET, "", "RAW", new byte[] {}); 88// try { 89// kr.readResolve(); 90// fail("NotSerializableException has not been thrown (empty key)"); 91// } catch (NotSerializableException ok) { 92// System.out.println(getName() + ": " + ok); 93// } 94// } 95// 96// public final void testReadResolve02() throws ObjectStreamException { 97// KeyRep kr = new KeyRep(KeyRep.Type.PUBLIC, "", "", new byte[] {}); 98// try { 99// kr.readResolve(); 100// fail("NotSerializableException has not been thrown (no format)"); 101// } catch (NotSerializableException ok) { 102// System.out.println(getName() + ": " + ok); 103// } 104// 105// kr = new KeyRep(KeyRep.Type.PUBLIC, "", "RAW", new byte[] {}); 106// try { 107// kr.readResolve(); 108// fail("NotSerializableException has not been thrown (unacceptable format)"); 109// } catch (NotSerializableException ok) { 110// System.out.println(getName() + ": " + ok); 111// } 112// 113// kr = new KeyRep(KeyRep.Type.PUBLIC, "bla-bla", "X.509", new byte[] {}); 114// try { 115// kr.readResolve(); 116// fail("NotSerializableException has not been thrown (unknown KeyFactory algorithm)"); 117// } catch (NotSerializableException ok) { 118// System.out.println(getName() + ": " + ok); 119// } 120// } 121// 122// public final void testReadResolve03() throws ObjectStreamException { 123// KeyRep kr = new KeyRep(KeyRep.Type.PRIVATE, "", "", new byte[] {}); 124// try { 125// kr.readResolve(); 126// fail("NotSerializableException has not been thrown (no format)"); 127// } catch (NotSerializableException ok) { 128// System.out.println(getName() + ": " + ok); 129// } 130// 131// kr = new KeyRep(KeyRep.Type.PRIVATE, "", "RAW", new byte[] {}); 132// try { 133// kr.readResolve(); 134// fail("NotSerializableException has not been thrown (unacceptable format)"); 135// } catch (NotSerializableException ok) { 136// System.out.println(getName() + ": " + ok); 137// } 138// 139// kr = new KeyRep(KeyRep.Type.PRIVATE, "bla-bla", "PKCS#8", new byte[] {}); 140// try { 141// kr.readResolve(); 142// fail("NotSerializableException has not been thrown (unknown KeyFactory algorithm)"); 143// } catch (NotSerializableException ok) { 144// System.out.println(getName() + ": " + ok); 145// } 146// } 147// 148// public final void testReadResolve04() throws ObjectStreamException { 149// if (keyFactoryAlgorithm.isEmpty()) { 150// System.err.println(getName() + ": skipped - no KeyFactory algorithms available"); 151// return; 152// } else { 153// System.out.println(getName() + ": available algorithms - " + 154// keyFactoryAlgorithm); 155// } 156// for (Iterator<String> i = keyFactoryAlgorithm.iterator(); i.hasNext();) { 157// KeyRep kr = new KeyRep(KeyRep.Type.PUBLIC, 158// i.next(), "X.509", new byte[] {1,2,3}); 159// try { 160// kr.readResolve(); 161// fail("NotSerializableException has not been thrown (no format)"); 162// } catch (NotSerializableException ok) { 163// System.out.println(getName() + ": " + ok); 164// } 165// } 166// } 167// 168// public final void testReadResolve05() throws ObjectStreamException { 169// if (keyFactoryAlgorithm.isEmpty()) { 170// System.err.println(getName() + ": skipped - no KeyFactory algorithms available"); 171// return; 172// } else { 173// System.out.println(getName() + ": available algorithms - " + 174// keyFactoryAlgorithm); 175// } 176// for (Iterator<String> i = keyFactoryAlgorithm.iterator(); i.hasNext();) { 177// KeyRep kr = new KeyRep(KeyRep.Type.PRIVATE, 178// i.next(), "PKCS#8", new byte[] {1,2,3}); 179// try { 180// kr.readResolve(); 181// fail("NotSerializableException has not been thrown (no format)"); 182// } catch (NotSerializableException ok) { 183// System.out.println(getName() + ": " + ok); 184// } 185// } 186// } 187} 188