01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.harmony.crypto.tests.support;
22:
23: import java.security.InvalidAlgorithmParameterException;
24: import java.security.InvalidKeyException;
25: import java.security.Key;
26: import java.security.NoSuchAlgorithmException;
27: import java.security.SecureRandom;
28: import java.security.spec.AlgorithmParameterSpec;
29:
30: import javax.crypto.KeyAgreementSpi;
31: import javax.crypto.SecretKey;
32: import javax.crypto.ShortBufferException;
33:
34: /**
35: * Additional class for verification of KeyAgreementSpi
36: * and KeyAgreement functionality
37: *
38: */
39:
40: public 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()
53: throws IllegalStateException {
54: return new byte[0];
55: }
56:
57: @Override
58: protected int engineGenerateSecret(byte[] sharedSecret, int offset)
59: throws IllegalStateException, ShortBufferException {
60: return -1;
61: }
62:
63: @Override
64: protected SecretKey engineGenerateSecret(String algorithm)
65: throws IllegalStateException, NoSuchAlgorithmException,
66: InvalidKeyException {
67: if (algorithm.length() == 0) {
68: throw new NoSuchAlgorithmException("Algorithm is empty");
69: }
70: return null;
71: }
72:
73: @Override
74: protected void engineInit(Key key, SecureRandom random)
75: throws InvalidKeyException {
76: throw new IllegalArgumentException("Invalid parameter");
77: }
78:
79: @Override
80: protected void engineInit(Key key, AlgorithmParameterSpec params,
81: SecureRandom random) throws InvalidKeyException,
82: InvalidAlgorithmParameterException {
83: throw new IllegalArgumentException("Invalid parameter");
84: }
85: }
|