#ifndef KEY_USER_CLASS
#define KEY_USER_CLASS

/*****************************************************************************\
*                                                                             *
*  Name   : key_user                                                          *
*  Author : Chris Koeritz                                                     *
*                                                                             *
*******************************************************************************
* Copyright (c) 2002-$now By Author.  This program is free software; you can  *
* redistribute it and/or modify it under the terms of the GNU General Public  *
* License as published by the Free Software Foundation; either version 2 of   *
* the License or (at your option) any later version.  This is online at:      *
*     http://www.fsf.org/copyleft/gpl.html                                    *
* Please send any updates to: fred@gruntose.com                               *
\*****************************************************************************/

//! Tracks the state and value of a key for use with the key_generator class.
/*!
  This object makes it a bit easier to track the keys that have been
  granted and to employ the keys for encryption and decryption.
*/

#include "crypto_dll.h"

// forward.
class ice_key;

class CRYPTO_CLASS_STYLE key_user
{
public:
  key_user();
  ~key_user();

  byte_array &current_key() const;
    //!< returns our current key that is being used for encryption.
  int stage() const { return _stage; }
    //!< provides information about our current state.
    /*!< if the "stage" is still zero, then the "current_key" will
    be invalid. */

  void update(int new_stage, const byte_array &new_key);
    //!< updates our internal information for a "new_key" and "new_stage".

  bool encrypt(const byte_array &to_encrypt, byte_array &encrypted);
    //!< encrypts "to_encrypt" with the current key and stores in "encrypted".
    /*!< uses the current key to flip information back and forth into
    encrypted and clear text formats. */
  bool decrypt(const byte_array &to_decrypt, byte_array &decrypted);
    //!< decrypts "to_decrypt" with the current key and stores in "decrypted".

private:
  int _stage;  //!< the current stage in generation.
  byte_array *_key;  //!< the current key value.
  ice_key *_crypt;  //!< encryption support based on current key.
};

#endif

