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.spec; 23 24import java.math.BigInteger; 25import java.security.spec.KeySpec; 26import java.security.spec.RSAPrivateCrtKeySpec; 27import java.security.spec.RSAPrivateKeySpec; 28 29import junit.framework.TestCase; 30 31/** 32 * Tests for <code>RSAPrivateCrtKeySpec</code> class fields and methods 33 * 34 */ 35public class RSAPrivateCrtKeySpecTest extends TestCase { 36 37 /** 38 * Constructor for RSAPrivateCrtKeySpecTest. 39 * @param name 40 */ 41 public RSAPrivateCrtKeySpecTest(String name) { 42 super(name); 43 } 44 45 /** 46 * Test #1 for <code>RSAPrivateCrtKeySpec</code> constructor 47 * Assertion: Constructs <code>RSAPrivateCrtKeySpec</code> 48 * object using valid parameters 49 */ 50 public final void testRSAPrivateCrtKeySpec01() { 51 KeySpec ks = new RSAPrivateCrtKeySpec( 52 BigInteger.ONE, 53 BigInteger.ONE, 54 BigInteger.ONE, 55 BigInteger.ONE, 56 BigInteger.ONE, 57 BigInteger.ONE, 58 BigInteger.ONE, 59 BigInteger.ONE); 60 assertTrue(ks instanceof RSAPrivateCrtKeySpec); 61 } 62 63 /** 64 * Test #2 for <code>RSAPrivateCrtKeySpec</code> constructor 65 * Assertion: Constructs <code>RSAPrivateCrtKeySpec</code> 66 * object using valid parameters 67 */ 68 public final void testRSAPrivateCrtKeySpec02() { 69 KeySpec ks = new RSAPrivateCrtKeySpec( 70 BigInteger.ONE, 71 BigInteger.ONE, 72 BigInteger.ONE, 73 BigInteger.ONE, 74 BigInteger.ONE, 75 BigInteger.ONE, 76 BigInteger.ONE, 77 BigInteger.ONE); 78 assertTrue(ks instanceof RSAPrivateKeySpec); 79 } 80 81 /** 82 * Test #3 for <code>RSAPrivateCrtKeySpec</code> constructor 83 * Assertion: Constructs <code>RSAPrivateCrtKeySpec</code> 84 * object using valid parameters 85 */ 86 public final void testRSAPrivateCrtKeySpec03() { 87 new RSAPrivateCrtKeySpec( 88 null, 89 null, 90 null, 91 null, 92 null, 93 null, 94 null, 95 null); 96 } 97 98 /** 99 * Test for <code>getCrtCoefficient()</code> method<br> 100 * Assertion: returns crt coefficient 101 */ 102 public final void testGetCrtCoefficient() { 103 RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( 104 BigInteger.ONE, 105 BigInteger.ONE, 106 BigInteger.ONE, 107 BigInteger.ONE, 108 BigInteger.ONE, 109 BigInteger.ONE, 110 BigInteger.ONE, 111 BigInteger.valueOf(5L)); 112 assertTrue(BigInteger.valueOf(5L).equals(ks.getCrtCoefficient())); 113 } 114 115 /** 116 * Test for <code>getPrimeExponentP()</code> method<br> 117 * Assertion: returns prime exponent P 118 */ 119 public final void testGetPrimeExponentP() { 120 RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( 121 BigInteger.ONE, 122 BigInteger.ONE, 123 BigInteger.ONE, 124 BigInteger.ONE, 125 BigInteger.ONE, 126 BigInteger.valueOf(5L), 127 BigInteger.ONE, 128 BigInteger.ONE); 129 assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeExponentP())); 130 } 131 132 /** 133 * Test for <code>getPrimeExponentQ()</code> method<br> 134 * Assertion: returns prime exponent Q 135 */ 136 public final void testGetPrimeExponentQ() { 137 RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( 138 BigInteger.ONE, 139 BigInteger.ONE, 140 BigInteger.ONE, 141 BigInteger.ONE, 142 BigInteger.ONE, 143 BigInteger.ONE, 144 BigInteger.valueOf(5L), 145 BigInteger.ONE); 146 assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeExponentQ())); 147 } 148 149 /** 150 * Test for <code>getPrimeP()</code> method<br> 151 * Assertion: returns prime P 152 */ 153 public final void testGetPrimeP() { 154 RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( 155 BigInteger.ONE, 156 BigInteger.ONE, 157 BigInteger.ONE, 158 BigInteger.valueOf(5L), 159 BigInteger.ONE, 160 BigInteger.ONE, 161 BigInteger.ONE, 162 BigInteger.ONE); 163 assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeP())); 164 } 165 166 /** 167 * Test for <code>getPrimeQ()</code> method<br> 168 * Assertion: returns prime Q 169 */ 170 public final void testGetPrimeQ() { 171 RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( 172 BigInteger.ONE, 173 BigInteger.ONE, 174 BigInteger.ONE, 175 BigInteger.ONE, 176 BigInteger.valueOf(5L), 177 BigInteger.ONE, 178 BigInteger.ONE, 179 BigInteger.ONE); 180 assertTrue(BigInteger.valueOf(5L).equals(ks.getPrimeQ())); 181 } 182 183 /** 184 * Test for <code>getPublicExponent()</code> method<br> 185 * Assertion: returns public exponent 186 */ 187 public final void testGetPublicExponent() { 188 RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( 189 BigInteger.ONE, 190 BigInteger.valueOf(5L), 191 BigInteger.ONE, 192 BigInteger.ONE, 193 BigInteger.ONE, 194 BigInteger.ONE, 195 BigInteger.ONE, 196 BigInteger.ONE); 197 assertTrue(BigInteger.valueOf(5L).equals(ks.getPublicExponent())); 198 } 199 200 // 201 // Tests for inherited methods 202 // 203 204 /** 205 * Test for <code>getModulus()</code> method<br> 206 * Assertion: returns modulus 207 */ 208 public final void testGetModulus() { 209 RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( 210 BigInteger.valueOf(5L), 211 BigInteger.ONE, 212 BigInteger.ONE, 213 BigInteger.ONE, 214 BigInteger.ONE, 215 BigInteger.ONE, 216 BigInteger.ONE, 217 BigInteger.ONE); 218 assertTrue(BigInteger.valueOf(5L).equals(ks.getModulus())); 219 } 220 221 /** 222 * Test for <code>getPrivateExponent()</code> method<br> 223 * Assertion: returns private exponent 224 */ 225 public final void testGetPrivateExponent() { 226 RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec( 227 BigInteger.ONE, 228 BigInteger.ONE, 229 BigInteger.valueOf(5L), 230 BigInteger.ONE, 231 BigInteger.ONE, 232 BigInteger.ONE, 233 BigInteger.ONE, 234 BigInteger.ONE); 235 assertTrue(BigInteger.valueOf(5L).equals(ks.getPrivateExponent())); 236 } 237 238} 239