1212import java .security .SignatureException ;
1313
1414import de .ntcomputer .crypto .hash .HashCondenser ;
15+ import de .ntcomputer .crypto .hash .ProgressListener ;
1516import net .i2p .crypto .eddsa .EdDSAEngine ;
1617import net .i2p .crypto .eddsa .EdDSAPublicKey ;
1718import net .i2p .crypto .eddsa .Utils ;
@@ -123,7 +124,7 @@ private boolean verifyLow(byte[] data, String signature) throws SignatureExcepti
123124 * @throws SignatureException if the given signature has an invalid format
124125 */
125126 public boolean verify (byte [] data , String signature ) throws NoSuchAlgorithmException , SignatureException {
126- return this .verifyLow (HashCondenser .getInstance ().compute (data ), signature );
127+ return this .verifyLow (HashCondenser .getInstance ().compute (data , null ), signature );
127128 }
128129
129130 /**
@@ -147,14 +148,15 @@ public boolean verify(String data, String signature) throws NoSuchAlgorithmExcep
147148 * @param source the data source
148149 * @param sourceSize the exact size of all data which will pass through the InputStream
149150 * @param signature a hexadecimal representation of the signature (generated by {@link Ed25519PrivateKey#sign(InputStream, long)}
151+ * @param listener a progress listener. Optional, may be null.
150152 * @return true if the signature is correct. False otherwise.
151153 * @throws IllegalArgumentException if sourceSize is not the correct size
152154 * @throws NoSuchAlgorithmException if the hash algorithm is not present on this machine
153155 * @throws IOException if an IO error occurs while reading the stream
154156 * @throws SignatureException if the given signature has an invalid format
155157 */
156- public boolean verify (InputStream source , long sourceSize , String signature ) throws IllegalArgumentException , NoSuchAlgorithmException , IOException , SignatureException {
157- return this .verifyLow (HashCondenser .getInstance ().compute (source , sourceSize ), signature );
158+ public boolean verify (InputStream source , long sourceSize , String signature , ProgressListener listener ) throws IllegalArgumentException , NoSuchAlgorithmException , IOException , SignatureException {
159+ return this .verifyLow (HashCondenser .getInstance ().compute (source , sourceSize , listener ), signature );
158160 }
159161
160162 /**
@@ -163,17 +165,18 @@ public boolean verify(InputStream source, long sourceSize, String signature) thr
163165 * @see #verify(InputStream, long, String)
164166 * @param source
165167 * @param signature a hexadecimal representation of the signature (generated by {@link Ed25519PrivateKey#sign(File)}
168+ * @param listener a progress listener. Optional, may be null.
166169 * @return true if the signature is correct. False otherwise.
167170 * @throws IOException if an IO error occurs while reading the file
168171 * @throws IllegalArgumentException if the file's size changes during computation
169172 * @throws NoSuchAlgorithmException if the hash algorithm is not present on this machine
170173 * @throws SignatureException if the given signature has an invalid format
171174 */
172- public boolean verify (File source , String signature ) throws IOException , IllegalArgumentException , NoSuchAlgorithmException , SignatureException {
175+ public boolean verify (File source , String signature , ProgressListener listener ) throws IOException , IllegalArgumentException , NoSuchAlgorithmException , SignatureException {
173176 if (!source .isFile ()) throw new FileNotFoundException (source .getAbsolutePath ());
174177 long fileSize = source .length ();
175178 try (InputStream is = new FileInputStream (source )) {
176- return this .verify (is , fileSize , signature );
179+ return this .verify (is , fileSize , signature , listener );
177180 }
178181 }
179182
@@ -183,14 +186,15 @@ public boolean verify(File source, String signature) throws IOException, Illegal
183186 *
184187 * @see #verifyFromFile(File, File)
185188 * @param source
189+ * @param listener a progress listener. Optional, may be null.
186190 * @return true if the signature is correct. False otherwise.
187191 * @throws IOException if an IO error occurs while reading a file
188192 * @throws IllegalArgumentException if the file's size changes during computation
189193 * @throws NoSuchAlgorithmException if the hash algorithm is not present on this machine
190194 * @throws SignatureException if the signature in the .sig file has an invalid format
191195 */
192- public boolean verifyFromFile (File source ) throws IOException , IllegalArgumentException , NoSuchAlgorithmException , SignatureException {
193- return this .verifyFromFile (source , new File (source , ".sig" ));
196+ public boolean verifyFromFile (File source , ProgressListener listener ) throws IOException , IllegalArgumentException , NoSuchAlgorithmException , SignatureException {
197+ return this .verifyFromFile (source , new File (source , ".sig" ), listener );
194198 }
195199
196200 /**
@@ -199,15 +203,16 @@ public boolean verifyFromFile(File source) throws IOException, IllegalArgumentEx
199203 * @see #verify(File, String)
200204 * @param source
201205 * @param signatureFile the file to write the signature to
206+ * @param listener a progress listener. Optional, may be null.
202207 * @return true if the signature is correct. False otherwise.
203208 * @throws IOException if an IO error occurs while reading a file
204209 * @throws IllegalArgumentException if the file's size changes during computation
205210 * @throws NoSuchAlgorithmException if the hash algorithm is not present on this machine
206211 * @throws SignatureException if the signature in the signature file has an invalid format
207212 */
208- public boolean verifyFromFile (File source , File signatureFile ) throws IOException , IllegalArgumentException , NoSuchAlgorithmException , SignatureException {
213+ public boolean verifyFromFile (File source , File signatureFile , ProgressListener listener ) throws IOException , IllegalArgumentException , NoSuchAlgorithmException , SignatureException {
209214 String signature = new String (Files .readAllBytes (signatureFile .toPath ()), StandardCharsets .UTF_8 );
210- return this .verify (source , signature );
215+ return this .verify (source , signature , listener );
211216 }
212217
213218}
0 commit comments