blob: 2d030978bcfce662c38e555bb8bf4d62c5725126 [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;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080014namespace ndn {
Yingdi Yu4270f202014-01-28 14:19:16 -080015
16BOOST_AUTO_TEST_SUITE(TestSignedInterest)
17
18BOOST_AUTO_TEST_CASE (SignVerify)
19{
20 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
21
22 Name identityName("/test");
Yingdi Yu52e79532014-01-29 23:57:19 -080023 Name certificateName = keyChain.createIdentity(identityName);
Yingdi Yu4270f202014-01-28 14:19:16 -080024
25 Interest interest("/test/interest");
26 keyChain.signByIdentity(interest, identityName);
27
28 Block interestBlock(interest.wireEncode().wire(), interest.wireEncode().size());
29
30 Interest interest2;
31 interest2.wireDecode(interestBlock);
32
Yingdi Yu52e79532014-01-29 23:57:19 -080033 ptr_lib::shared_ptr<PublicKey> publicKey = keyChain.getPublicKeyFromTpm(keyChain.getDefaultKeyNameForIdentity(identityName));
Yingdi Yu4270f202014-01-28 14:19:16 -080034 bool result = Verifier::verifySignature(interest2, *publicKey);
35
36 BOOST_REQUIRE_EQUAL(result, true);
37}
38
39BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080040
41} // namespace ndn