Home | History | Annotate | Download | only in io
      1 package org.bouncycastle.crypto.io;
      2 
      3 import java.io.IOException;
      4 import java.io.OutputStream;
      5 
      6 import org.bouncycastle.crypto.Mac;
      7 
      8 public 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