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