// ---------------------------------------------------------------------------
// - Blkmsg.hpp                                                              -
// - afnix:sec module - base block message buffer class definition           -
// ---------------------------------------------------------------------------
// - This program is free software;  you can redistribute it  and/or  modify -
// - it provided that this copyright notice is kept intact.                  -
// -                                                                         -
// - This program  is  distributed in  the hope  that it will be useful, but -
// - without  any  warranty;  without  even   the   implied    warranty   of -
// - merchantability or fitness for a particular purpose.  In no event shall -
// - the copyright holder be liable for any  direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software.     -
// ---------------------------------------------------------------------------
// - copyright (c) 1999-2009 amaury darsch                                   -
// ---------------------------------------------------------------------------

#ifndef  AFNIX_BLKMSG_HPP
#define  AFNIX_BLKMSG_HPP

#ifndef  AFNIX_NAMEABLE_HPP
#include "Nameable.hpp"
#endif

#ifndef  AFNIX_INPUTSTREAM_HPP
#include "InputStream.hpp"
#endif

namespace afnix {

  /// The Blkmsg class is a base class designed to ease the management of
  /// the message block buffer used by various cryptographic components such
  /// like the hasher object. The main operation associated with a message
  /// block buffer is to fill a byte buffer upto a certain limit.
  /// @author amaury darsch

  class Blkmsg : public Nameable {
  protected:
    /// the block name
    String d_name;
    /// the buffer size
    long    d_size;
    /// the message low length
    t_octa  d_llen;
    /// the message upper length
    t_octa  d_ulen;
    /// the buffer count
    long    d_count;
    /// the buffer data
    t_byte* p_data;

  public:
    /// create a block buffer by name and size
    /// @param name the hasher name
    /// @param size the block size
    Blkmsg (const String& name, const long size);

    /// destroy the block buffer
    ~Blkmsg (void);

    /// @return the class name
    String repr (void) const;

    /// @return the buffer name
    String getname (void) const;

    /// reset this buffer
    virtual void reset (void);

    /// clear this buffer counter
    virtual void clear (void);

    /// @return the buffer size
    virtual long getsize (void) const;

    /// @return the buffer count
    virtual long getcount (void) const;

    /// @return the buffer low length
    virtual t_octa getllen (void) const;

    /// @return the buffer upper length
    virtual t_octa getulen (void) const;

    /// copy some data in the buffer by size
    /// @param data the data to copy in the buffer
    /// @param size the data size
    /// @return the number of copied bytes
    virtual long copy (const t_byte* data, const long size);

    /// copy some data in the buffer from a buffer
    /// @param buf the buffer used as input
    /// @return the number of copied bytes
    virtual long copy (Buffer& buf);

    /// copy some data in the buffer from a stream
    /// @param is the input stream used as input
    /// @return the number of copied bytes
    virtual long copy (InputStream& is);

  private:
    // make the copy constructor private
    Blkmsg (const Blkmsg&);
    // make the assignment operator private
    Blkmsg& operator = (const Blkmsg&);
  };
}

#endif
