#pragma once

#include <string>
#include <memory>
#include <vector>
#include <map>

#include "security_db_record.hh"

class OCTETSTRING;
class CHARSTRING;

/*!
 * \class security_cache
 * \brief This class provides security record description for in memory security database. In memory mens there is no disk load/save mechanism
 */
class security_cache {
protected: /*! \protectedsection */
  // TODO Enforce with const security_cache_record, and const std::string
  std::map<std::string, std::unique_ptr<security_db_record> > _certificates; //! List of the certificates indexed by the certificate identifier
  std::map<std::vector<unsigned char>, std::string> _hashed_id8s; //! List of the certificates indexed by the HashedId8
  
public: /*! \publicsection */
  /*!
   * \brief Default ctor
   */
  security_cache();
  /*!
   * \brief Default private dtor
   */
  virtual ~security_cache();

  int get_certificate_id(const OCTETSTRING& p_hashed_id8, std::string& p_certificate_id) const;
  int get_certificate(const std::string& p_certificate_id, OCTETSTRING& p_certificate) const;
  int get_certificate(const std::string& p_certificate_id, IEEE1609dot2::CertificateBase& p_certificate) const;
  int get_issuer(const std::string& p_certificate_id, OCTETSTRING& p_hashed_id_issuer) const;
  int get_hashed_id(const std::string& p_certificate_id, OCTETSTRING& p_hashed_id) const;
  int get_private_key(const std::string& p_certificate_id, OCTETSTRING& p_private_key) const;
  int get_public_keys(const std::string& p_certificate_id, OCTETSTRING& p_public_key_x, OCTETSTRING& p_public_key_y) const;
  int get_private_enc_key(const std::string& p_certificate_id, OCTETSTRING& p_private_enc_key) const;
  int get_public_enc_keys(const std::string& p_certificate_id, OCTETSTRING& p_public_enc_key_x, OCTETSTRING& p_public_enc_key_y) const;

  virtual int store_certificate(const CHARSTRING& p_cert_id, const OCTETSTRING& p_cert, const OCTETSTRING& p_private_key, const OCTETSTRING& p_public_key_x, const OCTETSTRING& p_public_key_y, const OCTETSTRING& p_hashid8, const OCTETSTRING& p_issuer, const OCTETSTRING& p_private_enc_key, const OCTETSTRING& p_public_enc_key_x, const OCTETSTRING& p_public_enc_key_y);

  //virtual int store_certificate(const std::sring& p_cert_id, const std::vector<unsigned char>& p_cert, const std::vector<unsigned char>& p_private_key, const std::vector<unsigned char>& p_public_key_x, const std::vector<unsigned char>& p_public_key_y, const std::vector<unsigned char>& p_hashid8, const OCTETSTRING& p_issuer);
  virtual int clear();
  
  void dump() const;
  
}; // End of class security_cache
