• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 * @author Boris V. Kuznetsov
19 * @version $Revision$
20 */
21 
22 package org.apache.harmony.security.tests.support;
23 
24 import java.security.InvalidKeyException;
25 import java.security.InvalidParameterException;
26 import java.security.PrivateKey;
27 import java.security.PublicKey;
28 import java.security.Signature;
29 import java.security.SignatureException;
30 
31 /**
32  * Tests implementation of Signature
33  *
34  */
35 public class MySignature1 extends Signature {
36 
37     public boolean runEngineInitVerify = false;
38     public boolean runEngineInitSign = false;
39     public boolean runEngineUpdate1 = false;
40     public boolean runEngineUpdate2 = false;
41     public boolean runEngineSign = false;
42     public boolean runEngineVerify = false;
43     public boolean runEngineSetParameter = false;
44     public boolean runEngineGetParameter = false;
45 
46     public static int SIGN = Signature.SIGN;
47     public static int VERIFY = Signature.VERIFY;
48     public static int UNINITIALIZED = Signature.UNINITIALIZED;
49     private final int BUFFER_LENGTH = 10;
50     /**
51      *
52      *
53      */
MySignature1()54     public MySignature1() {
55         super(null);
56     }
57 
58     /**
59      *
60      * @param algorithm
61      */
MySignature1(String algorithm)62     public MySignature1(String algorithm) {
63         super(algorithm);
64     }
65 
engineInitVerify(PublicKey publicKey)66     protected void engineInitVerify(PublicKey publicKey)
67             throws InvalidKeyException {
68         runEngineInitVerify = true;
69     }
70 
engineInitSign(PrivateKey privateKey)71     protected void engineInitSign(PrivateKey privateKey)
72             throws InvalidKeyException {
73         runEngineInitSign = true;
74     }
75 
engineUpdate(byte b)76     protected void engineUpdate(byte b) throws SignatureException {
77         runEngineUpdate1 = true;
78     }
79 
engineUpdate(byte[] b, int off, int len)80     protected void engineUpdate(byte[] b, int off, int len)
81             throws SignatureException {
82         if (b == null) throw new NullPointerException();
83         if (off < 0 || off > b.length || off > len) {
84             throw new IllegalArgumentException("incorrect parameter off");
85         }
86         if (len < 0 || len > b.length) {
87             throw new IllegalArgumentException("incorrect parameter len");
88         }
89         runEngineUpdate2 = true;
90     }
91 
engineSign()92     protected byte[] engineSign() throws SignatureException {
93         runEngineSign = true;
94         byte [] out = new byte [BUFFER_LENGTH];
95         return out;
96     }
97 
engineVerify(byte[] sigBytes)98     protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
99         runEngineVerify = true;
100         return false;
101     }
102 
engineSetParameter(String param, Object value)103     protected void engineSetParameter(String param, Object value)
104             throws InvalidParameterException {
105         runEngineSetParameter = true;
106     }
107 
engineGetParameter(String param)108     protected Object engineGetParameter(String param)
109             throws InvalidParameterException {
110         runEngineGetParameter = true;
111         return null;
112     }
113 
getState()114     public int getState() {
115         return state;
116     }
117 
getBufferLength()118     public int getBufferLength() {
119         return BUFFER_LENGTH;
120     }
121 }
122