Move publisherPublicKeyDigest and keyLocator from MetaInfo to Signature.
diff --git a/ndn-cpp/c/data.h b/ndn-cpp/c/data.h
index 0226919..0990d86 100644
--- a/ndn-cpp/c/data.h
+++ b/ndn-cpp/c/data.h
@@ -14,6 +14,9 @@
extern "C" {
#endif
+/**
+ * An ndn_Signature struct holds the signature bits and other info representing the signature in a data packet.
+ */
struct ndn_Signature {
unsigned char *digestAlgorithm; /**< pointer to pre-allocated buffer. 0 for none.
* If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */
@@ -22,15 +25,25 @@
unsigned int witnessLength; /**< length of witness. 0 for none */
unsigned char *signature;
unsigned int signatureLength;
+ struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
+ struct ndn_KeyLocator keyLocator;
};
-static inline void ndn_Signature_initialize(struct ndn_Signature *self) {
+/**
+ * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm.
+ * @param self A pointer to the ndn_MetaInfo struct.
+ * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
+ * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
+ */
+static inline void ndn_Signature_initialize(struct ndn_Signature *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) {
self->digestAlgorithm = 0;
self->digestAlgorithmLength = 0;
self->witness = 0;
self->witnessLength = 0;
self->signature = 0;
self->signatureLength = 0;
+ ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
+ ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
}
typedef enum {
@@ -42,30 +55,27 @@
ndn_ContentType_NACK = 5
} ndn_ContentType;
+/**
+ * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
+ */
struct ndn_MetaInfo {
- struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
int freshnessSeconds; /**< -1 for none */
unsigned char *finalBlockID; /**< pointer to pre-allocated buffer. 0 for none */
unsigned int finalBlockIDLength; /**< length of finalBlockID. 0 for none */
- struct ndn_KeyLocator keyLocator;
};
/**
* Initialize the ndn_MetaInfo struct with values for none and the type to the default ndn_ContentType_DATA.
* @param self A pointer to the ndn_MetaInfo struct.
- * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
- * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
*/
static inline void ndn_MetaInfo_initialize
- (struct ndn_MetaInfo *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) {
- ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
+ (struct ndn_MetaInfo *self) {
self->type = ndn_ContentType_DATA;
self->freshnessSeconds = -1;
self->finalBlockID = 0;
self->finalBlockIDLength = 0;
- ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
}
struct ndn_Data {
@@ -82,16 +92,16 @@
* @param self A pointer to the ndn_Data struct.
* @param nameComponents The pre-allocated array of ndn_NameComponent.
* @param maxNameComponents The number of elements in the allocated nameComponents array.
- * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the metaInfo.keyLocator.
+ * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signature.keyLocator.
* @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
*/
static inline void ndn_Data_initialize
(struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents,
struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents)
{
- ndn_Signature_initialize(&self->signature);
+ ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents);
ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
- ndn_MetaInfo_initialize(&self->metaInfo, keyNameComponents, maxKeyNameComponents);
+ ndn_MetaInfo_initialize(&self->metaInfo);
self->content = 0;
self->contentLength = 0;
}
diff --git a/ndn-cpp/c/encoding/binary-xml-data.c b/ndn-cpp/c/encoding/binary-xml-data.c
index ebc9987..b07b7a4 100644
--- a/ndn-cpp/c/encoding/binary-xml-data.c
+++ b/ndn-cpp/c/encoding/binary-xml-data.c
@@ -56,7 +56,7 @@
return NDN_ERROR_success;
}
-static ndn_Error encodeSignedInfo(struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlEncoder *encoder)
+static ndn_Error encodeSignedInfo(struct ndn_Signature *signature, struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlEncoder *encoder)
{
if (metaInfo->type < 0)
return NDN_ERROR_success;
@@ -66,7 +66,7 @@
return error;
// This will skip encoding if there is no publisherPublicKeyDigest.
- if ((error = ndn_encodeBinaryXmlPublisherPublicKeyDigest(&metaInfo->publisherPublicKeyDigest, encoder)))
+ if ((error = ndn_encodeBinaryXmlPublisherPublicKeyDigest(&signature->publisherPublicKeyDigest, encoder)))
return error;
if ((error = ndn_BinaryXmlEncoder_writeOptionalTimeMillisecondsDTagElement
@@ -104,7 +104,7 @@
return error;
// This will skip encoding if there is no key locator.
- if ((error = ndn_encodeBinaryXmlKeyLocator(&metaInfo->keyLocator, encoder)))
+ if ((error = ndn_encodeBinaryXmlKeyLocator(&signature->keyLocator, encoder)))
return error;
if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
@@ -113,13 +113,13 @@
return NDN_ERROR_success;
}
-static ndn_Error decodeSignedInfo(struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlDecoder *decoder)
+static ndn_Error decodeSignedInfo(struct ndn_Signature *signature, struct ndn_MetaInfo *metaInfo, struct ndn_BinaryXmlDecoder *decoder)
{
ndn_Error error;
if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_SignedInfo)))
return error;
- if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&metaInfo->publisherPublicKeyDigest, decoder)))
+ if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&signature->publisherPublicKeyDigest, decoder)))
return error;
if (error= ndn_BinaryXmlDecoder_readOptionalTimeMillisecondsDTagElement
@@ -162,7 +162,7 @@
(decoder, ndn_BinaryXml_DTag_FinalBlockID, 0, &metaInfo->finalBlockID, &metaInfo->finalBlockIDLength)))
return error;
- if ((error = ndn_decodeOptionalBinaryXmlKeyLocator(&metaInfo->keyLocator, decoder)))
+ if ((error = ndn_decodeOptionalBinaryXmlKeyLocator(&signature->keyLocator, decoder)))
return error;
if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
@@ -186,7 +186,7 @@
if ((error = ndn_encodeBinaryXmlName(&data->name, encoder)))
return error;
- if ((error = encodeSignedInfo(&data->metaInfo, encoder)))
+ if ((error = encodeSignedInfo(&data->signature, &data->metaInfo, encoder)))
return error;
if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
@@ -216,7 +216,7 @@
return error;
}
else
- ndn_Signature_initialize(&data->signature);
+ ndn_Signature_initialize(&data->signature, data->signature.keyLocator.keyName.components, data->signature.keyLocator.keyName.maxComponents);
*signedFieldsBeginOffset = decoder->offset;
@@ -226,11 +226,11 @@
if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_SignedInfo, &gotExpectedTag)))
return error;
if (gotExpectedTag) {
- if ((error = decodeSignedInfo(&data->metaInfo, decoder)))
+ if ((error = decodeSignedInfo(&data->signature, &data->metaInfo, decoder)))
return error;
}
else
- ndn_MetaInfo_initialize(&data->metaInfo, data->metaInfo.keyLocator.keyName.components, data->metaInfo.keyLocator.keyName.maxComponents);
+ ndn_MetaInfo_initialize(&data->metaInfo);
// Require a Content element, but set allowNull to allow a missing BLOB.
if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
diff --git a/ndn-cpp/data.cpp b/ndn-cpp/data.cpp
index fd41020..68b4779 100644
--- a/ndn-cpp/data.cpp
+++ b/ndn-cpp/data.cpp
@@ -29,6 +29,9 @@
signatureStruct.signature = (unsigned char *)&signature_[0];
else
signatureStruct.signature = 0;
+
+ publisherPublicKeyDigest_.get(signatureStruct.publisherPublicKeyDigest);
+ keyLocator_.get(signatureStruct.keyLocator);
}
void Signature::set(const struct ndn_Signature& signatureStruct)
@@ -36,11 +39,12 @@
setVector(digestAlgorithm_, signatureStruct.digestAlgorithm, signatureStruct.digestAlgorithmLength);
setVector(witness_, signatureStruct.witness, signatureStruct.witnessLength);
setVector(signature_, signatureStruct.signature, signatureStruct.signatureLength);
+ publisherPublicKeyDigest_.set(signatureStruct.publisherPublicKeyDigest);
+ keyLocator_.set(signatureStruct.keyLocator);
}
void MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const
{
- publisherPublicKeyDigest_.get(metaInfoStruct.publisherPublicKeyDigest);
metaInfoStruct.timestampMilliseconds = timestampMilliseconds_;
metaInfoStruct.type = type_;
metaInfoStruct.freshnessSeconds = freshnessSeconds_;
@@ -50,18 +54,14 @@
metaInfoStruct.finalBlockID = (unsigned char *)&finalBlockID_[0];
else
metaInfoStruct.finalBlockID = 0;
-
- keyLocator_.get(metaInfoStruct.keyLocator);
}
void MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct)
{
- publisherPublicKeyDigest_.set(metaInfoStruct.publisherPublicKeyDigest);
timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds;
type_ = metaInfoStruct.type;
freshnessSeconds_ = metaInfoStruct.freshnessSeconds;
setVector(finalBlockID_, metaInfoStruct.finalBlockID, metaInfoStruct.finalBlockIDLength);
- keyLocator_.set(metaInfoStruct.keyLocator);
}
void Data::get(struct ndn_Data& dataStruct) const
diff --git a/ndn-cpp/data.hpp b/ndn-cpp/data.hpp
index 2bcc6aa..5d67f0f 100644
--- a/ndn-cpp/data.hpp
+++ b/ndn-cpp/data.hpp
@@ -14,6 +14,9 @@
namespace ndn {
+/**
+ * A Signature holds the signature bits and other info representing the signature in a data packet.
+ */
class Signature {
public:
/**
@@ -37,6 +40,12 @@
const std::vector<unsigned char>& getSignature() const { return signature_; }
std::vector<unsigned char>& getSignature() { return signature_; }
+
+ const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
+ PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
+
+ const KeyLocator& getKeyLocator() const { return keyLocator_; }
+ KeyLocator& getKeyLocator() { return keyLocator_; }
void setDigestAlgorithm(const std::vector<unsigned char>& digestAlgorithm) { digestAlgorithm_ = digestAlgorithm; }
void setDigestAlgorithm(const unsigned char *digestAlgorithm, unsigned int digestAlgorithmLength)
@@ -55,23 +64,34 @@
{
setVector(signature_, signature, signatureLength);
}
+
+ void setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
+
+ void setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
/**
- * Clear the digest algorithm, witness and signature fields.
+ * Clear all the fields.
*/
void clear()
{
digestAlgorithm_.clear();
witness_.clear();
signature_.clear();
+ publisherPublicKeyDigest_.clear();
+ keyLocator_.clear();
}
private:
std::vector<unsigned char> digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */
std::vector<unsigned char> witness_;
std::vector<unsigned char> signature_;
+ PublisherPublicKeyDigest publisherPublicKeyDigest_;
+ KeyLocator keyLocator_;
};
+/**
+ * An MetaInfo holds the meta info which is signed inside the data packet.
+ */
class MetaInfo {
public:
MetaInfo()
@@ -93,9 +113,6 @@
*/
void set(const struct ndn_MetaInfo& metaInfoStruct);
- const PublisherPublicKeyDigest& getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
- PublisherPublicKeyDigest& getPublisherPublicKeyDigest() { return publisherPublicKeyDigest_; }
-
double getTimestampMilliseconds() const { return timestampMilliseconds_; }
ndn_ContentType getType() const { return type_; }
@@ -105,11 +122,6 @@
const std::vector<unsigned char>& getFinalBlockID() const { return finalBlockID_; }
std::vector<unsigned char>& getFinalBlockID() { return finalBlockID_; }
- const KeyLocator& getKeyLocator() const { return keyLocator_; }
- KeyLocator& getKeyLocator() { return keyLocator_; }
-
- void setPublisherPublicKeyDigest(const PublisherPublicKeyDigest& publisherPublicKeyDigest) { publisherPublicKeyDigest_ = publisherPublicKeyDigest; }
-
void setTimestampMilliseconds(double timestampMilliseconds) { timestampMilliseconds_ = timestampMilliseconds; }
void setType(ndn_ContentType type) { type_ = type; }
@@ -122,15 +134,11 @@
setVector(finalBlockID_, finalBlockID, finalBlockIdLength);
}
- void setKeyLocator(const KeyLocator& keyLocator) { keyLocator_ = keyLocator; }
-
private:
- PublisherPublicKeyDigest publisherPublicKeyDigest_;
double timestampMilliseconds_; /**< milliseconds since 1/1/1970. -1 for none */
ndn_ContentType type_; /**< default is ndn_ContentType_DATA. -1 for none */
int freshnessSeconds_; /**< -1 for none */
std::vector<unsigned char> finalBlockID_; /** size 0 for none */
- KeyLocator keyLocator_;
};
class Data {
diff --git a/ndn-cpp/key.hpp b/ndn-cpp/key.hpp
index a3784f6..6cf449e 100644
--- a/ndn-cpp/key.hpp
+++ b/ndn-cpp/key.hpp
@@ -20,6 +20,16 @@
}
/**
+ * Clear the keyData and set the type to none.
+ */
+ void clear()
+ {
+ type_ = (ndn_KeyLocatorType)-1;
+ keyNameType_ = (ndn_KeyNameType)-1;
+ keyData_.clear();
+ }
+
+ /**
* Set the keyLocatorStruct to point to the values in this key locator, without copying any memory.
* WARNING: The resulting pointers in keyLocatorStruct are invalid after a further use of this object which could reallocate memory.
* @param keyLocatorStruct a C ndn_KeyLocator struct where the name components array is already allocated.
diff --git a/ndn-cpp/node.cpp b/ndn-cpp/node.cpp
index 1015bc3..7fb34fd 100644
--- a/ndn-cpp/node.cpp
+++ b/ndn-cpp/node.cpp
@@ -55,10 +55,10 @@
void Node::NdndIdFetcher::operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData)
{
- if (ndndIdData->getMetaInfo().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0) {
+ if (ndndIdData->getSignature().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0) {
// Set the ndndId_ and continue.
// TODO: If there are multiple connected hubs, the NDN ID is really stored per connected hub.
- info_->node_.ndndId_ = ndndIdData->getMetaInfo().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest();
+ info_->node_.ndndId_ = ndndIdData->getSignature().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest();
info_->node_.registerPrefixHelper(info_->prefix_, info_->onInterest_, info_->flags_);
}
// TODO: else need to log not getting the ndndId.
diff --git a/ndn-cpp/publisher-public-key-digest.hpp b/ndn-cpp/publisher-public-key-digest.hpp
index 3b8dd56..0a5a2c5 100644
--- a/ndn-cpp/publisher-public-key-digest.hpp
+++ b/ndn-cpp/publisher-public-key-digest.hpp
@@ -53,6 +53,14 @@
{
setVector(publisherPublicKeyDigest_, publisherPublicKeyDigest, publisherPublicKeyDigestLength);
}
+
+ /**
+ * Clear the publisherPublicKeyDigest.
+ */
+ void clear()
+ {
+ publisherPublicKeyDigest_.clear();
+ }
private:
std::vector<unsigned char> publisherPublicKeyDigest_;
diff --git a/ndn-cpp/security/key-chain.cpp b/ndn-cpp/security/key-chain.cpp
index 6a44aa1..a9248df 100644
--- a/ndn-cpp/security/key-chain.cpp
+++ b/ndn-cpp/security/key-chain.cpp
@@ -89,12 +89,12 @@
(Data& data, const unsigned char *publicKeyDer, unsigned int publicKeyDerLength,
const unsigned char *privateKeyDer, unsigned int privateKeyDerLength, WireFormat& wireFormat)
{
- // Set the public key.
- setSha256(publicKeyDer, publicKeyDerLength, data.getMetaInfo().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest());
- data.getMetaInfo().getKeyLocator().setType(ndn_KeyLocatorType_KEY);
- data.getMetaInfo().getKeyLocator().setKeyData(publicKeyDer, publicKeyDerLength);
// Clear the signature so we don't encode it below.
data.getSignature().clear();
+ // Set the public key.
+ setSha256(publicKeyDer, publicKeyDerLength, data.getSignature().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest());
+ data.getSignature().getKeyLocator().setType(ndn_KeyLocatorType_KEY);
+ data.getSignature().getKeyLocator().setKeyData(publicKeyDer, publicKeyDerLength);
// Sign the fields.
unsigned char dataFieldsDigest[SHA256_DIGEST_LENGTH];
@@ -142,9 +142,9 @@
// Find the public key.
const unsigned char *publicKeyDer;
unsigned int publicKeyDerLength;
- if (data.getMetaInfo().getKeyLocator().getType() == ndn_KeyLocatorType_KEY) {
- publicKeyDer = &data.getMetaInfo().getKeyLocator().getKeyData().front();
- publicKeyDerLength = data.getMetaInfo().getKeyLocator().getKeyData().size();
+ if (data.getSignature().getKeyLocator().getType() == ndn_KeyLocatorType_KEY) {
+ publicKeyDer = &data.getSignature().getKeyLocator().getKeyData().front();
+ publicKeyDerLength = data.getSignature().getKeyLocator().getKeyData().size();
}
else
// Can't find a public key.
diff --git a/tests/test-encode-decode-data.cpp b/tests/test-encode-decode-data.cpp
index cf9a352..5943890 100644
--- a/tests/test-encode-decode-data.cpp
+++ b/tests/test-encode-decode-data.cpp
@@ -72,9 +72,6 @@
else
cout << "content: <empty>" << endl;
- cout << "metaInfo.publisherPublicKeyDigest: "
- << (data.getMetaInfo().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0 ?
- toHex(data.getMetaInfo().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest()).c_str() : "<none>") << endl;
cout << "metaInfo.timestamp: ";
if (data.getMetaInfo().getTimestampMilliseconds() >= 0) {
time_t seconds = data.getMetaInfo().getTimestampMilliseconds() / 1000.0;
@@ -103,40 +100,6 @@
cout << "metaInfo.finalBlockID: "
<< (data.getMetaInfo().getFinalBlockID().size() > 0 ?
toHex(data.getMetaInfo().getFinalBlockID()).c_str() : "<none>") << endl;
- cout << "metaInfo.keyLocator: ";
- if ((int)data.getMetaInfo().getKeyLocator().getType() >= 0) {
- if (data.getMetaInfo().getKeyLocator().getType() == ndn_KeyLocatorType_KEY)
- cout << "Key: " << toHex(data.getMetaInfo().getKeyLocator().getKeyData()) << endl;
- else if (data.getMetaInfo().getKeyLocator().getType() == ndn_KeyLocatorType_CERTIFICATE)
- cout << "Certificate: " << toHex(data.getMetaInfo().getKeyLocator().getKeyData()) << endl;
- else if (data.getMetaInfo().getKeyLocator().getType() == ndn_KeyLocatorType_KEYNAME) {
- cout << "KeyName: " << data.getMetaInfo().getKeyLocator().getKeyName().to_uri() << endl;
- cout << "metaInfo.keyLocator: ";
- if ((int)data.getMetaInfo().getKeyLocator().getKeyNameType() >= 0) {
- bool showKeyNameData = true;
- if (data.getMetaInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST)
- cout << "PublisherPublicKeyDigest: ";
- else if (data.getMetaInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST)
- cout << "PublisherCertificateDigest: ";
- else if (data.getMetaInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST)
- cout << "PublisherIssuerKeyDigest: ";
- else if (data.getMetaInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST)
- cout << "PublisherIssuerCertificateDigest: ";
- else {
- cout << "<unrecognized ndn_KeyNameType " << data.getMetaInfo().getKeyLocator().getKeyNameType() << ">" << endl;
- showKeyNameData = false;
- }
- if (showKeyNameData)
- cout << toHex(data.getMetaInfo().getKeyLocator().getKeyData()) << endl;
- }
- else
- cout << "<no key digest>" << endl;
- }
- else
- cout << "<unrecognized ndn_KeyLocatorType " << data.getMetaInfo().getKeyLocator().getType() << ">" << endl;
- }
- else
- cout << "<none>" << endl;
cout << "signature.digestAlgorithm: "
<< (data.getSignature().getDigestAlgorithm().size() > 0 ? toHex(data.getSignature().getDigestAlgorithm()).c_str() : "default (sha-256)") << endl;
@@ -144,6 +107,43 @@
<< (data.getSignature().getWitness().size() > 0 ? toHex(data.getSignature().getWitness()).c_str() : "<none>") << endl;
cout << "signature.signature: "
<< (data.getSignature().getSignature().size() > 0 ? toHex(data.getSignature().getSignature()).c_str() : "<none>") << endl;
+ cout << "signature.publisherPublicKeyDigest: "
+ << (data.getSignature().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() > 0 ?
+ toHex(data.getSignature().getPublisherPublicKeyDigest().getPublisherPublicKeyDigest()).c_str() : "<none>") << endl;
+ cout << "signature.keyLocator: ";
+ if ((int)data.getSignature().getKeyLocator().getType() >= 0) {
+ if (data.getSignature().getKeyLocator().getType() == ndn_KeyLocatorType_KEY)
+ cout << "Key: " << toHex(data.getSignature().getKeyLocator().getKeyData()) << endl;
+ else if (data.getSignature().getKeyLocator().getType() == ndn_KeyLocatorType_CERTIFICATE)
+ cout << "Certificate: " << toHex(data.getSignature().getKeyLocator().getKeyData()) << endl;
+ else if (data.getSignature().getKeyLocator().getType() == ndn_KeyLocatorType_KEYNAME) {
+ cout << "KeyName: " << data.getSignature().getKeyLocator().getKeyName().to_uri() << endl;
+ cout << "metaInfo.keyLocator: ";
+ if ((int)data.getSignature().getKeyLocator().getKeyNameType() >= 0) {
+ bool showKeyNameData = true;
+ if (data.getSignature().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST)
+ cout << "PublisherPublicKeyDigest: ";
+ else if (data.getSignature().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST)
+ cout << "PublisherCertificateDigest: ";
+ else if (data.getSignature().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST)
+ cout << "PublisherIssuerKeyDigest: ";
+ else if (data.getSignature().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST)
+ cout << "PublisherIssuerCertificateDigest: ";
+ else {
+ cout << "<unrecognized ndn_KeyNameType " << data.getSignature().getKeyLocator().getKeyNameType() << ">" << endl;
+ showKeyNameData = false;
+ }
+ if (showKeyNameData)
+ cout << toHex(data.getSignature().getKeyLocator().getKeyData()) << endl;
+ }
+ else
+ cout << "<no key digest>" << endl;
+ }
+ else
+ cout << "<unrecognized ndn_KeyLocatorType " << data.getSignature().getKeyLocator().getType() << ">" << endl;
+ }
+ else
+ cout << "<none>" << endl;
}
int main(int argc, char** argv)