The Android Open Source Project | adc854b | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 | throw new NoSuchPaddingException(padding); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected int engineGetBlockSize() { |
| 62 | return 111; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected int engineGetOutputSize(int inputLen) { |
| 67 | return inputLen + 10; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | protected byte[] engineGetIV() { |
| 72 | byte[] b = {1,2,3}; |
| 73 | return b; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | protected AlgorithmParameters engineGetParameters() { |
| 78 | return null; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | protected void engineInit(int opmode, Key key, SecureRandom random) |
| 83 | throws InvalidKeyException { |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | protected void engineInit(int opmode, Key key, |
| 88 | AlgorithmParameterSpec params, SecureRandom random) |
| 89 | throws InvalidKeyException, InvalidAlgorithmParameterException { |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | protected void engineInit(int opmode, Key key, AlgorithmParameters params, |
| 94 | SecureRandom random) throws InvalidKeyException, |
| 95 | InvalidAlgorithmParameterException { |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) { |
| 100 | return null; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | protected int engineUpdate(byte[] input, int inputOffset, int inputLen, |
| 105 | byte[] output, int outputOffset) throws ShortBufferException { |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) |
| 111 | throws IllegalBlockSizeException, BadPaddingException { |
| 112 | return null; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, |
| 117 | byte[] output, int outputOffset) throws ShortBufferException, |
| 118 | IllegalBlockSizeException, BadPaddingException { |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | } |