iaik.utils
Class MacInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--iaik.utils.MacInputStream

public class MacInputStream
extends FilterInputStream

A stream implementation for MACing the data read from an input stream. This is similar to the java.security.DigestInputStream.

Version:
File Revision 5
See Also:
MacOutputStream, DigestInputStream

Field Summary
protected  Mac macEngine_
          The MAC engine to use for MACing the data.
protected  boolean macingActive_
          Indicates, if this objects sends data read from this stream to the Mac engine.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MacInputStream(InputStream stream, Mac macEngine)
          Creates a MAC input stream, using the specified input stream and MAC engine.
 
Method Summary
 Mac getMac()
          Get the MAC engine used for MACing the data.
 void on(boolean macingActive)
          Turns the MACing on or off.
 int read()
          This methods reads a byte fom the underlying stream and upadtes the MAC with this data, if the MACing is active.
 int read(byte[] dataByteArray, int offset, int length)
          This methods reads data bytes fom the underlying stream and upadtes the MAC with this data, if the MACing is active.
 void setMac(Mac macEngine)
          Set the MAC engine to use for MACing the data.
 String toString()
          Returns a string representation of this MAC output stream.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

macingActive_

protected boolean macingActive_
Indicates, if this objects sends data read from this stream to the Mac engine.

macEngine_

protected Mac macEngine_
The MAC engine to use for MACing the data.
Constructor Detail

MacInputStream

public MacInputStream(InputStream stream,
                      Mac macEngine)
Creates a MAC input stream, using the specified input stream and MAC engine.
Parameters:
stream - The input stream to read the data from.
macEngine - The MAC engine to use for MACing the data.
Method Detail

getMac

public Mac getMac()
Get the MAC engine used for MACing the data.
Returns:
The MAC engine used for MACing the data.

setMac

public void setMac(Mac macEngine)
Set the MAC engine to use for MACing the data.
Parameters:
macEngine - The MAC engine to use for MACing the data.

read

public int read()
         throws IOException
This methods reads a byte fom the underlying stream and upadtes the MAC with this data, if the MACing is active.
Overrides:
read in class FilterInputStream
Returns:
The data byte read from the underlying stream, or -1, if end of file is reached.
Throws:
IOException - If reading from the underlaying stream fails.

read

public int read(byte[] dataByteArray,
                int offset,
                int length)
         throws IOException
This methods reads data bytes fom the underlying stream and upadtes the MAC with this data, if the MACing is active.
Overrides:
read in class FilterInputStream
Parameters:
dataByteArray - The array receiving the new data bytes.
offset - The offset in the data byte array to start writing the data bytes.
length - The maximum number of bytes to read the stream.
Returns:
The actual number of bytes read from the stream or -1, if end of file was reached before reading the first byte.
Throws:
IOException - If reading from the underlaying stream fails.

on

public void on(boolean macingActive)
Turns the MACing on or off. If set to false, all data is just written through to the underlying stream but not to the MAC. Otherwise, if set to true, this object writes all data to the MAC as well as to the underlying stream.
Parameters:
macingActive - True, to MAC all data before writing to the underlying stream.

toString

public String toString()
Returns a string representation of this MAC output stream.
Overrides:
toString in class Object
Returns:
A string representation of this MAC output stream.

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK