1package org.bouncycastle.crypto.io;
2
3import java.io.IOException;
4import java.io.OutputStream;
5
6import org.bouncycastle.crypto.Mac;
7
8public class MacOutputStream
9    extends OutputStream
10{
11    protected Mac mac;
12
13    public MacOutputStream(
14        Mac          mac)
15    {
16        this.mac = mac;
17    }
18
19    public void write(int b)
20        throws IOException
21    {
22        mac.update((byte)b);
23    }
24
25    public void write(
26        byte[] b,
27        int off,
28        int len)
29        throws IOException
30    {
31        mac.update(b, off, len);
32    }
33
34    public byte[] getMac()
35    {
36        byte[] res = new byte[mac.getMacSize()];
37
38        mac.doFinal(res, 0);
39
40        return res;
41    }
42}
43