1package org.bouncycastle.crypto.io;
2
3import java.io.FilterInputStream;
4import java.io.IOException;
5import java.io.InputStream;
6
7import org.bouncycastle.crypto.Mac;
8
9public class MacInputStream
10    extends FilterInputStream
11{
12    protected Mac mac;
13
14    public MacInputStream(
15        InputStream stream,
16        Mac         mac)
17    {
18        super(stream);
19        this.mac = mac;
20    }
21
22    public int read()
23        throws IOException
24    {
25        int b = in.read();
26
27        if (b >= 0)
28        {
29            mac.update((byte)b);
30        }
31        return b;
32    }
33
34    public int read(
35        byte[] b,
36        int off,
37        int len)
38        throws IOException
39    {
40        int n = in.read(b, off, len);
41        if (n >= 0)
42        {
43            mac.update(b, off, n);
44        }
45        return n;
46    }
47
48    public Mac getMac()
49    {
50        return mac;
51    }
52}
53