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 Vera Y. Petrashkova 20* @version $Revision$ 21*/ 22 23package org.apache.harmony.security.tests.java.security; 24 25import java.security.InvalidAlgorithmParameterException; 26import java.security.InvalidParameterException; 27import java.security.KeyPair; 28import java.security.KeyPairGeneratorSpi; 29import java.security.SecureRandom; 30import java.security.spec.AlgorithmParameterSpec; 31 32import org.apache.harmony.security.tests.support.MyKeyPairGeneratorSpi; 33 34import junit.framework.TestCase; 35 36/** 37 * Tests for <code>KeyPairGeneratorSpi</code> class constructors and methods. 38 * 39 */ 40public class KeyPairGeneratorSpiTest extends TestCase { 41 42 /** 43 * Test for <code>KeyPairGeneratorSpi</code> constructor 44 * Assertion: constructs KeyPairGeneratorSpi 45 */ 46 public void testKeyPairGeneratorSpi01() 47 throws InvalidAlgorithmParameterException, 48 InvalidParameterException { 49 KeyPairGeneratorSpi keyPairGen = new MyKeyPairGeneratorSpi(); 50 51 AlgorithmParameterSpec pp = null; 52 try { 53 keyPairGen.initialize(pp, null); 54 fail("UnsupportedOperationException must be thrown"); 55 } catch (UnsupportedOperationException e) { 56 } 57 58 keyPairGen.initialize(pp, new SecureRandom()); 59 keyPairGen.initialize(1024, new SecureRandom()); 60 try { 61 keyPairGen.initialize(-1024, new SecureRandom()); 62 fail("IllegalArgumentException must be thrown for incorrect keysize"); 63 } catch (IllegalArgumentException e) { 64 } 65 try { 66 keyPairGen.initialize(1024, null); 67 fail("IllegalArgumentException must be thrown"); 68 } catch (IllegalArgumentException e) { 69 assertEquals("Incorrect exception", e.getMessage(), 70 "Invalid random"); 71 } 72 KeyPair kp = keyPairGen.generateKeyPair(); 73 assertNull("Not null KeyPair", kp); 74 } 75 76 class MyAlgorithmParameterSpec implements AlgorithmParameterSpec {} 77 78} 79