001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Boris V. Kuznetsov
019: * @version $Revision$
020: */package org.apache.harmony.crypto.tests.support;
021:
022: import java.security.AlgorithmParameters;
023: import java.security.InvalidAlgorithmParameterException;
024: import java.security.InvalidKeyException;
025: import java.security.Key;
026: import java.security.NoSuchAlgorithmException;
027: import java.security.SecureRandom;
028: import java.security.spec.AlgorithmParameterSpec;
029:
030: import javax.crypto.BadPaddingException;
031: import javax.crypto.CipherSpi;
032: import javax.crypto.IllegalBlockSizeException;
033: import javax.crypto.NoSuchPaddingException;
034: import javax.crypto.ShortBufferException;
035:
036: /**
037: *
038: * Cipher implementation for testing
039: */
040: public class MyCipher extends CipherSpi {
041:
042: public MyCipher() {
043: super ();
044: }
045:
046: @Override
047: protected void engineSetMode(String mode)
048: throws NoSuchAlgorithmException {
049: }
050:
051: @Override
052: protected void engineSetPadding(String padding)
053: throws NoSuchPaddingException {
054: if (!"PKCS5Padding".equals(padding)) {
055: throw new NoSuchPaddingException(padding);
056: }
057: }
058:
059: @Override
060: protected int engineGetBlockSize() {
061: return 111;
062: }
063:
064: @Override
065: protected int engineGetOutputSize(int inputLen) {
066: return inputLen + 10;
067: }
068:
069: @Override
070: protected byte[] engineGetIV() {
071: byte[] b = { 1, 2, 3 };
072: return b;
073: }
074:
075: @Override
076: protected AlgorithmParameters engineGetParameters() {
077: return null;
078: }
079:
080: @Override
081: protected void engineInit(int opmode, Key key, SecureRandom random)
082: throws InvalidKeyException {
083: }
084:
085: @Override
086: protected void engineInit(int opmode, Key key,
087: AlgorithmParameterSpec params, SecureRandom random)
088: throws InvalidKeyException,
089: InvalidAlgorithmParameterException {
090: }
091:
092: @Override
093: protected void engineInit(int opmode, Key key,
094: AlgorithmParameters params, SecureRandom random)
095: throws InvalidKeyException,
096: InvalidAlgorithmParameterException {
097: }
098:
099: @Override
100: protected byte[] engineUpdate(byte[] input, int inputOffset,
101: int inputLen) {
102: return null;
103: }
104:
105: @Override
106: protected int engineUpdate(byte[] input, int inputOffset,
107: int inputLen, byte[] output, int outputOffset)
108: throws ShortBufferException {
109: return 0;
110: }
111:
112: @Override
113: protected byte[] engineDoFinal(byte[] input, int inputOffset,
114: int inputLen) throws IllegalBlockSizeException,
115: BadPaddingException {
116: return null;
117: }
118:
119: @Override
120: protected int engineDoFinal(byte[] input, int inputOffset,
121: int inputLen, byte[] output, int outputOffset)
122: throws ShortBufferException, IllegalBlockSizeException,
123: BadPaddingException {
124: return 0;
125: }
126:
127: }
|