Home | History | Annotate | Download | only in interfaces
      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  */
     16 
     17 package tests.security.interfaces;
     18 
     19 import junit.framework.TestCase;
     20 
     21 import java.math.BigInteger;
     22 import java.security.interfaces.RSAMultiPrimePrivateCrtKey;
     23 import java.security.spec.RSAOtherPrimeInfo;
     24 
     25 import org.apache.harmony.security.tests.support.interfaces.RSAMultiPrimePrivateCrtKeyImpl;
     26 
     27 public class RSAMultiPrimePrivateCrtKeyTest extends TestCase {
     28 
     29     /**
     30      * Reference array of RSAOtherPrimeInfo. DO NOT MODIFY
     31      */
     32     private static final RSAOtherPrimeInfo[] opi = new RSAOtherPrimeInfo[] {
     33             new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE),
     34             new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE),
     35             new RSAOtherPrimeInfo(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE)
     36     };
     37 
     38     private final BigInteger publicExponent = BigInteger.ONE;
     39     private final BigInteger primeExponentP = BigInteger.ONE;
     40     private final BigInteger primeExponentQ = BigInteger.ONE;
     41     private final BigInteger primeP = BigInteger.ONE;
     42     private final BigInteger primeQ = BigInteger.ONE;
     43     private final BigInteger crtCoefficient = BigInteger.ONE;
     44 
     45     class RSAMulti extends RSAMultiPrimePrivateCrtKeyImpl {
     46         public RSAMulti(BigInteger publicExp,
     47                         BigInteger primeExpP,
     48                         BigInteger primeExpQ,
     49                         BigInteger prP,
     50                         BigInteger prQ,
     51                         BigInteger crtCft,
     52                         RSAOtherPrimeInfo[] otherPrmInfo) {
     53             super(publicExp, primeExpP, primeExpQ, prP, prQ, crtCft, otherPrmInfo);
     54         }
     55     }
     56 
     57     /**
     58      * java.security.interfaces.RSAMultiPrimePrivateCrtKey#getCrtCoefficient()
     59      * java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPrimeExponentP()
     60      * java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPrimeExponentQ()
     61      * java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPrimeP()
     62      * java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPrimeQ()
     63      * java.security.interfaces.RSAMultiPrimePrivateCrtKey#getPublicExponent()
     64      */
     65     public void test_RSAMultiPrimePrivateCrtKey() {
     66         RSAMulti rsam = new RSAMulti(publicExponent, primeExponentP, primeExponentQ,
     67                                      primeP, primeQ, crtCoefficient, opi);
     68         try {
     69             assertEquals(rsam.getCrtCoefficient(), crtCoefficient);
     70             assertEquals(rsam.getPrimeExponentP(), primeExponentP);
     71             assertEquals(rsam.getPrimeExponentQ(), primeExponentQ);
     72             assertEquals(rsam.getPrimeP(), primeP);
     73             assertEquals(rsam.getPrimeQ(), primeQ);
     74             assertEquals(rsam.getPublicExponent(), publicExponent);
     75         } catch (Exception e) {
     76             fail("Unexpected exception: " + e);
     77         }
     78     }
     79 
     80     /**
     81      * java.security.interfaces.RSAMultiPrimePrivateCrtKey#getOtherPrimeInfo()
     82      */
     83     public void test_getOtherPrimeInfo() {
     84         RSAMulti rsam = new RSAMulti(publicExponent, primeExponentP, primeExponentQ,
     85                                      primeP, primeQ, crtCoefficient, null);
     86         try {
     87             assertNull("Object RSAOtherPrimeInfo is not NULL", rsam.getOtherPrimeInfo());
     88         } catch (Exception e) {
     89             fail("Unexpected exception: " + e);
     90         }
     91         rsam = new RSAMulti(publicExponent, primeExponentP, primeExponentQ,
     92                             primeP, primeQ, crtCoefficient, opi);
     93 
     94         try {
     95             assertEquals(rsam.getOtherPrimeInfo(), opi);
     96         } catch (Exception e) {
     97             fail("Unexpected exception: " + e);
     98         }
     99     }
    100 }
    101