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