Added dumpData
diff --git a/tests/test-encode-decode-data.cpp b/tests/test-encode-decode-data.cpp
index b328001..6599a1e 100644
--- a/tests/test-encode-decode-data.cpp
+++ b/tests/test-encode-decode-data.cpp
@@ -70,12 +70,64 @@
const ptime UNIX_EPOCH_TIME = ptime (date (1970, Jan, 1));
#endif
+static void dumpData(const Data &data)
+{
+ cout << "name: " << data.getName().to_uri() << endl;
+ if (data.getContent().size() > 0) {
+ cout << "content (raw): ";
+ for (unsigned int i = 0; i < data.getContent().size(); ++i)
+ cout << data.getContent()[i];
+ cout<< endl;
+ cout << "content (hex): " << toHex(data.getContent()) << endl;
+ }
+ else
+ cout << "content: <empty>" << endl;
+
+ cout << "signature.digestAlgorithm: "
+ << (data.getSignature().getDigestAlgorithm().size() > 0 ? toHex(data.getSignature().getDigestAlgorithm()).c_str() : "default (sha-256)") << endl;
+ cout << "signature.witness: "
+ << (data.getSignature().getWitness().size() > 0 ? toHex(data.getSignature().getWitness()).c_str() : "<none>") << endl;
+ cout << "signature.signature: ";
+ if (data.getSignature().getSignature().size() > 0)
+ cout << data.getSignature().getSignature().size() << " bytes" << endl;
+ else
+ cout << "<none>" << endl;
+
+ cout << "signedInfo.publisherPublicKeyDigest: "
+ << (data.getSignedInfo().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0 ?
+ toHex(data.getSignedInfo().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest()).c_str() : "<none>") << endl;
+ // TODO: dump timestamp.
+ cout << "signedInfo.freshnessSeconds: ";
+ if (data.getSignedInfo().getFreshnessSeconds() >= 0)
+ cout << data.getSignedInfo().getFreshnessSeconds() << endl;
+ else
+ cout << "<none>" << endl;
+ cout << "signedInfo.finalBlockID: "
+ << (data.getSignedInfo().getFinalBlockID().size() > 0 ?
+ toHex(data.getSignedInfo().getFinalBlockID()).c_str() : "<none>") << endl;
+ cout << "signedInfo.keyLocator: ";
+ if (data.getSignedInfo().getKeyLocator().getType() >= 0) {
+ if (data.getSignedInfo().getKeyLocator().getType() == ndn_KeyLocatorType_KEY)
+ cout << "Key: " << toHex(data.getSignedInfo().getKeyLocator().getKeyOrCertificate()) << endl;
+ else if (data.getSignedInfo().getKeyLocator().getType() == ndn_KeyLocatorType_CERTIFICATE)
+ cout << "Certificate: " << toHex(data.getSignedInfo().getKeyLocator().getKeyOrCertificate()) << endl;
+ else if (data.getSignedInfo().getKeyLocator().getType() == ndn_KeyLocatorType_KEYNAME)
+ // TODO: Implement keyName.
+ cout << "keyName" << endl;
+ else
+ cout << "<unrecognized ndn_KeyLocatorType " << data.getSignedInfo().getKeyLocator().getType() << ">" << endl;
+ }
+ else
+ cout << "<none>" << endl;
+}
+
int main(int argc, char** argv)
{
try {
Data data;
data.wireDecode(Data1, sizeof(Data1));
- cout << "Data name " << data.getName().to_uri() << endl;
+ cout << "Decoded Data:" << endl;
+ dumpData(data);
#if 0
ptime timestamp = UNIX_EPOCH_TIME + milliseconds(data.getSignedInfo().getTimestampMilliseconds());
cout << "Data timestamp " << timestamp.date().year() << "/" << timestamp.date().month() << "/" << timestamp.date().day()
@@ -83,15 +135,11 @@
#endif
ptr_lib::shared_ptr<vector<unsigned char> > encoding = data.wireEncode();
- cout << "Data encoding length " << encoding->size() << " vs. sizeof(Data1) " << sizeof(Data1) << endl;
Data reDecodedData;
reDecodedData.wireDecode(*encoding);
- cout << "Re-decoded Data name " << reDecodedData.getName().to_uri() << endl;
-#if 0
- timestamp = UNIX_EPOCH_TIME + milliseconds(reDecodedData.getSignedInfo().getTimestampMilliseconds());
- cout << "Re-decoded Data timestamp " << timestamp.date().year() << "/" << timestamp.date().month() << "/" << timestamp.date().day() << endl;
-#endif
+ cout << endl << "Re-decoded Data:" << endl;
+ dumpData(reDecodedData);
} catch (exception &e) {
cout << "exception: " << e.what() << endl;
}