Package org.apache.harmony.crypto.tests.support

Source Code of org.apache.harmony.crypto.tests.support.MyCipher

/*
*  Licensed to the Apache Software Foundation (ASF) under one or more
*  contributor license agreements.  See the NOTICE file distributed with
*  this work for additional information regarding copyright ownership.
*  The ASF licenses this file to You under the Apache License, Version 2.0
*  (the "License"); you may not use this file except in compliance with
*  the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
/**
* @author Boris V. Kuznetsov
*/

package org.apache.harmony.crypto.tests.support;

import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;

import javax.crypto.BadPaddingException;
import javax.crypto.CipherSpi;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;

/**
*
* Cipher implementation for testing
*/
public class MyCipher extends CipherSpi {

  public MyCipher() {
    super();
  }

  @Override
    protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
  }

  @Override
    protected void engineSetPadding(String padding)
      throws NoSuchPaddingException {
    if (!"PKCS5Padding".equals(padding)) {
      throw new  NoSuchPaddingException(padding);
    }
  }

  @Override
    protected int engineGetBlockSize() {
    return 111;
  }

  @Override
    protected int engineGetOutputSize(int inputLen) {
    return inputLen + 10;
  }

  @Override
    protected byte[] engineGetIV() {
    byte[] b = {1,2,3};
    return b;
  }

  @Override
    protected AlgorithmParameters engineGetParameters() {
    return null;
  }

  @Override
    protected void engineInit(int opmode, Key key, SecureRandom random)
      throws InvalidKeyException {
  }

  @Override
    protected void engineInit(int opmode, Key key,
      AlgorithmParameterSpec params, SecureRandom random)
      throws InvalidKeyException, InvalidAlgorithmParameterException {
  }

  @Override
    protected void engineInit(int opmode, Key key, AlgorithmParameters params,
      SecureRandom random) throws InvalidKeyException,
      InvalidAlgorithmParameterException {
  }

  @Override
    protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) {
    return null;
  }

  @Override
    protected int engineUpdate(byte[] input, int inputOffset, int inputLen,
      byte[] output, int outputOffset) throws ShortBufferException {
    return 0;
  }

  @Override
    protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
      throws IllegalBlockSizeException, BadPaddingException {
    return null;
  }

  @Override
    protected int engineDoFinal(byte[] input, int inputOffset, int inputLen,
      byte[] output, int outputOffset) throws ShortBufferException,
      IllegalBlockSizeException, BadPaddingException {
    return 0;
  }

}
TOP

Related Classes of org.apache.harmony.crypto.tests.support.MyCipher

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.