IAIK PKCS#11 Provider API Documentation
version 1.6

iaik.pkcs.pkcs11.provider.signatures
Class SignatureOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by iaik.pkcs.pkcs11.provider.signatures.SignatureOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class SignatureOutputStream
extends java.io.FilterOutputStream

This class implements a streaming version of a signature engine. It passes through all date written to this stream to the underlying stream and signs or verifies this passed through data. It is similar to the java.security.DigestOutputStream.

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

Constructor Summary
SignatureOutputStream(java.io.OutputStream 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 signed 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 isStreamClosed()
          Check, if this stream has been closed; i.e. if close() has been called.
 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.
 void write(byte[] buffer)
          Write some bytes from the given buffer to the underlying output stream and updates the signature engine, if the signing function is on.
 void write(byte[] buffer, int offset, int length)
          Write some bytes from the given buffer to the underlying output stream and updates the signature engine, if the signing function is on.
 void write(int dataByte)
          Writes a byte to the underlying input stream and updates the signature engine, if the signing function is on.
 
Methods inherited from class java.io.FilterOutputStream
flush
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SignatureOutputStream

public SignatureOutputStream(java.io.OutputStream 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)

write

public void write(int dataByte)
           throws java.io.IOException
Writes a byte to 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:
write in class java.io.FilterOutputStream
Parameters:
dataByte - The byte to be written.
Throws:
java.io.IOException - if writing to the underlying stream fails or if updating the signature fails.
See Also:
Signature.update(byte)

write

public void write(byte[] buffer,
                  int offset,
                  int length)
           throws java.io.IOException
Write some bytes from the given buffer to the underlying output stream and updates the signature engine, if the signing function is on.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
buffer - The buffer holding the data to write.
offset - The offset where to start getting bytes from the buffer.
length - The maximum number of bytes to read from the buffer and write to the stream.
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)

write

public void write(byte[] buffer)
           throws java.io.IOException
Write some bytes from the given buffer to the underlying output stream and updates the signature engine, if the signing function is on.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
buffer - The buffer holding the data to write.
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)

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 the 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.

getBytesProcessed

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

Returns:
The number of bytes that have been signed 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.FilterOutputStream
Throws:
java.io.IOException - If closing the underlying stream fails.
See Also:
SignatureOutputStream(OutputStream, Signature, boolean), OutputStream.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