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