Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 791badb | 2017-02-03 02:03:18 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 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 | |
| 26 | namespace ndn { |
| 27 | namespace crypto { |
| 28 | namespace tests { |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(Util) |
| 31 | BOOST_AUTO_TEST_SUITE(TestCrypto) |
| 32 | |
| 33 | BOOST_AUTO_TEST_CASE(Basic) |
| 34 | { |
| 35 | const std::string testString = "Hello, world!"; |
Davide Pesavento | 791badb | 2017-02-03 02:03:18 -0500 | [diff] [blame] | 36 | auto result = computeSha256Digest(reinterpret_cast<const uint8_t*>(testString.data()), |
| 37 | testString.size()); |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 38 | |
| 39 | BOOST_CHECK_EQUAL(result->size(), SHA256_DIGEST_SIZE); |
| 40 | |
| 41 | const uint8_t expectedSha256[] = {0x31, 0x5f, 0x5b, 0xdb, 0x76, 0xd0, 0x78, 0xc4, |
| 42 | 0x3b, 0x8a, 0xc0, 0x06, 0x4e, 0x4a, 0x01, 0x64, |
| 43 | 0x61, 0x2b, 0x1f, 0xce, 0x77, 0xc8, 0x69, 0x34, |
| 44 | 0x5b, 0xfc, 0x94, 0xc7, 0x58, 0x94, 0xed, 0xd3}; |
| 45 | BOOST_CHECK_EQUAL_COLLECTIONS(result->begin(), result->end(), |
| 46 | expectedSha256, expectedSha256 + sizeof(expectedSha256)); |
| 47 | } |
| 48 | |
| 49 | BOOST_AUTO_TEST_SUITE_END() // TestCrypto |
| 50 | BOOST_AUTO_TEST_SUITE_END() // Util |
| 51 | |
| 52 | } // namespace tests |
| 53 | } // namespace crypto |
| 54 | } // namespace ndn |