本文整理汇总了C++中KeyChain::verifyInterest方法的典型用法代码示例。如果您正苦于以下问题:C++ KeyChain::verifyInterest方法的具体用法?C++ KeyChain::verifyInterest怎么用?C++ KeyChain::verifyInterest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyChain
的用法示例。
在下文中一共展示了KeyChain::verifyInterest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MemoryIdentityStorage
TEST_F(TestInterestMethods, VerifyDigestSha256)
{
// Create a KeyChain but we don't need to add keys.
ptr_lib::shared_ptr<MemoryIdentityStorage> identityStorage
(new MemoryIdentityStorage());
KeyChain keyChain
(ptr_lib::make_shared<IdentityManager>
(identityStorage, ptr_lib::make_shared<MemoryPrivateKeyStorage>()),
ptr_lib::make_shared<SelfVerifyPolicyManager>(identityStorage.get()));
ptr_lib::shared_ptr<Interest> interest(new Interest(Name("/test/signed-interest")));
keyChain.signWithSha256(*interest);
VerifyCounter counter;
keyChain.verifyInterest
(interest, bind(&VerifyCounter::onVerified, &counter, _1),
// Cast to disambiguate from the deprecated OnVerifyInterestFailed.
(const OnInterestValidationFailed)bind
(&VerifyCounter::onInterestValidationFailed, &counter, _1, _2));
ASSERT_EQ(counter.onValidationFailedCallCount_, 0) << "Signature verification failed";
ASSERT_EQ(counter.onVerifiedCallCount_, 1) << "Verification callback was not used.";
}
示例2: main
int main(int argc, char** argv)
{
try {
Interest interest;
interest.wireDecode(TlvInterest, sizeof(TlvInterest));
cout << "Interest:" << endl;
dumpInterest(interest);
// Set the name again to clear the cached encoding so we encode again.
interest.setName(interest.getName());
Blob encoding = interest.wireEncode();
cout << endl << "Re-encoded interest " << encoding.toHex() << endl;
Interest reDecodedInterest;
reDecodedInterest.wireDecode(encoding);
cout << "Re-decoded Interest:" << endl;
dumpInterest(reDecodedInterest);
Interest freshInterest(Name("/ndn/abc"));
freshInterest.setMinSuffixComponents(4)
.setMaxSuffixComponents(6)
.setInterestLifetimeMilliseconds(30000)
.setChildSelector(1)
.setMustBeFresh(true);
freshInterest.getKeyLocator().setType(ndn_KeyLocatorType_KEY_LOCATOR_DIGEST);
uint8_t digest[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
freshInterest.getKeyLocator().setKeyData(Blob(digest, sizeof(digest)));
freshInterest.getExclude().appendComponent(Name("abc")[0]).appendAny();
ptr_lib::shared_ptr<MemoryIdentityStorage> identityStorage
(new MemoryIdentityStorage());
ptr_lib::shared_ptr<MemoryPrivateKeyStorage> privateKeyStorage
(new MemoryPrivateKeyStorage());
KeyChain keyChain
(ptr_lib::make_shared<IdentityManager>(identityStorage, privateKeyStorage),
ptr_lib::make_shared<SelfVerifyPolicyManager>(identityStorage.get()));
// Initialize the storage.
Name keyName("/testname/DSK-123");
Name certificateName = keyName.getSubName(0, keyName.size() - 1).append
("KEY").append(keyName[-1]).append("ID-CERT").append("0");
identityStorage->addKey
(keyName, KEY_TYPE_RSA, Blob(DEFAULT_RSA_PUBLIC_KEY_DER,
sizeof(DEFAULT_RSA_PUBLIC_KEY_DER)));
privateKeyStorage->setKeyPairForKeyName
(keyName, KEY_TYPE_RSA, DEFAULT_RSA_PUBLIC_KEY_DER,
sizeof(DEFAULT_RSA_PUBLIC_KEY_DER), DEFAULT_RSA_PRIVATE_KEY_DER,
sizeof(DEFAULT_RSA_PRIVATE_KEY_DER));
// Make a Face just so that we can sign the interest.
Face face("localhost");
face.setCommandSigningInfo(keyChain, certificateName);
face.makeCommandInterest(freshInterest);
ptr_lib::shared_ptr<Interest> reDecodedFreshInterest(new Interest());
reDecodedFreshInterest->wireDecode(freshInterest.wireEncode());
cout << endl << "Re-decoded fresh Interest:" << endl;
dumpInterest(*reDecodedFreshInterest);
keyChain.verifyInterest
(reDecodedFreshInterest, bind(&onVerified, "Freshly-signed Interest", _1),
bind(&onVerifyFailed, "Freshly-signed Interest", _1));
} catch (std::exception& e) {
cout << "exception: " << e.what() << endl;
}
return 0;
}