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/** 19* @author Vera Y. Petrashkova 20* @version $Revision$ 21*/ 22 23package org.apache.harmony.crypto.tests.support; 24 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.KeyAgreementSpi; 33import javax.crypto.SecretKey; 34import javax.crypto.ShortBufferException; 35 36/** 37 * Additional class for verification of KeyAgreementSpi 38 * and KeyAgreement functionality 39 * 40 */ 41 42public class MyKeyAgreementSpi extends KeyAgreementSpi { 43 44 @Override 45 protected Key engineDoPhase(Key key, boolean lastPhase) 46 throws InvalidKeyException, IllegalStateException { 47 if (!lastPhase) { 48 throw new IllegalStateException("last Phase is false"); 49 } 50 return null; 51 } 52 53 @Override 54 protected byte[] engineGenerateSecret() throws IllegalStateException { 55 return new byte[0]; 56 } 57 58 @Override 59 protected int engineGenerateSecret(byte[] sharedSecret, int offset) 60 throws IllegalStateException, ShortBufferException { 61 return -1; 62 } 63 64 @Override 65 protected SecretKey engineGenerateSecret(String algorithm) 66 throws IllegalStateException, NoSuchAlgorithmException, 67 InvalidKeyException { 68 if (algorithm.length() == 0) { 69 throw new NoSuchAlgorithmException("Algorithm is empty"); 70 } 71 return null; 72 } 73 74 @Override 75 protected void engineInit(Key key, SecureRandom random) 76 throws InvalidKeyException { 77 throw new IllegalArgumentException("Invalid parameter"); 78 } 79 80 @Override 81 protected void engineInit(Key key, AlgorithmParameterSpec params, 82 SecureRandom random) throws InvalidKeyException, 83 InvalidAlgorithmParameterException { 84 throw new IllegalArgumentException("Invalid parameter"); 85 } 86} 87