blob: daf359b97340e516cde4196c974fba76167f9ad8 [file] [log] [blame]
Yingdi Yu21157162014-02-28 13:02:34 -08001/**
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 Shi482ccc52014-03-31 13:05:24 -070012#include "security/cryptopp.hpp"
Yingdi Yu21157162014-02-28 13:02:34 -080013
14using namespace std;
15namespace ndn {
16
17BOOST_AUTO_TEST_SUITE(TestSignatureSha256)
18
19string SHA256_RESULT("a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4");
20
21BOOST_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
33BOOST_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
52BOOST_AUTO_TEST_SUITE_END()
53
54} // namespace ndn