blob: 82f7e1fc7f96f18ef125c1d5e4a867aaa20b2f68 [file] [log] [blame]
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +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 } catch (SignatureException e) {
Stuart McCulloch08ef6ed2011-10-17 10:46:45 +000019 throw new IOException(e.getMessage());
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +000020 }
21 }
22
23 @Override public void write(int b) throws IOException {
24 try {
25 signature.update((byte) b);
26 } catch (SignatureException e) {
Stuart McCulloch08ef6ed2011-10-17 10:46:45 +000027 throw new IOException(e.getMessage());
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +000028 }
29 }
30
31
32 public D signature() throws Exception {
33 return digester.digest(signature().digest());
34 }
35}