IAIK PKCS#11 Provider API Documentation
version 1.6

iaik.pkcs.pkcs11.provider.signatures
Class SignatureInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by iaik.pkcs.pkcs11.provider.signatures.SignatureInputStream
All Implemented Interfaces:
java.io.Closeable

public class SignatureInputStream
extends java.io.FilterInputStream

This class implements a streaming version of a signature engine. It passes through an input stream and signs orverifies the passed through data. It is similar to the java.security.DigestInputStream.

Author:
Karl Scheibelhofer
See Also:
Signature, DigestInputStream
Invariants
(in <> null) and (signatureEngine_ <> null)

Constructor Summary
SignatureInputStream(java.io.InputStream data, java.security.Signature signatureEngine, boolean passThroughClose)
          Creates a streaming signature engine that reads its data from the provided stream.
 
Method Summary
 int clearBytesProcessed()
          Set the number of bytes that have been read so far to zero.
 void close()
          Close this stream and also the underlying stream if this has been specified at stream construction.
 int getBytesProcessed()
          Return the number of bytes that have been read so far.
 java.security.Signature getSignature()
          Get the signature engine used by this stream.
 boolean isOn()
          Check if the signing/verification functionality is on or off.
 boolean isStreamAtEOF()
          Check, if this input stream has been read until EOF.
 boolean isStreamClosed()
          Check, if this stream has been closed; i.e. if close() has been called.
 int read()
          Reads a byte from the underlying input stream and updates the signature engine, if the signing function is on.
 int read(byte[] buffer)
          Reads some bytes from the underlying input stream into the given buffer and updates the signature engine, if the signing function is on.
 int read(byte[] buffer, int offset, int length)
          Reads some bytes from the underlying input stream into the given buffer and updates the signature engine, if the signing function is on.
 boolean setOn(boolean on)
          Switch the signing/verification functionality on or off.
 void setSignature(java.security.Signature signatureEngine)
          Set the signature engine used by this stream.
 java.lang.String toString()
          Get a string representation of this object for debugging.
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SignatureInputStream

public SignatureInputStream(java.io.InputStream data,
                            java.security.Signature signatureEngine,
                            boolean passThroughClose)
Creates a streaming signature engine that reads its data from the provided stream. It uses the given signature engine.

Parameters:
data - The input stream proving the data.
signatureEngine - The signature object used to create and verify signatures.
passThroughClose - If true, a call to close will ba passed through.
Preconditions
(data <> null) and (signatureEngine <> null)
Method Detail

getSignature

public java.security.Signature getSignature()
Get the signature engine used by this stream.

Returns:
The signature engien used by this stream.
See Also:
setSignature(java.security.Signature)
Postconditions
(result <> null)

setSignature

public void setSignature(java.security.Signature signatureEngine)
Set the signature engine used by this stream.

Parameters:
signatureEngine - The signature engine used by this stream.
See Also:
getSignature()
Preconditions
(signatureEngine <> null)

read

public int read()
         throws java.io.IOException
Reads a byte from the underlying input stream and updates the signature engine, if the signing function is on. After sending this byte to the signature engine, it returns it.

Overrides:
read in class java.io.FilterInputStream
Returns:
The byte read.
Throws:
java.io.IOException - if reading from the underlying stream fails or if updating the signature fails.
See Also:
Signature.update(byte)

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws java.io.IOException
Reads some bytes from the underlying input stream into the given buffer and updates the signature engine, if the signing function is on. After sending these bytes to the signature engine, it returns them.

Overrides:
read in class java.io.FilterInputStream
Parameters:
buffer - The data buffer to put the read byte to.
offset - The offset where to start putting bytes into the buffer.
length - The maximum number of bytes to read.
Returns:
The number of bytes that have actually been read and put into the buffer.
Throws:
java.io.IOException - if reading from the underlying stream fails or if updating the signature fails.
See Also:
Signature.update(byte[], int, int)
Preconditions
(buffer <> null) and ((offset + length) <= data.length)

read

public int read(byte[] buffer)
         throws java.io.IOException
Reads some bytes from the underlying input stream into the given buffer and updates the signature engine, if the signing function is on. After sending these bytes to the signature engine, it returns them.

Overrides:
read in class java.io.FilterInputStream
Parameters:
buffer - The data buffer to put the read byte to.
Returns:
The number of bytes that have actually been read and put into the buffer.
Throws:
java.io.IOException - if reading from the underlying stream fails or if updating the signature fails.
See Also:
Signature.update(byte[], int, int)
Preconditions
(buffer <> null)

isOn

public boolean isOn()
Check if the signing/verification functionality is on or off. If it is turned on, all data read from this stream is also passed to the signature engine. If it is off, the data is just passed through without passing it to the signature engine.

Returns:
boolean True, if signing/verification functionality is on.

setOn

public boolean setOn(boolean on)
Switch the signing/verification functionality on or off. If it is turned on, all data read from this stream is also passed to the signature engine. If it is off, the data is just passed through without passing it to the signature engine.

Parameters:
on - True, to switch the signing/verification functionality on, false, to switch it off.
Returns:
boolean The old value of the switch.

isStreamAtEOF

public boolean isStreamAtEOF()
Check, if this input stream has been read until EOF. This is the case if any read operation has returned -1 or has thrown an EOFException.

Returns:
boolean True, if the stream of this hash engine is at EOF.
Postconditions
(result <> null)

getBytesProcessed

public int getBytesProcessed()
Return the number of bytes that have been read so far.

Returns:
The number of bytes that have been read so far.
Postconditions
(result <> null)

clearBytesProcessed

public int clearBytesProcessed()
Set the number of bytes that have been read so far to zero.

Returns:
The old number of bytes that have been read so far before setting it to zero.
Postconditions
(result >= 0)

close

public void close()
           throws java.io.IOException
Close this stream and also the underlying stream if this has been specified at stream construction.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterInputStream
Throws:
java.io.IOException - If closing the underlying stream fails.
See Also:
SignatureInputStream(InputStream, Signature, boolean), InputStream.close()
Postconditions
(isStreamClosed() == true)

isStreamClosed

public boolean isStreamClosed()
Check, if this stream has been closed; i.e. if close() has been called.

Returns:
boolean True, if this stream has been closed.
Postconditions
(result <> null)

toString

public java.lang.String toString()
Get a string representation of this object for debugging.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of this object for debugging.
Postconditions
(result <> null)

IAIK PKCS#11 Provider API Documentation
version 1.6

IAIK JavaSecurity Website http://jce.iaik.tugraz.at/

IAIK at Graz University of Technology, Austria, Europe
Copyright 2001-2004, IAIK, Graz University of Technology, Inffeldgasse 16a, 8010 Graz, Austria. All Rights Reserved.
version 1.6