// ---------------------------------------------------------------------------
// - Hasher.hpp                                                              -
// - afnix:txt library - 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_HASHER_HPP
#define  AFNIX_HASHER_HPP

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

namespace afnix {

  /// The Hasher class is a class that can be used to compute a message
  /// digest. A message digest is a hash computation of a particular
  /// message. The hash agorithm is determined at the class construction.
  /// The default algorithm is the MD5 algorithm.
  /// @author amaury darsch

  class Hasher : public Object {
  public:
    /// the message hasher algorithm
    enum t_algo {
      MD5  = 0,  // the MD5 algorithm
      SHA1 = 1   // the SHA-1 algorithm
    };

  private:
    /// the hasher algorithm
    t_algo d_algo;
    /// the digest object
    Digest* p_hash;

  public:
    /// create a default hasher
    Hasher (void);

    /// create a hasher by type
    /// @param algo the hasher algorith to use
    Hasher (const t_algo algo);

    /// destroy hasher
    ~Hasher (void);

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

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

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

    /// evaluate a hasher data member
    /// @param robj  robj the current runnable
    /// @param nset  the current nameset    
    /// @param quark the quark to evaluate
    static Object* meval (Runnable* robj, Nameset* nset, const long quark);

    /// generate a new hasher object
    /// @param argv the argument vector
    static Object* mknew (Vector* argv);

    /// apply hasher object with a set of arguments and a quark
    /// @param robj  robj the current runnable
    /// @param nset  the current nameset    
    /// @param quark the quark to apply these arguments
    /// @param argv  the arguments to apply
    Object* apply (Runnable* robj, Nameset* nset, const long quark,
		   Vector* argv);

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

#endif
