blob: efec04f18ca19bd6ad08af6bdb4d6d29f6f2e872 [file] [log] [blame]
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +00001package aQute.libg.cryptography;
2
3import java.io.*;
4import java.security.*;
5
6
7public class Verifier extends OutputStream {
8 final Signature signature;
9 final Digest d;
10
11 Verifier(Signature s, Digest d) {
12 this.signature = s;
13 this.d = d;
14 }
15
16 @Override
17 public void write( byte[] buffer, int offset, int length) throws IOException {
18 try {
19 signature.update(buffer, offset, length);
20 } catch (SignatureException e) {
Stuart McCulloch08ef6ed2011-10-17 10:46:45 +000021 throw new IOException(e.getMessage());
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +000022 }
23 }
24
25 @Override
26 public void write( int b) throws IOException {
27 try {
28 signature.update((byte) b);
29 } catch (SignatureException e) {
Stuart McCulloch08ef6ed2011-10-17 10:46:45 +000030 throw new IOException(e.getMessage());
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +000031 }
32 }
33
34 public boolean verify() throws Exception {
35 return signature.verify(d.digest());
36 }
37
38}