Home | History | Annotate | Download | only in support
      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 * @author Boris V. Kuznetsov
     19 * @version $Revision$
     20 */
     21 
     22 package org.apache.harmony.crypto.tests.support;
     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.NoSuchAlgorithmException;
     29 import java.security.SecureRandom;
     30 import java.security.spec.AlgorithmParameterSpec;
     31 
     32 import javax.crypto.BadPaddingException;
     33 import javax.crypto.CipherSpi;
     34 import javax.crypto.IllegalBlockSizeException;
     35 import javax.crypto.NoSuchPaddingException;
     36 import javax.crypto.ShortBufferException;
     37 
     38 /**
     39  *
     40  * Cipher implementation for testing
     41  */
     42 public class MyCipher extends CipherSpi {
     43 
     44     public MyCipher() {
     45         super();
     46     }
     47 
     48     @Override
     49     protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
     50     }
     51 
     52     @Override
     53     protected void engineSetPadding(String padding)
     54             throws NoSuchPaddingException {
     55         if ((!"PKCS5Padding".equals(padding))
     56                 && (!"PKCS7Padding".equals(padding))) {
     57             throw new  NoSuchPaddingException(padding);
     58         }
     59     }
     60 
     61     @Override
     62     protected int engineGetBlockSize() {
     63         return 111;
     64     }
     65 
     66     @Override
     67     protected int engineGetOutputSize(int inputLen) {
     68         return inputLen + 10;
     69     }
     70 
     71     @Override
     72     protected byte[] engineGetIV() {
     73         byte[] b = {1,2,3};
     74         return b;
     75     }
     76 
     77     @Override
     78     protected AlgorithmParameters engineGetParameters() {
     79         return null;
     80     }
     81 
     82     @Override
     83     protected void engineInit(int opmode, Key key, SecureRandom random)
     84             throws InvalidKeyException {
     85     }
     86 
     87     @Override
     88     protected void engineInit(int opmode, Key key,
     89             AlgorithmParameterSpec params, SecureRandom random)
     90             throws InvalidKeyException, InvalidAlgorithmParameterException {
     91     }
     92 
     93     @Override
     94     protected void engineInit(int opmode, Key key, AlgorithmParameters params,
     95             SecureRandom random) throws InvalidKeyException,
     96             InvalidAlgorithmParameterException {
     97     }
     98 
     99     @Override
    100     protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) {
    101         return null;
    102     }
    103 
    104     @Override
    105     protected int engineUpdate(byte[] input, int inputOffset, int inputLen,
    106             byte[] output, int outputOffset) throws ShortBufferException {
    107         return 0;
    108     }
    109 
    110     @Override
    111     protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
    112             throws IllegalBlockSizeException, BadPaddingException {
    113         return null;
    114     }
    115 
    116     @Override
    117     protected int engineDoFinal(byte[] input, int inputOffset, int inputLen,
    118             byte[] output, int outputOffset) throws ShortBufferException,
    119             IllegalBlockSizeException, BadPaddingException {
    120         return 0;
    121     }
    122 
    123 }
    124