/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2013-2017 Regents of the University of California.
 *
 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
 *
 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * ndn-cxx library 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.  See the GNU Lesser General Public License for more details.
 *
 * You should have received copies of the GNU General Public License and GNU Lesser
 * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
 */

#ifndef NDN_SECURITY_PIB_KEY_HPP
#define NDN_SECURITY_PIB_KEY_HPP

#include "certificate-container.hpp"
#include "../security-common.hpp"

namespace ndn {
namespace security {

namespace v2 {
class KeyChain;
} // namespace v2

namespace pib {

namespace detail {
class KeyImpl;
} // namespace detail

/**
 * @brief A frontend handle of a key instance
 *
 * Key is at the second level in PIB's Identity-Key-Certificate hierarchy.  A Key has a Name
 * (identity + "KEY" + keyId), and contains one or more certificates, one of which is set as
 * the default certificate of this key.  A certificate can be directly accessed from a Key
 * object.
 */
class Key
{
public:
  /**
   * @brief Default Constructor
   *
   * Key created using this default constructor is just a place holder.
   * It can obtain an actual instance from Identity::getKey(...).  A typical
   * usage would be for exception handling:
   *
   *   Key key;
   *   try {
   *     key = identity.getKey(...);
   *   }
   *   catch (const Pib::Error&) {
   *     ...
   *   }
   *
   * A Key instance created using this constructor is invalid. Calling a
   * member method on an invalid Key instance may cause an std::domain_error.
   */
  Key();

  /**
   * @brief Create a Key with a backend implementation @p impl.
   *
   * This method should only be used by KeyContainer.
   */
  explicit
  Key(weak_ptr<detail::KeyImpl> impl);

  /*
   * @brief Get key name.
   */
  const Name&
  getName() const;

  /**
   * @brief Get the name of the belonging identity.
   */
  const Name&
  getIdentity() const;

  /**
   * @brief Get key type.
   */
  KeyType
  getKeyType() const;

  /**
   * @brief Get public key bits.
   */
  const Buffer&
  getPublicKey() const;

  /**
   * @brief Get a certificate with @p certName
   * @throw std::invalid_argument @p certName does not match key name
   * @throw Pib::Error the certificate does not exist.
   */
  v2::Certificate
  getCertificate(const Name& certName) const;

  /**
   * @brief Get all certificates for this key.
   */
  const CertificateContainer&
  getCertificates() const;

  /**
   * @brief Get the default certificate for this Key.
   * @throw Pib::Error the default certificate does not exist.
   */
  const v2::Certificate&
  getDefaultCertificate() const;

  /**
   * @brief Check if the Key instance is valid.
   */
  explicit
  operator bool() const;

  /**
   * @brief Check if the Key instance is invalid.
   */
  bool
  operator!() const;

NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // write operations should be private
  /**
   * @brief Add @p certificate.
   * @throw std::invalid_argument certificate name does not match key name
   *
   * If a certificate with the same name (without implicit digest) already exists, overwrite
   * the certificate.
   */
  void
  addCertificate(const v2::Certificate& certificate) const;

  /**
   * @brief Remove a certificate with @p certName
   * @throw std::invalid_argument @p certName does not match key name
   */
  void
  removeCertificate(const Name& certName) const;

  /**
   * @brief Set an existing certificate with @p certName as the default certificate
   * @throw std::invalid_argument @p certName does not match key name
   * @throw Pib::Error the certificate does not exist.
   * @return the default certificate
   */
  const v2::Certificate&
  setDefaultCertificate(const Name& certName) const;

  /**
   * @brief Add @p certificate and set it as the default certificate of the key
   * @throw std::invalid_argument @p certificate does not match key name
   * @return the default certificate
   */
  const v2::Certificate&
  setDefaultCertificate(const v2::Certificate& certificate) const;

private:
  /**
   * @brief Check the validity of the instance
   * @return a shared_ptr when the instance is valid
   * @throw std::domain_error the instance is invalid
   */
  shared_ptr<detail::KeyImpl>
  lock() const;

private:
  weak_ptr<detail::KeyImpl> m_impl;

  friend class v2::KeyChain;
  friend bool operator!=(const Key&, const Key&);
};

bool
operator!=(const Key& lhs, const Key& rhs);

inline bool
operator==(const Key& lhs, const Key& rhs)
{
  return !(lhs != rhs);
}

std::ostream&
operator<<(std::ostream& os, const Key& key);

} // namespace pib

using pib::Key;

namespace v2 {

/**
 * @brief Construct key name based on the appropriate naming conventions
 */
Name
constructKeyName(const Name& identity, const name::Component& keyId);

/**
 * @brief Check if @p keyName follow the naming conventions for the key name
 */
bool
isValidKeyName(const Name& keyName);

/**
 * @brief Extract identity namespace from the key name @p keyName
 */
Name
extractIdentityFromKeyName(const Name& keyName);

} // namespace v2

} // namespace security
} // namespace ndn

#endif // NDN_SECURITY_PIB_KEY_HPP
