blob: c3210574f3490d89f00b10cdb90ca3f2cfd74215 [file] [log] [blame]
Yingdi Yu4270f202014-01-28 14:19:16 -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/verifier.hpp"
11#include <iostream>
12
13using namespace std;
14using namespace ndn;
15
16
17BOOST_AUTO_TEST_SUITE(TestSignedInterest)
18
19BOOST_AUTO_TEST_CASE (SignVerify)
20{
21 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
22
23 Name identityName("/test");
Yingdi Yu52e79532014-01-29 23:57:19 -080024 Name certificateName = keyChain.createIdentity(identityName);
Yingdi Yu4270f202014-01-28 14:19:16 -080025
26 Interest interest("/test/interest");
27 keyChain.signByIdentity(interest, identityName);
28
29 Block interestBlock(interest.wireEncode().wire(), interest.wireEncode().size());
30
31 Interest interest2;
32 interest2.wireDecode(interestBlock);
33
Yingdi Yu52e79532014-01-29 23:57:19 -080034 ptr_lib::shared_ptr<PublicKey> publicKey = keyChain.getPublicKeyFromTpm(keyChain.getDefaultKeyNameForIdentity(identityName));
Yingdi Yu4270f202014-01-28 14:19:16 -080035 bool result = Verifier::verifySignature(interest2, *publicKey);
36
37 BOOST_REQUIRE_EQUAL(result, true);
38}
39
40BOOST_AUTO_TEST_SUITE_END()