In KeyLocator, added support for KeyName.
diff --git a/ndn-cpp/c/encoding/binary-xml-key.c b/ndn-cpp/c/encoding/binary-xml-key.c
index c1df758..42e4463 100644
--- a/ndn-cpp/c/encoding/binary-xml-key.c
+++ b/ndn-cpp/c/encoding/binary-xml-key.c
@@ -8,6 +8,54 @@
#include "binary-xml-structure-decoder.h"
#include "binary-xml-key.h"
+static ndn_Error decodeKeyNameData(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXmlDecoder *decoder)
+{
+ int gotExpectedTag;
+ ndn_Error error;
+ if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &gotExpectedTag)))
+ return error;
+ if (gotExpectedTag) {
+ keyLocator->keyNameType = ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST;
+ if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, 0, &keyLocator->keyData, &keyLocator->keyDataLength)))
+ return error;
+ }
+ else {
+ if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherCertificateDigest, &gotExpectedTag)))
+ return error;
+ if (gotExpectedTag) {
+ keyLocator->keyNameType = ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST;
+ if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXml_DTag_PublisherCertificateDigest, 0, &keyLocator->keyData, &keyLocator->keyDataLength)))
+ return error;
+ }
+ else {
+ if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherIssuerKeyDigest, &gotExpectedTag)))
+ return error;
+ if (gotExpectedTag) {
+ keyLocator->keyNameType = ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST;
+ if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXml_DTag_PublisherIssuerKeyDigest, 0, &keyLocator->keyData, &keyLocator->keyDataLength)))
+ return error;
+ }
+ else {
+ if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, &gotExpectedTag)))
+ return error;
+ if (gotExpectedTag) {
+ keyLocator->keyNameType = ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST;
+ if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
+ (decoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, 0, &keyLocator->keyData, &keyLocator->keyDataLength)))
+ return error;
+ }
+ else
+ return NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_name_type;
+ }
+ }
+ }
+
+ return NDN_ERROR_success;
+}
+
ndn_Error ndn_encodeBinaryXmlKeyLocator(struct ndn_KeyLocator *keyLocator, struct ndn_BinaryXmlEncoder *encoder)
{
if (keyLocator->type < 0)
@@ -28,7 +76,36 @@
return error;
}
else if (keyLocator->type == ndn_KeyLocatorType_KEYNAME) {
- // TODO: Implement keyName
+ if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_KeyName)))
+ return error;
+ if ((error = ndn_encodeBinaryXmlName(&keyLocator->keyName, encoder)))
+ return error;
+
+ if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST) {
+ if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
+ (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, keyLocator->keyData, keyLocator->keyDataLength)))
+ return error;
+ }
+ else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST) {
+ if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
+ (encoder, ndn_BinaryXml_DTag_PublisherCertificateDigest, keyLocator->keyData, keyLocator->keyDataLength)))
+ return error;
+ }
+ else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST) {
+ if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
+ (encoder, ndn_BinaryXml_DTag_PublisherIssuerKeyDigest, keyLocator->keyData, keyLocator->keyDataLength)))
+ return error;
+ }
+ else if (keyLocator->keyNameType == ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST) {
+ if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
+ (encoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, keyLocator->keyData, keyLocator->keyDataLength)))
+ return error;
+ }
+ else
+ return NDN_ERROR_unrecognized_ndn_KeyNameType;
+
+ if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
+ return error;
}
else
return NDN_ERROR_unrecognized_ndn_KeyLocatorType;
@@ -69,16 +146,16 @@
if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_KeyName, &gotExpectedTag)))
return error;
if (gotExpectedTag) {
- // TODO: Implement keyName. For now, just use a structure decoder to skip it.
- struct ndn_BinaryXmlStructureDecoder structureDecoder;
- ndn_BinaryXmlStructureDecoder_init(&structureDecoder);
+ keyLocator->type = ndn_KeyLocatorType_KEYNAME;
- ndn_BinaryXmlStructureDecoder_seek(&structureDecoder, decoder->offset);
- if ((error = ndn_BinaryXmlStructureDecoder_findElementEnd(&structureDecoder, decoder->input, decoder->inputLength)))
+ if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_KeyName)))
return error;
- if (!structureDecoder.gotElementEnd)
- return NDN_ERROR_read_past_the_end_of_the_input;
- ndn_BinaryXmlDecoder_seek(decoder, structureDecoder.offset);
+ if ((error = ndn_decodeBinaryXmlName(&keyLocator->keyName, decoder)))
+ return error;
+ if ((error = decodeKeyNameData(keyLocator, decoder)))
+ return error;
+ if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
+ return error;
}
else
return NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_locator_type;
@@ -102,7 +179,7 @@
return error;
}
else
- ndn_KeyLocator_init(keyLocator);
+ ndn_KeyLocator_init(keyLocator, keyLocator->keyName.components, keyLocator->keyName.maxComponents);
return NDN_ERROR_success;
}