Home | History | Annotate | Download | only in crypto
      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 Vera Y. Petrashkova
     20 */
     21 
     22 package javax.crypto;
     23 
     24 import java.security.AlgorithmParameters;
     25 import java.security.InvalidAlgorithmParameterException;
     26 import java.security.InvalidKeyException;
     27 import java.security.Key;
     28 import java.security.spec.AlgorithmParameterSpec;
     29 
     30 import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi;
     31 
     32 import junit.framework.TestCase;
     33 
     34 
     35 /**
     36  * Tests for <code>ExemptionMechanismSpi</code> class constructors and
     37  * methods.
     38  *
     39  */
     40 
     41 public class ExemptionMechanismSpiTest extends TestCase {
     42     /**
     43      * Constructor for ExemptionMechanismSpiTests.
     44      *
     45      * @param arg0
     46      */
     47     public ExemptionMechanismSpiTest(String arg0) {
     48         super(arg0);
     49     }
     50 
     51     /**
     52      * Test for <code>ExemptionMechanismSpi</code> constructor Assertion:
     53      * constructs ExemptionMechanismSpi
     54      */
     55     public void testExemptionMechanismSpi01()
     56             throws  ExemptionMechanismException,
     57             ShortBufferException, InvalidKeyException,
     58             InvalidAlgorithmParameterException {
     59         ExemptionMechanismSpi emSpi = new MyExemptionMechanismSpi();
     60         int len = MyExemptionMechanismSpi.getLength();
     61         byte [] bbRes = emSpi.engineGenExemptionBlob();
     62         assertEquals("Incorrect length", bbRes.length, len);
     63         assertEquals("Incorrect result",
     64                 emSpi.engineGenExemptionBlob(new byte[1], len), len);
     65         assertEquals("Incorrect output size", 10, emSpi.engineGetOutputSize(100));
     66         Key key = null;
     67         AlgorithmParameters params = null;
     68         AlgorithmParameterSpec parSpec = null;
     69         try {
     70             emSpi.engineInit(key);
     71             fail("InvalidKeyException must be thrown");
     72         } catch (InvalidKeyException e) {
     73         }
     74         try {
     75             emSpi.engineInit(key, params);
     76             fail("InvalidKeyException must be thrown");
     77         } catch (InvalidKeyException e) {
     78         }
     79         try {
     80             emSpi.engineInit(key, parSpec);
     81             fail("InvalidKeyException must be thrown");
     82         } catch (InvalidKeyException e) {
     83         }
     84         key = ((MyExemptionMechanismSpi)emSpi).new tmp1Key("Proba", new byte[0]);
     85         try {
     86             emSpi.engineInit(key);
     87             fail("ExemptionMechanismException must be thrown");
     88         } catch (ExemptionMechanismException e) {
     89         }
     90         try {
     91             emSpi.engineInit(key, params);
     92             fail("ExemptionMechanismException must be thrown");
     93         } catch (ExemptionMechanismException e) {
     94         }
     95         try {
     96             emSpi.engineInit(key, parSpec);
     97             fail("ExemptionMechanismException must be thrown");
     98         } catch (ExemptionMechanismException e) {
     99         }
    100         key = ((MyExemptionMechanismSpi)emSpi).new tmpKey("Proba", new byte[0]);
    101         emSpi.engineInit(key);
    102         emSpi.engineInit(key, params);
    103         emSpi.engineInit(key, parSpec);
    104 
    105         assertEquals("Incorrect result", 10, emSpi.engineGetOutputSize(100));
    106     }
    107 }
    108