Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Yingdi Yu <yingdi0@cs.ucla.edu> |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include <boost/test/unit_test.hpp> |
| 8 | |
| 9 | #include "security/key-chain.hpp" |
| 10 | #include "security/validator.hpp" |
| 11 | |
Junxiao Shi | 482ccc5 | 2014-03-31 13:05:24 -0700 | [diff] [blame] | 12 | #include "security/cryptopp.hpp" |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 13 | |
| 14 | using namespace std; |
| 15 | namespace ndn { |
| 16 | |
| 17 | BOOST_AUTO_TEST_SUITE(TestSignatureSha256) |
| 18 | |
| 19 | string SHA256_RESULT("a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4"); |
| 20 | |
| 21 | BOOST_AUTO_TEST_CASE (Sha256) |
| 22 | { |
| 23 | using namespace CryptoPP; |
| 24 | |
| 25 | char content[6] = "1234\n"; |
| 26 | ConstBufferPtr buf = crypto::sha256(reinterpret_cast<uint8_t*>(content), 5); |
| 27 | string result; |
| 28 | StringSource(buf->buf(), buf->size(), true, new HexEncoder(new StringSink(result), false)); |
| 29 | |
| 30 | BOOST_REQUIRE_EQUAL(SHA256_RESULT, result); |
| 31 | } |
| 32 | |
| 33 | BOOST_AUTO_TEST_CASE (Signature) |
| 34 | { |
| 35 | using namespace CryptoPP; |
| 36 | |
| 37 | Name name("/TestSignatureSha/Basic"); |
| 38 | Data testData(name); |
| 39 | char content[5] = "1234"; |
| 40 | testData.setContent(reinterpret_cast<uint8_t*>(content), 5); |
| 41 | |
| 42 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain; |
| 43 | keychain.signWithSha256(testData); |
| 44 | |
| 45 | testData.wireEncode(); |
| 46 | |
| 47 | SignatureSha256 sig(testData.getSignature()); |
| 48 | |
| 49 | BOOST_REQUIRE(Validator::verifySignature(testData, sig)); |
| 50 | } |
| 51 | |
| 52 | BOOST_AUTO_TEST_SUITE_END() |
| 53 | |
| 54 | } // namespace ndn |