Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
Signer | 33 | 0 | - | 0 | 0 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.crypto.signer; | |
21 | ||
22 | import java.io.FilterInputStream; | |
23 | import java.io.InputStream; | |
24 | import java.io.OutputStream; | |
25 | import java.security.GeneralSecurityException; | |
26 | ||
27 | /** | |
28 | * Interface on a signer engines ready to process data for signing or verification. | |
29 | * | |
30 | * @version $Id: 675eb0563d4ce474354596b38ceda75f3f603fe5 $ | |
31 | * @since 5.4RC1 | |
32 | */ | |
33 | public interface Signer | |
34 | { | |
35 | /** | |
36 | * @return the algorithm name of the underlying signer. | |
37 | */ | |
38 | String getAlgorithmName(); | |
39 | ||
40 | /** | |
41 | * @return true if the signer is initialised for signing, and false for verifying. | |
42 | */ | |
43 | boolean isForSigning(); | |
44 | ||
45 | /** | |
46 | * Return a pass through input stream, all data will be accumulated for calculating signatures. | |
47 | * | |
48 | * The signer is reset each time this function is called. | |
49 | * | |
50 | * @param is an input stream to read from and pass through. | |
51 | * @return a pass through input stream. | |
52 | */ | |
53 | FilterInputStream getInputStream(InputStream is); | |
54 | ||
55 | /** | |
56 | * Return a pass through output stream, all data will be accumulated for calculating signatures. | |
57 | * | |
58 | * The signer is reset each time this function is called. | |
59 | * | |
60 | * @return an output stream to this signer. | |
61 | */ | |
62 | OutputStream getOutputStream(); | |
63 | ||
64 | /** | |
65 | * Accumulate byte data to calculate signature. | |
66 | * | |
67 | * @param input a byte. | |
68 | */ | |
69 | void update(byte input); | |
70 | ||
71 | /** | |
72 | * Accumulate byte array data to calculate signature. | |
73 | * | |
74 | * @param input a byte array. | |
75 | */ | |
76 | void update(byte[] input); | |
77 | ||
78 | /** | |
79 | * Accumulate part of a byte array to calculate signature. | |
80 | * | |
81 | * @param input the input buffer. | |
82 | * @param inputOffset the offset in input where the input starts. | |
83 | * @param inputLen the input length. | |
84 | */ | |
85 | void update(byte[] input, int inputOffset, int inputLen); | |
86 | ||
87 | /** | |
88 | * Generate a signature for the accumulated data. | |
89 | * | |
90 | * The bytes that have been accumulated during a previous update or stream operations are signed. | |
91 | * | |
92 | * Upon finish, this method resets this signer. | |
93 | * | |
94 | * @return a buffer with the signature. | |
95 | * @throws GeneralSecurityException if this signing algorithm is unable to proceed properly. | |
96 | */ | |
97 | byte[] generate() throws GeneralSecurityException; | |
98 | ||
99 | /** | |
100 | * Generate a signature for the accumulated data, including the provided buffer. | |
101 | * | |
102 | * The bytes that have been accumulated during a previous update or stream operations appended with the given | |
103 | * input buffer are signed. | |
104 | * | |
105 | * Upon finish, this method resets this signer. | |
106 | * | |
107 | * @param input the input buffer. | |
108 | * @return a buffer with the signature. | |
109 | * @throws GeneralSecurityException if this signing algorithm is unable to proceed properly. | |
110 | */ | |
111 | byte[] generate(byte[] input) throws GeneralSecurityException; | |
112 | ||
113 | /** | |
114 | * Generate a signature for the accumulated data, including the part of the provided buffer. | |
115 | * | |
116 | * The bytes that have been accumulated during a previous update or stream operations appended with the first | |
117 | * inputLen bytes in the input buffer, starting at inputOffset inclusive, are signed. | |
118 | * | |
119 | * Upon finish, this method resets this signer. | |
120 | * | |
121 | * @param input the input buffer. | |
122 | * @param inputOffset the offset in input where the input starts. | |
123 | * @param inputLen the input length. | |
124 | * @return a buffer with the signature. | |
125 | * @throws GeneralSecurityException if this signing algorithm is unable to proceed properly. | |
126 | */ | |
127 | byte[] generate(byte[] input, int inputOffset, int inputLen) throws GeneralSecurityException; | |
128 | ||
129 | /** | |
130 | * Verify the given signature against the accumulated data. | |
131 | * | |
132 | * The bytes that have been accumulated during a previous update or stream operations are signed, and signatures | |
133 | * are compared. | |
134 | * | |
135 | * Upon finish, this method resets this signer. | |
136 | * | |
137 | * @param signature to be verified. | |
138 | * @return true if signatures are equals. | |
139 | * @throws GeneralSecurityException if this signing algorithm is unable to proceed properly. | |
140 | */ | |
141 | boolean verify(byte[] signature) throws GeneralSecurityException; | |
142 | ||
143 | /** | |
144 | * Verify the given signature against the accumulated data, including the provided buffer. | |
145 | * | |
146 | * The bytes that have been accumulated during a previous update or stream operations appended with the given input | |
147 | * buffer are signed, and signatures are compared. | |
148 | * | |
149 | * Upon finish, this method resets this signer. | |
150 | * | |
151 | * @param signature to be verified. | |
152 | * @param input the input buffer. | |
153 | * @return a buffer with the signature. | |
154 | * @throws GeneralSecurityException if this signing algorithm is unable to proceed properly. | |
155 | */ | |
156 | boolean verify(byte[] signature, byte[] input) throws GeneralSecurityException; | |
157 | ||
158 | /** | |
159 | * Verify the given signature against the accumulated data, including the part of the provided buffer. | |
160 | * | |
161 | * The bytes that have been accumulated during a previous update or stream operations appended with the first | |
162 | * inputLen bytes in the input buffer, starting at inputOffset inclusive, are signed, and signatures are compared. | |
163 | * | |
164 | * Upon finish, this method resets this signer. | |
165 | * | |
166 | * @param signature to be verified. | |
167 | * @param signOffset the offset in signature buffer where the signature starts. | |
168 | * @param signLen the signature length. | |
169 | * @param input the input buffer. | |
170 | * @param inputOffset the offset in input where the input starts. | |
171 | * @param inputLen the input length. | |
172 | * @return a buffer with the signature. | |
173 | * @throws GeneralSecurityException if this signing algorithm is unable to proceed properly. | |
174 | */ | |
175 | boolean verify(byte[] signature, int signOffset, int signLen, byte[] input, int inputOffset, int inputLen) | |
176 | throws GeneralSecurityException; | |
177 | ||
178 | /** | |
179 | * @return the algorithm identifier of this signer in encoded form. | |
180 | */ | |
181 | byte[] getEncoded(); | |
182 | } |