// ---------------------------------------------------------------------------
// - Md5.hpp                                                                 -
// - afnix cryptography - MD5 message digest 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-2005 amaury darsch                                   -
// ---------------------------------------------------------------------------

#ifndef  AFNIX_MD5_HPP
#define  AFNIX_MD5_HPP

#ifndef  AFNIX_DIGEST_HPP
#include "Digest.hpp"
#endif

namespace afnix {

  /// The Md5 class is a class that can be used to compute a message
  /// digest based on the MD5 algorithm. The algorithm used here is the
  /// one described by Ron Rivest in RFC 1321. This implementation is also
  /// very inspired from RFC 1321.
  /// @author amaury darsch

  class Md5 : public Digest {
  private:
    // MD5 ABCD states
    t_quad d_state[4];

  public:
    /// create an MD5 message digest
    Md5 (void);

    /// reset this digest
    void reset (void);

    /// update the message state with the buffer data
    void update (void);

    /// process a message by data and size
    /// @param data the data to process
    /// @param size the data size
    void process (const t_byte* data, const long size);

    /// process a message with an input stream
    /// @param is the input stream to process
    void process (Input& is);

    /// finish the message by padding the data
    void finish (void);

    /// @return the formatted message digest
    String format (void) const;

    /// compute a message digest from a string
    /// @param msg the string message to compute
    String compute (const String& msg);

    /// compute a message digest from an input stream
    /// @param is the input stream
    String compute (Input& is);

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

#endif
