blob: 9bf9f592e89bc9765d9bcf3d56e685ad1c3bd70e [file] [log] [blame]
Alexander Afanasyev2fa59392016-07-29 17:24:23 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "util/crypto.hpp"
23
24#include "boost-test.hpp"
25
26namespace ndn {
27namespace crypto {
28namespace tests {
29
30BOOST_AUTO_TEST_SUITE(Util)
31BOOST_AUTO_TEST_SUITE(TestCrypto)
32
33BOOST_AUTO_TEST_CASE(Basic)
34{
35 const std::string testString = "Hello, world!";
36 ConstBufferPtr result;
37 BOOST_CHECK_NO_THROW(result = computeSha256Digest(reinterpret_cast<const uint8_t*>(testString.data()),
38 testString.size()));
39
40 BOOST_CHECK_EQUAL(result->size(), SHA256_DIGEST_SIZE);
41
42 const uint8_t expectedSha256[] = {0x31, 0x5f, 0x5b, 0xdb, 0x76, 0xd0, 0x78, 0xc4,
43 0x3b, 0x8a, 0xc0, 0x06, 0x4e, 0x4a, 0x01, 0x64,
44 0x61, 0x2b, 0x1f, 0xce, 0x77, 0xc8, 0x69, 0x34,
45 0x5b, 0xfc, 0x94, 0xc7, 0x58, 0x94, 0xed, 0xd3};
46 BOOST_CHECK_EQUAL_COLLECTIONS(result->begin(), result->end(),
47 expectedSha256, expectedSha256 + sizeof(expectedSha256));
48}
49
50BOOST_AUTO_TEST_SUITE_END() // TestCrypto
51BOOST_AUTO_TEST_SUITE_END() // Util
52
53} // namespace tests
54} // namespace crypto
55} // namespace ndn