Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

WvCounterModeEncoder Class Reference

#include <wvcountermode.h>

Inheritance diagram for WvCounterModeEncoder:

Inheritance graph
[legend]
List of all members.

Detailed Description

A counter mode encryption encoder.


Public Member Functions

 WvCounterModeEncoder (WvEncoder *_keycrypt, const void *_counter, size_t _countersize)
 Create a new counter mode encoder / decoder.
void setcounter (const void *counter, size_t countersize)
 Sets the Counter mode auto-incrementing counter.
void getcounter (void *counter) const
 Stores the current counter in the supplied buffer.
size_t getcountersize () const
 Returns the counter size.
virtual void incrcounter ()
 Increments the counter.
bool isok () const
 Returns true if the encoder has not encountered an error.
bool isfinished () const
 Returns true if the encoder can no longer encode data.
WvString geterror () const
 Returns an error message if any is available.
bool encode (WvBuf &inbuf, WvBuf &outbuf, bool flush=false, bool finish=false)
 Reads data from the input buffer, encodes it, and writes the result to the output buffer.
bool flush (WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
 Flushes the encoder and optionally finishes it.
bool finish (WvBuf &outbuf)
 Tells the encoder that NO MORE DATA will ever be encoded.
bool reset ()
 Asks an encoder to reset itself to its initial state at creation time, if supported.
bool flushstrbuf (WvStringParm instr, WvBuf &outbuf, bool finish=false)
 Flushes data through the encoder from a string to a buffer.
bool flushstrstr (WvStringParm instr, WvString &outstr, bool finish=false)
 Flushes data through the encoder from a string to a string.
bool encodebufstr (WvBuf &inbuf, WvString &outstr, bool flush=false, bool finish=false)
 Encodes data from a buffer to a string.
bool flushbufstr (WvBuf &inbuf, WvString &outstr, bool finish=false)
 Flushes data through the encoder from a buffer to a string.
WvString strflushstr (WvStringParm instr, bool finish=false)
 Flushes data through the encoder from a string to a string.
WvString strflushbuf (WvBuf &inbuf, bool finish=false)
 Flushes data through the encoder from a buffer to a string.
bool flushmembuf (const void *inmem, size_t inlen, WvBuf &outbuf, bool finish=false)
 Flushes data through the encoder from memory to a buffer.
bool flushmemmem (const void *inmem, size_t inlen, void *outmem, size_t *outlen, bool finish=false)
 Flushes data through the encoder from memory to memory.
bool encodebufmem (WvBuf &inbuf, void *outmem, size_t *outlen, bool flush=false, bool finish=false)
 Encodes data from a buffer to memory.
bool flushbufmem (WvBuf &inbuf, void *outmem, size_t *outlen, bool finish=false)
 Flushes data through the encoder from a buffer to memory.
bool flushstrmem (WvStringParm instr, void *outmem, size_t *outlen, bool finish=false)
 Flushes data through the encoder from a string to memory.
WvString strflushmem (const void *inmem, size_t inlen, bool finish=false)
 Flushes data through the encoder from memory to a string.

Public Attributes

WvEncoderkeycrypt

Protected Member Functions

virtual bool _encode (WvBuf &inbuf, WvBuf &outbuf, bool flush)
 Template method implementation of encode().
void setnotok ()
 Sets 'okay' to false explicitly.
void seterror (WvStringParm message)
 Sets an error condition, then setnotok().
void seterror (WVSTRING_FORMAT_DECL)
 Sets an error condition, then setnotok().
void setfinished ()
 Sets 'finished' to true explicitly.
virtual bool _isok () const
 Template method implementation of isok().
virtual bool _isfinished () const
 Template method implementation of isfinished().
virtual WvString _geterror () const
 Template method implementation of geterror().
virtual bool _finish (WvBuf &outbuf)
 Template method implementation of finish().
virtual bool _reset ()
 Template method implementation of reset().

Protected Attributes

unsigned char * counter
size_t countersize
bool okay
bool finished
WvString errstr


Constructor & Destructor Documentation

WvCounterModeEncoder::WvCounterModeEncoder WvEncoder _keycrypt,
const void *  _counter,
size_t  _countersize
 

Create a new counter mode encoder / decoder.

_keycrypt : the underlying encoder for generating the keystream (note: takes ownership of this encoder) _counter : the initial counter value _countersize : the counter size, must equal crypto block size


Member Function Documentation

void WvCounterModeEncoder::setcounter const void *  counter,
size_t  countersize
 

Sets the Counter mode auto-incrementing counter.

counter : the counter countersize : the new counter size, must equal crypto block size

void WvCounterModeEncoder::getcounter void *  counter  )  const
 

Stores the current counter in the supplied buffer.

counter : the array that receives the counter

bool WvCounterModeEncoder::_encode WvBuf inbuf,
WvBuf outbuf,
bool  flush
[protected, virtual]
 

Template method implementation of encode().

Not called if any of the following cases are true:

  • okay == false
  • finished == true
  • in.used() == 0 && flush == false

All implementations MUST define this.

