/* -*- 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.
 */

#include "security/digest-sha256.hpp"
#include "security/validator.hpp"
#include "util/string-helper.hpp"

#include "identity-management-fixture.hpp"
#include "boost-test.hpp"

namespace ndn {
namespace tests {

BOOST_AUTO_TEST_SUITE(Security)
BOOST_FIXTURE_TEST_SUITE(TestDigestSha256, IdentityManagementFixture)

BOOST_AUTO_TEST_CASE(Sha256)
{
  char content[6] = "1234\n";
  ConstBufferPtr buf = crypto::computeSha256Digest(reinterpret_cast<uint8_t*>(content), 5);

  BOOST_CHECK_EQUAL(toHex(buf->buf(), buf->size(), false),
                    "a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4");
}

BOOST_AUTO_TEST_CASE(DataSignature)
{
  Name name("/TestSignatureSha/Basic");
  Data testData(name);
  char content[5] = "1234";
  testData.setContent(reinterpret_cast<uint8_t*>(content), 5);

  m_keyChain.sign(testData, security::SigningInfo(security::SigningInfo::SIGNER_TYPE_SHA256));

  testData.wireEncode();

  DigestSha256 sig(testData.getSignature());

  BOOST_CHECK(Validator::verifySignature(testData, sig));

  BOOST_CHECK_THROW(sig.getKeyLocator(), ndn::SignatureInfo::Error);
}

BOOST_AUTO_TEST_CASE(InterestSignature)
{
  Name name("/SecurityTestDigestSha256/InterestSignature/Interest1");
  Interest testInterest(name);

  m_keyChain.sign(testInterest, security::SigningInfo(security::SigningInfo::SIGNER_TYPE_SHA256));
  testInterest.wireEncode();
  const Name& signedName = testInterest.getName();

  Signature signature(signedName[signed_interest::POS_SIG_INFO].blockFromValue(),
                      signedName[signed_interest::POS_SIG_VALUE].blockFromValue());
  DigestSha256 sig(signature);
  BOOST_CHECK(Validator::verifySignature(testInterest, sig));
}

BOOST_AUTO_TEST_SUITE_END() // TestDigestSha256
BOOST_AUTO_TEST_SUITE_END() // Security

} // namespace tests
} // namespace ndn
