tests: Change to use verifyData with callbacks.
diff --git a/tests/test-encode-decode-data.cpp b/tests/test-encode-decode-data.cpp
index 0b80c0b..9d2db41 100644
--- a/tests/test-encode-decode-data.cpp
+++ b/tests/test-encode-decode-data.cpp
@@ -14,6 +14,11 @@
using namespace std;
using namespace ndn;
+using namespace func_lib;
+#if HAVE_STD_FUNCTION
+// In the std library, the placeholders are in a different namespace than boost.
+using namespace func_lib::placeholders;
+#endif
unsigned char Data1[] = {
0x04, 0x82, // NDN Data
@@ -122,7 +127,7 @@
cout << "Certificate: " << toHex(*signature->getKeyLocator().getKeyData()) << endl;
else if (signature->getKeyLocator().getType() == ndn_KeyLocatorType_KEYNAME) {
cout << "KeyName: " << signature->getKeyLocator().getKeyName().to_uri() << endl;
- cout << "metaInfo.keyLocator: ";
+ cout << "signature.keyLocator: ";
if ((int)signature->getKeyLocator().getKeyNameType() >= 0) {
bool showKeyNameData = true;
if (signature->getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST)
@@ -138,7 +143,8 @@
showKeyNameData = false;
}
if (showKeyNameData)
- cout << toHex(*signature->getKeyLocator().getKeyData()) << endl;
+ cout << (signature->getKeyLocator().getKeyData().size() > 0 ?
+ toHex(*signature->getKeyLocator().getKeyData()).c_str() : "<none>") << endl;
}
else
cout << "<no key digest>" << endl;
@@ -151,6 +157,16 @@
}
}
+static void onVerified(const char *prefix, const Data &data)
+{
+ cout << prefix << " signature verification: VERIFIED" << endl;
+}
+
+static void onVerifyFailed(const char *prefix)
+{
+ cout << prefix << " signature verification: FAILED" << endl;
+}
+
int main(int argc, char** argv)
{
try {
@@ -158,7 +174,6 @@
data.wireDecode(Data1, sizeof(Data1));
cout << "Decoded Data:" << endl;
dumpData(data);
- cout << "Decoded Data signature verification: " << (KeyChain::selfVerifyData(Data1, sizeof(Data1)) ? "VERIFIED" : "FAILED") << endl;
Blob encoding = data.wireEncode();
@@ -166,19 +181,27 @@
reDecodedData.wireDecode(*encoding);
cout << endl << "Re-decoded Data:" << endl;
dumpData(reDecodedData);
- cout << "Re-decoded Data signature verification: " << (KeyChain::selfVerifyData(&encoding->front(), encoding->size()) ? "VERIFIED" : "FAILED") << endl;
Data freshData(Name("/ndn/abc"));
const unsigned char freshContent[] = "SUCCESS!";
freshData.setContent(freshContent, sizeof(freshContent) - 1);
freshData.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0);
- KeyChain::defaultSign(freshData);
+ ptr_lib::shared_ptr<PrivateKeyStorage> privateKeyStorage(new PrivateKeyStorage());
+ ptr_lib::shared_ptr<IdentityManager> identityManager(new IdentityManager(privateKeyStorage));
+ KeyChain keyChain(identityManager);
+
+ keyChain.sign(freshData);
cout << endl << "Freshly-signed Data:" << endl;
dumpData(freshData);
Blob freshEncoding = freshData.wireEncode();
- cout << "Freshly-signed Data signature verification: " << (KeyChain::selfVerifyData(&freshEncoding->front(), freshEncoding->size()) ? "VERIFIED" : "FAILED") << endl;
- } catch (exception& e) {
+
+ // Do verification at the end because it uses callbacks.
+ cout << endl;
+ keyChain.verifyData(data, bind(&onVerified, "Decoded Data", _1), bind(&onVerifyFailed, "Decoded Data"));
+ keyChain.verifyData(reDecodedData, bind(&onVerified, "Re-decoded Data", _1), bind(&onVerifyFailed, "Re-decoded Data"));
+ keyChain.verifyData(freshData, bind(&onVerified, "Freshly-signed Data", _1), bind(&onVerifyFailed, "Freshly-signed Data"));
+ } catch (std::exception& e) {
cout << "exception: " << e.what() << endl;
}
return 0;