2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package tests.security.interfaces;
19 import dalvik.annotation.TestTargets;
20 import dalvik.annotation.TestLevel;
21 import dalvik.annotation.TestTargetNew;
22 import dalvik.annotation.TestTargetClass;
24 import junit.framework.TestCase;
26 import java.math.BigInteger;
27 import java.security.interfaces.RSAMultiPrimePrivateCrtKey;
28 import java.security.spec.RSAOtherPrimeInfo;
30 import org.apache.harmony.security.tests.support.interfaces.RSAMultiPrimePrivateCrtKeyImpl;
32 @TestTargetClass(RSAMultiPrimePrivateCrtKey.class)
33 public class RSAMultiPrimePrivateCrtKeyTest extends TestCase {
36 * Reference array of RSAOtherPrimeInfo. DO NOT MODIFY
38 private static final RSAOtherPrimeInfo[] opi = new RSAOtherPrimeInfo[] {
39 new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE),
40 new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE),
41 new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE)
44 private final BigInteger publicExponent = BigInteger.ONE;
45 private final BigInteger primeExponentP = BigInteger.ONE;
46 private final BigInteger primeExponentQ = BigInteger.ONE;
47 private final BigInteger primeP = BigInteger.ONE;
48 private final BigInteger primeQ = BigInteger.ONE;
49 private final BigInteger crtCoefficient = BigInteger.ONE;
51 class RSAMulti extends RSAMultiPrimePrivateCrtKeyImpl {
52 public RSAMulti(BigInteger publicExp,
58 RSAOtherPrimeInfo[] otherPrmInfo) {
59 super(publicExp, primeExpP, primeExpQ, prP, prQ, crtCft, otherPrmInfo);
64 * @tests java.security.interfaces.RSAMultiPrimePrivateCrtKey#getCrtCoefficient()
65 * @tests java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPrimeExponentP()
66 * @tests java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPrimeExponentQ()
67 * @tests java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPrimeP()
68 * @tests java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPrimeQ()
69 * @tests java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPublicExponent()
73 level = TestLevel.COMPLETE,
75 method = "getCrtCoefficient",
79 level = TestLevel.COMPLETE,
81 method = "getPrimeExponentP",
85 level = TestLevel.COMPLETE,
87 method = "getPrimeExponentQ",
91 level = TestLevel.COMPLETE,
97 level = TestLevel.COMPLETE,
103 level = TestLevel.COMPLETE,
105 method = "getPublicExponent",
109 public void test_RSAMultiPrimePrivateCrtKey() {
110 RSAMulti rsam = new RSAMulti(publicExponent, primeExponentP, primeExponentQ,
111 primeP, primeQ, crtCoefficient, opi);
113 assertEquals(rsam.getCrtCoefficient(), crtCoefficient);
114 assertEquals(rsam.getPrimeExponentP(), primeExponentP);
115 assertEquals(rsam.getPrimeExponentQ(), primeExponentQ);
116 assertEquals(rsam.getPrimeP(), primeP);
117 assertEquals(rsam.getPrimeQ(), primeQ);
118 assertEquals(rsam.getPublicExponent(), publicExponent);
119 } catch (Exception e) {
120 fail("Unexpected exception: " + e);
125 * @tests java.security.interfaces.RSAMultiPrimePrivateCrtKey#getOtherPrimeInfo()
128 level = TestLevel.COMPLETE,
130 method = "getOtherPrimeInfo",
133 public void test_getOtherPrimeInfo() {
134 RSAMulti rsam = new RSAMulti(publicExponent, primeExponentP, primeExponentQ,
135 primeP, primeQ, crtCoefficient, null);
137 assertNull("Object RSAOtherPrimeInfo is not NULL", rsam.getOtherPrimeInfo());
138 } catch (Exception e) {
139 fail("Unexpected exception: " + e);
141 rsam = new RSAMulti(publicExponent, primeExponentP, primeExponentQ,
142 primeP, primeQ, crtCoefficient, opi);
145 assertEquals(rsam.getOtherPrimeInfo(), opi);
146 } catch (Exception e) {
147 fail("Unexpected exception: " + e);