blob: 5218e2d0cc5b5b98cf7203987c853357069e2a52 [file] [log] [blame]
Stuart McCullochf3173222012-06-07 21:57:32 +00001package aQute.libg.cryptography;
2
3import java.io.*;
4import java.security.*;
5
6public class Signer<D extends Digest> extends OutputStream {
7 Signature signature;
8 Digester<D> digester;
9
10 Signer(Signature s, Digester<D> digester) {
11 this.signature = s;
12 this.digester = digester;
13 }
14
15 @Override public void write(byte[] buffer, int offset, int length) throws IOException {
16 try {
17 signature.update(buffer, offset, length);
18 digester.write(buffer, offset, length);
19 } catch (SignatureException e) {
20 throw new IOException(e.getLocalizedMessage());
21 }
22 }
23
24 @Override public void write(int b) throws IOException {
25 try {
26 signature.update((byte) b);
27 digester.write(b);
28 } catch (SignatureException e) {
29 throw new IOException(e.getLocalizedMessage());
30 }
31 }
32
33
34 public Signature signature() throws Exception {
35 return signature;
36 }
37
38 public D digest() throws Exception {
39 return digester.digest();
40 }
41}