Celartem::ChecksumStream Class Reference

#include <cel_checksum.h>

Inheritance diagram for Celartem::ChecksumStream:

Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual void writeSum (Stream *inStream=NULL)=0
virtual bool verifySum (Stream *inStream=NULL)=0
virtual void resetSum ()=0
virtual const u8getCurrentSum ()=0
virtual size_t getSumSize () const =0


Detailed Description

This class calculates the sum of the data that is "read from" or "write to" this stream.
            // Writer sample
            void writeData(Stream *inStream)
            {
                AutoPtr<MD5Stream> md5 = MD5Stream::create(inStream);

                // write data as if it were the original stream.
                md5->writeBytes(...);
                md5->writeBytes(...);
                md5->writeBytes(...);

                // save the current MD5 sum
                md5->writeSum();
            }

            // Reader sample
            void readData(Stream *inStream)
            {
                AutoPtr<MD5Stream> md5 = MD5Stream::create(inStream);

                // read the data as if it were the original stream.
                // This should read the bytes exactly identical to the ones
                // written by writeData function, otherwise the verifySum
                // fails.
                md5->readBytes(...);
                md5->readBytes(...);
                md5->readBytes(...);

                // verify the current MD5 sum
                if(md5->verifySum())
                {
                    // The sum is identical
                }
                else
                {
                    // The sum is not identical
                }
            }

ChecksumStream defines an interface for the Stream with Checksum feature.

See also:
MD5Stream, SHA1Stream, SHA256Stream, Checksum

Definition at line 168 of file cel_checksum.h.


Member Function Documentation

virtual void Celartem::ChecksumStream::writeSum ( Stream inStream = NULL  )  [pure virtual]

This method writes the sum to the specified stream.

Parameters:
inStream A stream to write. NULL to write on this stream.

virtual bool Celartem::ChecksumStream::verifySum ( Stream inStream = NULL  )  [pure virtual]

This method verifies the sum which is read from the specified stream.

Parameters:
inStream A stream to read from. NULL to read from this stream.
Returns:
true if the sum read from the specified stream is match to the one of current sum, otherwise false.

virtual void Celartem::ChecksumStream::resetSum (  )  [pure virtual]

This method resets the current sum and revert to the initial state.

virtual const u8* Celartem::ChecksumStream::getCurrentSum (  )  [pure virtual]

This method gets the current sum as the binary block.

Returns:
Pointer that points the binary block. This pointer is valid until the next call to the method of the instance. The size of that block is obtained by getSumSize method.

virtual size_t Celartem::ChecksumStream::getSumSize (  )  const [pure virtual]

This method gets the size of sums in bytes that is generated by the instance. The size of sum is usually a constant; MD5 uses 16, SHA-1 uses 20.

Returns:
The size of sums.


The documentation for this class was generated from the following file:
This document is automatically generated using doxygen 1.5.4 at Fri Jun 27 18:23:14 2008.