1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16package tests.security.interfaces;
17import dalvik.annotation.TestLevel;
18import dalvik.annotation.TestTargetNew;
19import dalvik.annotation.TestTargetClass;
20
21import junit.framework.TestCase;
22
23import java.security.KeyFactory;
24import java.security.interfaces.RSAPrivateCrtKey;
25
26@TestTargetClass(RSAPrivateCrtKey.class)
27public class RSAPrivateCrtKeyTest extends TestCase {
28
29    RSAPrivateCrtKey key = null;
30
31    protected void setUp() throws Exception {
32        super.setUp();
33        KeyFactory gen = KeyFactory.getInstance("RSA");
34        key = (RSAPrivateCrtKey) gen.generatePrivate(Util.rsaCrtParam);
35    }
36
37    /**
38     * @tests java.security.interfaces.RSAPrivateCrtKey
39     * #getCrtCoefficient()
40     */
41    @TestTargetNew(
42        level = TestLevel.COMPLETE,
43        notes = "",
44        method = "getCrtCoefficient",
45        args = {}
46    )
47    public void test_getCrtCoefficient() {
48        assertEquals("invalid CRT coefficient",
49                Util.rsaCrtParam.getCrtCoefficient(), key.getCrtCoefficient());
50    }
51
52    /**
53     * @tests java.security.interfaces.RSAPrivateCrtKey
54     * #getPrimeExponentP()
55     */
56    @TestTargetNew(
57        level = TestLevel.COMPLETE,
58        notes = "",
59        method = "getPrimeExponentP",
60        args = {}
61    )
62    public void test_getPrimeExponentP() {
63        assertEquals("invalid prime exponent P",
64                Util.rsaCrtParam.getPrimeExponentP(), key.getPrimeExponentP());
65    }
66
67    /**
68     * @tests java.security.interfaces.RSAPrivateCrtKey
69     * #getPrimeExponentQ()
70     */
71    @TestTargetNew(
72        level = TestLevel.COMPLETE,
73        notes = "",
74        method = "getPrimeExponentQ",
75        args = {}
76    )
77    public void test_getPrimeExponentQ() {
78        assertEquals("invalid prime exponent Q",
79                Util.rsaCrtParam.getPrimeExponentQ(), key.getPrimeExponentQ());
80    }
81
82    /**
83     * @tests java.security.interfaces.RSAPrivateCrtKey
84     * #getPrimeP()
85     */
86    @TestTargetNew(
87        level = TestLevel.COMPLETE,
88        notes = "",
89        method = "getPrimeP",
90        args = {}
91    )
92    public void test_getPrimeP() {
93        assertEquals("invalid prime P",
94                Util.rsaCrtParam.getPrimeP(), key.getPrimeP());
95    }
96
97    /**
98     * @tests java.security.interfaces.RSAPrivateCrtKey
99     * #getPrimeQ()
100     */
101    @TestTargetNew(
102        level = TestLevel.COMPLETE,
103        notes = "",
104        method = "getPrimeQ",
105        args = {}
106    )
107    public void test_getPrimeQ() {
108        assertEquals("invalid prime Q",
109                Util.rsaCrtParam.getPrimeQ(), key.getPrimeQ());
110    }
111
112    /**
113     * @tests java.security.interfaces.RSAPrivateCrtKey
114     * #getPublicExponent()
115     */
116    @TestTargetNew(
117        level = TestLevel.COMPLETE,
118        notes = "",
119        method = "getPublicExponent",
120        args = {}
121    )
122    public void test_getPublicExponent() {
123        assertEquals("invalid public exponent",
124                Util.rsaCrtParam.getPublicExponent(), key.getPublicExponent());
125    }
126
127    protected void tearDown() throws Exception {
128        key = null;
129        super.tearDown();
130    }
131}
132