If you also override _isok() or _isfinished(), note that they will NOT be consulted when determining whether or not to invoke this function. This allows finer control over the semantics of isok() and isfinished() with respect to encode().

"inbuf" is the input buffer "outbuf" is the output buffer "flush" is if true, flushes the encoder Returns: true on success

See also:
encode

Implements WvEncoder.

bool WvEncoder::isok  )  const [inline, inherited]
 

Returns true if the encoder has not encountered an error.

This should only be used to record permanent failures. Transient errors (eg. bad block, but recoverable) should be detected in a different fashion.

Returns: true if the encoder is ok

bool WvEncoder::isfinished  )  const [inline, inherited]
 

Returns true if the encoder can no longer encode data.

This will be set when the encoder detects and end-of-data mark in its input, or when finish() is called.

Returns: true if the encoder is finished

WvString WvEncoder::geterror  )  const [inherited]
 

Returns an error message if any is available.

Returns: the error message, or the null string is isok() == true

bool WvEncoder::encode WvBuf inbuf,
WvBuf outbuf,
bool  flush = false,
bool  finish = false
[inherited]
 

Reads data from the input buffer, encodes it, and writes the result to the output buffer.

If flush == true, the input buffer will be drained and the output buffer will contain all of the encoded data including any that might have been buffered internally from previous calls. Thus it is possible that new data will be written to the output buffer even though the input buffer was empty when encode() was called. If the buffer could not be fully drained because there was insufficient data, this function returns false and leaves the remaining unflushed data in the buffer.

If flush == false, the encoder will read and encode as much data as possible (or as it convenient) from the input buffer and store the results in the output buffer. Partial results may be buffered internally by the encoder to be written to the output buffer later when the encoder is flushed.

If finish = true, the encode() will be followed up by a call to finish(). The return values will be ANDed together to yield the final result. Most useful when flush is also true.

If a permanent error occurs, then isok() will return false, this function will return false and the input buffer will be left in an undefined state.

If a recoverable error occurs, the encoder should discard the problematic data from the input buffer and return false from this function, but isok() will remain true.

A stream might become isfinished() == true if an encoder- specific end-of-data marker was detected in the input.

"inbuf" is the input buffer "outbuf" is the output buffer "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success

See also:
_encode for the actual implementation

bool WvEncoder::flush WvBuf inbuf,
WvBuf outbuf,
bool  finish = false
[inline, inherited]
 

Flushes the encoder and optionally finishes it.

"inbuf" is the input buffer "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success

bool WvEncoder::finish WvBuf outbuf  )  [inherited]
 

Tells the encoder that NO MORE DATA will ever be encoded.

The encoder will flush out any internally buffered data and write out whatever end-of-data marking it needs to the supplied output buffer before returning.

Clients should invoke flush() on the input buffer before finish() if the input buffer was not yet empty.

It is safe to call this function multiple times. The implementation will simply return isok() and do nothing else.

"outbuf" is the output buffer Returns: true on success

See also:
_finish for the actual implementation

bool WvEncoder::reset  )  [inherited]
 

Asks an encoder to reset itself to its initial state at creation time, if supported.

This function may be called at any time, even if isok() == false, or isfinished() == true.

If the behaviour is not supported or an error occurs, then false is returned and afterwards isok() == false.

Returns: true on success

See also:
_reset for the actual implementation

bool WvEncoder::flushstrbuf WvStringParm  instr,
WvBuf outbuf,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a string to a buffer.

"instr" is the input string "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success

bool WvEncoder::flushstrstr WvStringParm  instr,
WvString outstr,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a string to a string.

The output data is appended to the target string.

"instr" is the input string "outstr" is the output string "finish" is if true, calls finish() on success Returns: true on success

bool WvEncoder::encodebufstr WvBuf inbuf,
WvString outstr,
bool  flush = false,
bool  finish = false
[inherited]
 

Encodes data from a buffer to a string.

The output data is appended to the target string.

"inbuf" is the input buffer "outstr" is the output string "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success

bool WvEncoder::flushbufstr WvBuf inbuf,
WvString outstr,
bool  finish = false
[inline, inherited]
 

Flushes data through the encoder from a buffer to a string.

The output data is appended to the target string.

"inbuf" is the input buffer "outstr" is the output string "finish" is if true, calls finish() on success Returns: true on success

WvString WvEncoder::strflushstr WvStringParm  instr,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a string to a string.

"inbuf" is the input buffer "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors

WvString WvEncoder::strflushbuf WvBuf inbuf,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a buffer to a string.

"inbuf" is the input buffer "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors

bool WvEncoder::flushmembuf const void *  inmem,
size_t  inlen,
WvBuf outbuf,
bool  finish = false
[inherited]
 

Flushes data through the encoder from memory to a buffer.

"inmem" is the input data pointer "inlen" is the input data length "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success

bool WvEncoder::flushmemmem const void *  inmem,
size_t  inlen,
void *  outmem,
size_t *  outlen,
bool  finish = false
[inherited]
 

Flushes data through the encoder from memory to memory.

The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.

"inmem" is the input data pointer "inlen" is the input data length "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success

