Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame^] | 1 | package aQute.libg.cryptography; |
| 2 | |
| 3 | import java.io.*; |
| 4 | import java.security.*; |
| 5 | |
| 6 | |
| 7 | public 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) { |
| 21 | throw new IOException(e.getLocalizedMessage()); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | @Override |
| 26 | public void write( int b) throws IOException { |
| 27 | try { |
| 28 | signature.update((byte) b); |
| 29 | } catch (SignatureException e) { |
| 30 | throw new IOException(e.getLocalizedMessage()); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public boolean verify() throws Exception { |
| 35 | return signature.verify(d.digest()); |
| 36 | } |
| 37 | |
| 38 | } |