01: package org.bouncycastle.crypto.io;
02:
03: import java.io.FilterInputStream;
04: import java.io.IOException;
05: import java.io.InputStream;
06:
07: import org.bouncycastle.crypto.Mac;
08:
09: public class MacInputStream extends FilterInputStream {
10: protected Mac mac;
11:
12: public MacInputStream(InputStream stream, Mac mac) {
13: super (stream);
14: this .mac = mac;
15: }
16:
17: public int read() throws IOException {
18: int b = in.read();
19:
20: if (b >= 0) {
21: mac.update((byte) b);
22: }
23: return b;
24: }
25:
26: public int read(byte[] b, int off, int len) throws IOException {
27: int n = in.read(b, off, len);
28: if (n >= 0) {
29: mac.update(b, off, n);
30: }
31: return n;
32: }
33:
34: public Mac getMac() {
35: return mac;
36: }
37: }
|