Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -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/verifier.hpp" |
| 11 | #include <iostream> |
| 12 | |
| 13 | using namespace std; |
| 14 | using namespace ndn; |
| 15 | |
| 16 | |
| 17 | BOOST_AUTO_TEST_SUITE(TestSignedInterest) |
| 18 | |
| 19 | BOOST_AUTO_TEST_CASE (SignVerify) |
| 20 | { |
| 21 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain; |
| 22 | |
| 23 | Name identityName("/test"); |
| 24 | Name keyName = keyChain.createIdentity(identityName); |
| 25 | |
| 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 | |
| 34 | ptr_lib::shared_ptr<PublicKey> publicKey = keyChain.getPublicKeyFromTpm(keyName); |
| 35 | bool result = Verifier::verifySignature(interest2, *publicKey); |
| 36 | |
| 37 | BOOST_REQUIRE_EQUAL(result, true); |
| 38 | } |
| 39 | |
| 40 | BOOST_AUTO_TEST_SUITE_END() |