bool WvEncoder::encodebufmem WvBuf inbuf,
void *  outmem,
size_t *  outlen,
bool  flush = false,
bool  finish = false
[inherited]
 

Encodes data from a buffer to memory.

The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.

"inmem" is the input data pointer "inlen" is the input data length "outmem" is the output data pointer "outlen" is the output data length, by reference "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success

bool WvEncoder::flushbufmem WvBuf inbuf,
void *  outmem,
size_t *  outlen,
bool  finish = false
[inline, inherited]
 

Flushes data through the encoder from a buffer to memory.

The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.

"inbuf" is the input buffer "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success

bool WvEncoder::flushstrmem WvStringParm  instr,
void *  outmem,
size_t *  outlen,
bool  finish = false
[inherited]
 

Flushes data through the encoder from a string to memory.

The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.

"instr" is the input string "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success

WvString WvEncoder::strflushmem const void *  inmem,
size_t  inlen,
bool  finish = false
[inherited]
 

Flushes data through the encoder from memory to a string.

"inmem" is the input data pointer "inlen" is the input data length "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors

virtual bool WvEncoder::_isok  )  const [inline, protected, virtual, inherited]
 

Template method implementation of isok().

Not called if any of the following cases are true:

  • okay == false

Most implementations do not need to override this.

Returns: true if the encoder is ok

See also:
setnotok

Reimplemented in WvEncoderChain, WvOggSpeexEncoder, and WvOggSpeexDecoder.

virtual bool WvEncoder::_isfinished  )  const [inline, protected, virtual, inherited]
 

Template method implementation of isfinished().

Not called if any of the following cases are true:

  • finished == true

Most implementations do not need to override this.

Returns: true if the encoder is finished

See also:
setfinished

Reimplemented in WvEncoderChain.

virtual WvString WvEncoder::_geterror  )  const [inline, protected, virtual, inherited]
 

Template method implementation of geterror().

Not called if any of the following cases are true:

  • isok() == true
  • errstr is not null

Most implementations do not need to override this.

Returns: the error message, or the null string if _isok() == true

See also:
seterror

Reimplemented in WvEncoderChain, WvOggSpeexEncoder, and WvOggSpeexDecoder.

virtual bool WvEncoder::_finish WvBuf outbuf  )  [inline, protected, virtual, inherited]
 

Template method implementation of finish().

Not called if any of the following cases are true:

  • okay == false
  • finished == true

The encoder is marked finished AFTER this function exits.

Many implementations do not need to override this.

If you also override _isok() or _isfinished(), note that they will NOT be consulted when determining whether or not to invoke this function. This allows finer control over the semantics of isok() and isfinished() with respect to finish().

"outbuf" is the output buffer Returns: true on success

See also:
finish

Reimplemented in WvBase64Encoder, WvHMACDigest, WvEncoderChain, WvGzipEncoder, WvTypedEncoder< unsigned char, float >, WvTypedEncoder< float, unsigned char >, WvTypedEncoder< double, double >, WvTypedEncoder< IT, OT >, WvTypedEncoder< double, signed short int >, WvTypedEncoder< float, signed short int >, WvTypedEncoder< signed short int, float >, and WvTypedEncoder< signed short int, double >.

virtual bool WvEncoder::_reset  )  [inline, protected, virtual, inherited]
 

Template method implementation of reset().

When this method is invoked, the current local state will be okay == true and finished == false. If false is returned, then okay will be set to false.

May set a detailed error message if an error occurs.

Returns: true on success, false on error or if not supported

See also:
reset

Reimplemented in WvBackslashEncoder, WvBackslashDecoder, WvBase64Encoder, WvBase64Decoder, WvBlowfishEncoder, WvHMACDigest, WvNullEncoder, WvPassthroughEncoder, WvEncoderChain, WvRealToComplexFFTEncoder, WvComplexToRealFFTEncoder, WvPowerSpectrumEncoder, WvFunctorEncoder< IT, OT, FT >, WvGzipEncoder, WvHexEncoder, WvHexDecoder, WvRSAEncoder, WvWordWrapEncoder, WvFunctorEncoder< float, signed short int, WvPCMNormFloatToSigned16Functor >, WvFunctorEncoder< double, signed short int, WvPCMNormDoubleToSigned16Functor >, WvFunctorEncoder< float, signed short int, WvPCMUnnormFloatToSigned16Functor >, WvFunctorEncoder< signed short int, float, WvPCMSigned16ToNormFloatFunctor >, WvFunctorEncoder< signed short int, double, WvPCMSigned16ToNormDoubleFunctor >, and WvFunctorEncoder< signed short int, float, WvPCMSigned16ToUnnormFloatFunctor >.


Member Data Documentation

bool WvEncoder::okay [protected, inherited]
 

false iff setnotok() was called

bool WvEncoder::finished [protected, inherited]
 

true iff setfinished()/finish() was called

WvString WvEncoder::errstr [protected, inherited]
 

the error message


The documentation for this class was generated from the following files:
Generated on Sun Jul 10 15:30:35 2005 for WvStreams by  doxygen 1.4.0