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