Added separate PublishPublicKeyDigest and use in Interest.
diff --git a/ndn-cpp/c/encoding/BinaryXMLInterest.c b/ndn-cpp/c/encoding/BinaryXMLInterest.c
index 270e13b..c7e4177 100644
--- a/ndn-cpp/c/encoding/BinaryXMLInterest.c
+++ b/ndn-cpp/c/encoding/BinaryXMLInterest.c
@@ -7,6 +7,7 @@
#include "BinaryXMLEncoder.h"
#include "BinaryXMLDecoder.h"
#include "BinaryXMLName.h"
+#include "BinaryXMLPublisherPublicKeyDigest.h"
#include "BinaryXMLInterest.h"
static ndn_Error encodeExclude(struct ndn_Exclude *exclude, struct ndn_BinaryXMLEncoder *encoder)
@@ -138,13 +139,11 @@
return error;
}
- if (interest->publisherPublicKeyDigest && interest->publisherPublicKeyDigestLength > 0) {
- if (error = ndn_BinaryXMLEncoder_writeBlobDTagElement
- (encoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, interest->publisherPublicKeyDigest, interest->publisherPublicKeyDigestLength))
- return error;
- }
+ // This will skip encoding if there is no publisherPublicKeyDigest.
+ if (error = ndn_encodeBinaryXMLPublisherPublicKeyDigest(&interest->publisherPublicKeyDigest, encoder))
+ return error;
- // This will check for no exclude.
+ // This will skip encoding if there is no exclude.
if (error = encodeExclude(&interest->exclude, encoder))
return error;
@@ -208,14 +207,12 @@
if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, &gotExpectedTag))
return error;
if (gotExpectedTag) {
- if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
- (decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, 0, &interest->publisherPublicKeyDigest,
- &interest->publisherPublicKeyDigestLength))
+ if (error = ndn_decodeBinaryXMLPublisherPublicKeyDigest(&interest->publisherPublicKeyDigest, decoder))
return error;
}
else {
- interest->publisherPublicKeyDigest = 0;
- interest->publisherPublicKeyDigestLength = 0;
+ interest->publisherPublicKeyDigest.publisherPublicKeyDigest = 0;
+ interest->publisherPublicKeyDigest.publisherPublicKeyDigestLength = 0;
}
if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_Exclude, &gotExpectedTag))
diff --git a/ndn-cpp/c/encoding/BinaryXMLInterest.h b/ndn-cpp/c/encoding/BinaryXMLInterest.h
index 38917aa..9a58b78 100644
--- a/ndn-cpp/c/encoding/BinaryXMLInterest.h
+++ b/ndn-cpp/c/encoding/BinaryXMLInterest.h
@@ -8,6 +8,8 @@
#include "../errors.h"
#include "../Interest.h"
+#include "BinaryXMLEncoder.h"
+#include "BinaryXMLDecoder.h"
#ifdef __cplusplus
extern "C" {
diff --git a/ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.c b/ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.c
new file mode 100644
index 0000000..b1ee3f8
--- /dev/null
+++ b/ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.c
@@ -0,0 +1,35 @@
+/**
+ * @author: Jeff Thompson
+ * Derived from PublisherPublicKeyDigest.js by Meki Cheraoui.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "BinaryXML.h"
+#include "BinaryXMLPublisherPublicKeyDigest.h"
+
+ndn_Error ndn_encodeBinaryXMLPublisherPublicKeyDigest
+ (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXMLEncoder *encoder)
+{
+ if (!publisherPublicKeyDigest->publisherPublicKeyDigest || publisherPublicKeyDigest->publisherPublicKeyDigestLength == 0)
+ return;
+
+ ndn_Error error;
+ if (error = ndn_BinaryXMLEncoder_writeBlobDTagElement
+ (encoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, publisherPublicKeyDigest->publisherPublicKeyDigest,
+ publisherPublicKeyDigest->publisherPublicKeyDigestLength))
+ return error;
+
+ return 0;
+}
+
+ndn_Error ndn_decodeBinaryXMLPublisherPublicKeyDigest
+ (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXMLDecoder *decoder)
+{
+ ndn_Error error;
+ if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, 0, &publisherPublicKeyDigest->publisherPublicKeyDigest,
+ &publisherPublicKeyDigest->publisherPublicKeyDigestLength))
+ return error;
+
+ return 0;
+}
diff --git a/ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.h b/ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.h
new file mode 100644
index 0000000..430395c
--- /dev/null
+++ b/ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.h
@@ -0,0 +1,41 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_BINARYXMLPUBLISHERPUBLICKEYDIGEST_H
+#define NDN_BINARYXMLPUBLISHERPUBLICKEYDIGEST_H
+
+#include "../errors.h"
+#include "../PublisherPublicKeyDigest.h"
+#include "BinaryXMLEncoder.h"
+#include "BinaryXMLDecoder.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Encode the ndn_PublisherPublicKeyDigest struct using Binary XML. If publisherPublicKeyDigest->publisherPublicKeyDigest or
+ * publisherPublicKeyDigestLength is 0, then do nothing.
+ * @param publisherPublicKeyDigest pointer to the ndn_PublisherPublicKeyDigest struct
+ * @param encoder pointer to the ndn_BinaryXMLEncoder struct
+ * @return 0 for success, else an error code
+ */
+ndn_Error ndn_encodeBinaryXMLPublisherPublicKeyDigest
+ (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXMLEncoder *encoder);
+
+/**
+ * Expect the next element to be a Binary XML PublisherPublicKeyDigest and decode into the ndn_PublisherPublicKeyDigest struct.
+ * @param publisherPublicKeyDigest pointer to the ndn_PublisherPublicKeyDigest struct
+ * @param decoder pointer to the ndn_BinaryXMLDecoder struct
+ * @return 0 for success, else an error code, including if the next element is not PublisherPublicKeyDigest.
+ */
+ndn_Error ndn_decodeBinaryXMLPublisherPublicKeyDigest
+ (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXMLDecoder *decoder);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif