Added BinaryXMLKey
diff --git a/Makefile.am b/Makefile.am
index d9a11e7..b51bb9e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -26,6 +26,7 @@
ndn-cpp/c/encoding/BinaryXMLDecoder.c ndn-cpp/c/encoding/BinaryXMLDecoder.h \
ndn-cpp/c/encoding/BinaryXMLEncoder.c ndn-cpp/c/encoding/BinaryXMLEncoder.h \
ndn-cpp/c/encoding/BinaryXMLInterest.c ndn-cpp/c/encoding/BinaryXMLInterest.h \
+ ndn-cpp/c/encoding/BinaryXMLKey.c ndn-cpp/c/encoding/BinaryXMLKey.h \
ndn-cpp/c/encoding/BinaryXMLName.c ndn-cpp/c/encoding/BinaryXMLName.h \
ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.c ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.h \
ndn-cpp/c/encoding/BinaryXMLStructureDecoder.c ndn-cpp/c/encoding/BinaryXMLStructureDecoder.h \
diff --git a/Makefile.in b/Makefile.in
index d614e11..2a84ac9 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -140,6 +140,7 @@
ndn-cpp/c/encoding/BinaryXMLDecoder.$(OBJEXT) \
ndn-cpp/c/encoding/BinaryXMLEncoder.$(OBJEXT) \
ndn-cpp/c/encoding/BinaryXMLInterest.$(OBJEXT) \
+ ndn-cpp/c/encoding/BinaryXMLKey.$(OBJEXT) \
ndn-cpp/c/encoding/BinaryXMLName.$(OBJEXT) \
ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.$(OBJEXT) \
ndn-cpp/c/encoding/BinaryXMLStructureDecoder.$(OBJEXT) \
@@ -414,6 +415,7 @@
ndn-cpp/c/encoding/BinaryXMLDecoder.c ndn-cpp/c/encoding/BinaryXMLDecoder.h \
ndn-cpp/c/encoding/BinaryXMLEncoder.c ndn-cpp/c/encoding/BinaryXMLEncoder.h \
ndn-cpp/c/encoding/BinaryXMLInterest.c ndn-cpp/c/encoding/BinaryXMLInterest.h \
+ ndn-cpp/c/encoding/BinaryXMLKey.c ndn-cpp/c/encoding/BinaryXMLKey.h \
ndn-cpp/c/encoding/BinaryXMLName.c ndn-cpp/c/encoding/BinaryXMLName.h \
ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.c ndn-cpp/c/encoding/BinaryXMLPublisherPublicKeyDigest.h \
ndn-cpp/c/encoding/BinaryXMLStructureDecoder.c ndn-cpp/c/encoding/BinaryXMLStructureDecoder.h \
@@ -550,6 +552,9 @@
ndn-cpp/c/encoding/BinaryXMLInterest.$(OBJEXT): \
ndn-cpp/c/encoding/$(am__dirstamp) \
ndn-cpp/c/encoding/$(DEPDIR)/$(am__dirstamp)
+ndn-cpp/c/encoding/BinaryXMLKey.$(OBJEXT): \
+ ndn-cpp/c/encoding/$(am__dirstamp) \
+ ndn-cpp/c/encoding/$(DEPDIR)/$(am__dirstamp)
ndn-cpp/c/encoding/BinaryXMLName.$(OBJEXT): \
ndn-cpp/c/encoding/$(am__dirstamp) \
ndn-cpp/c/encoding/$(DEPDIR)/$(am__dirstamp)
@@ -691,6 +696,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLDecoder.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLEncoder.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLInterest.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLKey.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLName.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLPublisherPublicKeyDigest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/c/encoding/$(DEPDIR)/BinaryXMLStructureDecoder.Po@am__quote@
diff --git a/ndn-cpp/c/encoding/BinaryXMLKey.c b/ndn-cpp/c/encoding/BinaryXMLKey.c
new file mode 100644
index 0000000..8d51b4d
--- /dev/null
+++ b/ndn-cpp/c/encoding/BinaryXMLKey.c
@@ -0,0 +1,98 @@
+/**
+ * @author: Jeff Thompson
+ * Derived from Key.js by Meki Cheraoui.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "BinaryXML.h"
+#include "BinaryXMLKey.h"
+
+ndn_Error ndn_encodeBinaryXMLKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXMLEncoder *encoder)
+{
+ if (keyLocator->type < 0)
+ return 0;
+
+ ndn_Error error;
+ if (error = ndn_BinaryXMLEncoder_writeElementStartDTag(encoder, ndn_BinaryXML_DTag_KeyLocator))
+ return error;
+
+ if (keyLocator->type == ndn_KeyLocatorType_KEY) {
+ if (error = ndn_BinaryXMLEncoder_writeBlobDTagElement
+ (encoder, ndn_BinaryXML_DTag_Key, keyLocator->keyOrCertificate, keyLocator->keyOrCertificateLength))
+ return error;
+ }
+ else if (keyLocator->type == ndn_KeyLocatorType_CERTIFICATE) {
+ if (error = ndn_BinaryXMLEncoder_writeBlobDTagElement
+ (encoder, ndn_BinaryXML_DTag_Certificate, keyLocator->keyOrCertificate, keyLocator->keyOrCertificateLength))
+ return error;
+ }
+ else if (keyLocator->type == ndn_KeyLocatorType_KEYNAME) {
+ // TODO: Implement keyName
+ }
+ else
+ return NDN_ERROR_unrecognized_ndn_KeyLocatorType;
+
+ if (error = ndn_BinaryXMLEncoder_writeElementClose(encoder))
+ return error;
+
+ return 0;
+}
+
+ndn_Error ndn_decodeBinaryXMLKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXMLDecoder *decoder)
+{
+ ndn_Error error;
+ if (error = ndn_BinaryXMLDecoder_readElementStartDTag(decoder, ndn_BinaryXML_DTag_KeyLocator))
+ return error;
+
+ int gotExpectedTag;
+ if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_Key, &gotExpectedTag))
+ return error;
+ if (gotExpectedTag) {
+ keyLocator->type = ndn_KeyLocatorType_KEY;
+
+ if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXML_DTag_Key, 0, &keyLocator->keyOrCertificate, &keyLocator->keyOrCertificateLength))
+ return error;
+ }
+ else {
+ if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_Certificate, &gotExpectedTag))
+ return error;
+ if (gotExpectedTag) {
+ keyLocator->type = ndn_KeyLocatorType_CERTIFICATE;
+
+ if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXML_DTag_Certificate, 0, &keyLocator->keyOrCertificate, &keyLocator->keyOrCertificateLength))
+ return error;
+ }
+ else {
+ if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_KeyName, &gotExpectedTag))
+ return error;
+ if (gotExpectedTag) {
+ // TODO: Implement keyName
+ }
+ else
+ return NDN_ERROR_decodeBinaryXMLKeyLocator_unrecognized_key_locator_type;
+ }
+ }
+
+ if (error = ndn_BinaryXMLDecoder_readElementClose(decoder))
+ return error;
+
+ return 0;
+}
+
+ndn_Error ndn_decodeOptionalBinaryXMLKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXMLDecoder *decoder)
+{
+ int gotExpectedTag;
+ ndn_Error error;
+ if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_KeyLocator, &gotExpectedTag))
+ return error;
+ if (gotExpectedTag) {
+ if (error = ndn_decodeBinaryXMLKeyLocator(keyLocator, decoder))
+ return error;
+ }
+ else
+ ndn_KeyLocator_init(keyLocator);
+
+ return 0;
+}
diff --git a/ndn-cpp/c/encoding/BinaryXMLKey.h b/ndn-cpp/c/encoding/BinaryXMLKey.h
new file mode 100644
index 0000000..8896dd6
--- /dev/null
+++ b/ndn-cpp/c/encoding/BinaryXMLKey.h
@@ -0,0 +1,47 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_BINARYXMLKEY_H
+#define NDN_BINARYXMLKEY_H
+
+#include "../errors.h"
+#include "../Key.h"
+#include "BinaryXMLEncoder.h"
+#include "BinaryXMLDecoder.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Encode the ndn_KeyLocator struct using Binary XML. If keyLocator->type is -1, then do nothing.
+ * @param keyLocator pointer to the ndn_KeyLocator struct
+ * @param encoder pointer to the ndn_BinaryXMLEncoder struct
+ * @return 0 for success, else an error code
+ */
+ndn_Error ndn_encodeBinaryXMLKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXMLEncoder *encoder);
+
+/**
+ * Expect the next element to be a Binary XML KeyLocator and decode into the ndn_KeyLocator struct.
+ * @param keyLocator pointer to the ndn_KeyLocator struct
+ * @param decoder pointer to the ndn_BinaryXMLDecoder struct
+ * @return 0 for success, else an error code, including if the next element is not KeyLocator.
+ */
+ndn_Error ndn_decodeBinaryXMLKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXMLDecoder *decoder);
+
+/**
+ * Peek the next element and if it is a Binary XML KeyLocator and decode into the ndn_KeyLocator struct.
+ * Otherwise, set the ndn_KeyLocator struct to none.
+ * @param keyLocator pointer to the ndn_KeyLocator struct
+ * @param decoder pointer to the ndn_BinaryXMLDecoder struct
+ * @return 0 for success, else an error code, including if the next element is not KeyLocator.
+ */
+ndn_Error ndn_decodeOptionalBinaryXMLKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXMLDecoder *decoder);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif