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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @author Vera Y. Petrashkova
23 package org.apache.harmony.crypto.tests.javax.crypto;
25 import dalvik.annotation.TestTargetClass;
26 import dalvik.annotation.TestTargets;
27 import dalvik.annotation.TestLevel;
28 import dalvik.annotation.TestTargetNew;
30 import java.security.InvalidAlgorithmParameterException;
31 import java.security.SecureRandom;
32 import java.security.spec.AlgorithmParameterSpec;
33 import javax.crypto.KeyGeneratorSpi;
34 import javax.crypto.SecretKey;
36 import org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi;
38 import junit.framework.TestCase;
40 @TestTargetClass(KeyGeneratorSpi.class)
42 * Tests for <code>KeyGeneratorSpi</code> class constructors and methods.
46 public class KeyGeneratorSpiTest extends TestCase {
47 class Mock_KeyGeneratorSpi extends MyKeyGeneratorSpi {
50 protected SecretKey engineGenerateKey() {
51 return super.engineGenerateKey();
55 protected void engineInit(SecureRandom random) {
56 super.engineInit(random);
60 protected void engineInit(AlgorithmParameterSpec params, SecureRandom random)
61 throws InvalidAlgorithmParameterException {
62 super.engineInit(params, random);
66 protected void engineInit(int keysize, SecureRandom random) {
67 super.engineInit(keysize, random);
73 * Test for <code>KeyGeneratorSpi</code> constructor Assertion: constructs
76 @TestTargetNew(level = TestLevel.COMPLETE, notes = "", method = "KeyGeneratorSpi", args = {})
77 public void testKeyGeneratorSpi01() throws InvalidAlgorithmParameterException {
78 Mock_KeyGeneratorSpi kgSpi = new Mock_KeyGeneratorSpi();
79 assertNull("Not null result", kgSpi.engineGenerateKey());
81 kgSpi.engineInit(77, new SecureRandom());
82 fail("IllegalArgumentException must be thrown");
83 } catch (IllegalArgumentException e) {
86 kgSpi.engineInit(new SecureRandom());
87 fail("IllegalArgumentException must be thrown");
88 } catch (IllegalArgumentException e) {
90 AlgorithmParameterSpec aps = null;
92 kgSpi.engineInit(aps, new SecureRandom());
93 fail("InvalidAlgorithmParameterException must be thrown when parameter is null");
94 } catch (InvalidAlgorithmParameterException e) {
96 aps = new APSpecSpi();
97 kgSpi.engineInit(aps, new SecureRandom());
102 class APSpecSpi implements AlgorithmParameterSpec {