// ---------------------------------------------------------------------------
// - Sha1.hpp                                                                -
// - afnix cryptography - Secure Hash Algorithm 1 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_SHA1_HPP
#define  AFNIX_SHA1_HPP

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

namespace afnix {

  /// The Sha1 class is a class that can be used to compute a message
  /// digest based on the Secure Hash Algorithm (SHA1) algorithm. 
  /// The algorithm used here is the one described by the Federal 
  /// Standard FIPS PUB 180-2. This is an original implementation
  /// similar to the description given in FIPS PUB 180-2.
  /// @author amaury darsch

  class Sha1 : public Digest {
  private:
    // SHA1 states
    t_quad d_state[5];

  public:
    /// create a message digest
    Sha1 (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
    Sha1 (const Sha1&);
    // make the assignment operator private
    Sha1& operator = (const Sha1&);
  };
}

#endif
