blob: bb1b7561b797a475fb70a8281a465ab5d252d92c [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
12#include <cryptopp/base64.h>
13#include <cryptopp/hex.h>
14#include <cryptopp/files.h>
15
16using namespace std;
17namespace ndn {
18
19BOOST_AUTO_TEST_SUITE(TestSignatureSha256)
20
21string SHA256_RESULT("a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4");
22
23BOOST_AUTO_TEST_CASE (Sha256)
24{
25 using namespace CryptoPP;
26
27 char content[6] = "1234\n";
28 ConstBufferPtr buf = crypto::sha256(reinterpret_cast<uint8_t*>(content), 5);
29 string result;
30 StringSource(buf->buf(), buf->size(), true, new HexEncoder(new StringSink(result), false));
31
32 BOOST_REQUIRE_EQUAL(SHA256_RESULT, result);
33}
34
35BOOST_AUTO_TEST_CASE (Signature)
36{
37 using namespace CryptoPP;
38
39 Name name("/TestSignatureSha/Basic");
40 Data testData(name);
41 char content[5] = "1234";
42 testData.setContent(reinterpret_cast<uint8_t*>(content), 5);
43
44 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain;
45 keychain.signWithSha256(testData);
46
47 testData.wireEncode();
48
49 SignatureSha256 sig(testData.getSignature());
50
51 BOOST_REQUIRE(Validator::verifySignature(testData, sig));
52}
53
54BOOST_AUTO_TEST_SUITE_END()
55
56} // namespace ndn