blob: ff4babca9c014780ffcac79f4f035578330ba40c [file] [log] [blame]
The Android Open Source Projectadc854b2009-03-03 19:28:47 -08001/*
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
22package org.apache.harmony.crypto.tests.support;
23
24import java.security.AlgorithmParameters;
25import java.security.InvalidAlgorithmParameterException;
26import java.security.InvalidKeyException;
27import java.security.Key;
28import java.security.NoSuchAlgorithmException;
29import java.security.SecureRandom;
30import java.security.spec.AlgorithmParameterSpec;
31
32import javax.crypto.BadPaddingException;
33import javax.crypto.CipherSpi;
34import javax.crypto.IllegalBlockSizeException;
35import javax.crypto.NoSuchPaddingException;
36import javax.crypto.ShortBufferException;
37
38/**
39 *
40 * Cipher implementation for testing
41 */
42public 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 {
Alex Klyubin9f48b7f2014-01-31 15:38:20 -080055 if ((!"PKCS5Padding".equals(padding))
56 && (!"PKCS7Padding".equals(padding))) {
The Android Open Source Projectadc854b2009-03-03 19:28:47 -080057 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}