If KeyLocator is a KeyName, allow the key name data to be omitted.
diff --git a/ndn-cpp/c/encoding/binary-xml-key.c b/ndn-cpp/c/encoding/binary-xml-key.c
index 42e4463..1f61e51 100644
--- a/ndn-cpp/c/encoding/binary-xml-key.c
+++ b/ndn-cpp/c/encoding/binary-xml-key.c
@@ -47,8 +47,11 @@
               (decoder, ndn_BinaryXml_DTag_PublisherIssuerCertificateDigest, 0, &keyLocator->keyData, &keyLocator->keyDataLength)))
             return error;
         }
-        else
-          return NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_name_type;
+        else {
+          // Key name data is omitted.
+          keyLocator->keyNameType = -1;
+          keyLocator->keyDataLength = 0;
+        }
       }
     }
   }
@@ -81,29 +84,31 @@
     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;    
+    if ((int)keyLocator->keyNameType >= 0 && keyLocator->keyDataLength > 0) {
+      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;
     }
-    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;
   }
diff --git a/ndn-cpp/c/errors.c b/ndn-cpp/c/errors.c
index af70f56..7f87c5b 100644
--- a/ndn-cpp/c/errors.c
+++ b/ndn-cpp/c/errors.c
@@ -56,8 +56,6 @@
     return      "unrecognized ndn_KeyNameType";
   case NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_locator_type:
     return      "decodeBinaryXmlKeyLocator unrecognized key locator type";
-  case NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_name_type:
-    return      "decodeBinaryXmlKeyLocator unrecognized key name type";
   case NDN_ERROR_unrecognized_ndn_SocketTransport:
     return      "unrecognized ndn_SocketTransport";
   case NDN_ERROR_SocketTransport_error_in_getaddrinfo:
diff --git a/ndn-cpp/c/errors.h b/ndn-cpp/c/errors.h
index da8548f..ee76528 100644
--- a/ndn-cpp/c/errors.h
+++ b/ndn-cpp/c/errors.h
@@ -36,7 +36,6 @@
   NDN_ERROR_unrecognized_ndn_KeyLocatorType,
   NDN_ERROR_unrecognized_ndn_KeyNameType,
   NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_locator_type,
-  NDN_ERROR_decodeBinaryXmlKeyLocator_unrecognized_key_name_type,
   NDN_ERROR_unrecognized_ndn_SocketTransport,
   NDN_ERROR_SocketTransport_error_in_getaddrinfo,
   NDN_ERROR_SocketTransport_cannot_connect_to_socket,
diff --git a/ndn-cpp/c/key.h b/ndn-cpp/c/key.h
index 5bfe05e..f6df357 100644
--- a/ndn-cpp/c/key.h
+++ b/ndn-cpp/c/key.h
@@ -40,7 +40,7 @@
     */
   unsigned int keyDataLength;  /**< The length of keyData. */
   struct ndn_Name keyName;     /**< The key name (only used if type is ndn_KeyLocatorType_KEYNAME.) */
-  ndn_KeyNameType keyNameType; /**< The type of data for keyName (only used if type is ndn_KeyLocatorType_KEYNAME.) */
+  ndn_KeyNameType keyNameType; /**< The type of data for keyName, -1 for none. (only used if type is ndn_KeyLocatorType_KEYNAME.) */
 };
 
 /**
diff --git a/ndn-cpp/key.hpp b/ndn-cpp/key.hpp
index 6cf2a1b..6fa2f05 100644
--- a/ndn-cpp/key.hpp
+++ b/ndn-cpp/key.hpp
@@ -77,7 +77,7 @@
     *   If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST, the publisher issuer certificate digest. 
                                 */
   Name keyName_;                /**< The key name (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
-  ndn_KeyNameType keyNameType_; /**< The type of data for keyName_ (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
+  ndn_KeyNameType keyNameType_; /**< The type of data for keyName_, -1 for none. (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
 };
   
 }
diff --git a/tests/test-encode-decode-data.cpp b/tests/test-encode-decode-data.cpp
index ad10650..387712a 100644
--- a/tests/test-encode-decode-data.cpp
+++ b/tests/test-encode-decode-data.cpp
@@ -111,7 +111,7 @@
        << (data.getSignedInfo().getFinalBlockID().size() > 0 ? 
            toHex(data.getSignedInfo().getFinalBlockID()).c_str() : "<none>") << endl;
   cout << "signedInfo.keyLocator: ";
-  if (data.getSignedInfo().getKeyLocator().getType() >= 0) {
+  if ((int)data.getSignedInfo().getKeyLocator().getType() >= 0) {
     if (data.getSignedInfo().getKeyLocator().getType() == ndn_KeyLocatorType_KEY)
       cout << "Key: " << toHex(data.getSignedInfo().getKeyLocator().getKeyData()) << endl;
     else if (data.getSignedInfo().getKeyLocator().getType() == ndn_KeyLocatorType_CERTIFICATE)
@@ -119,21 +119,25 @@
     else if (data.getSignedInfo().getKeyLocator().getType() == ndn_KeyLocatorType_KEYNAME) {
       cout << "KeyName: " << data.getSignedInfo().getKeyLocator().getKeyName().to_uri() << endl;
       cout << "signedInfo.keyLocator: ";
-      bool showKeyNameData = true;
-      if (data.getSignedInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST)
-        cout << "PublisherPublicKeyDigest: ";
-      else if (data.getSignedInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST)
-        cout << "PublisherCertificateDigest: ";
-      else if (data.getSignedInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST)
-        cout << "PublisherIssuerKeyDigest: ";
-      else if (data.getSignedInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST)
-        cout << "PublisherIssuerCertificateDigest: ";
-      else {
-        cout << "<unrecognized ndn_KeyNameType " << data.getSignedInfo().getKeyLocator().getKeyNameType() << ">" << endl;
-        showKeyNameData = false;
+      if ((int)data.getSignedInfo().getKeyLocator().getKeyNameType() >= 0) {
+        bool showKeyNameData = true;
+        if (data.getSignedInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST)
+          cout << "PublisherPublicKeyDigest: ";
+        else if (data.getSignedInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST)
+          cout << "PublisherCertificateDigest: ";
+        else if (data.getSignedInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST)
+          cout << "PublisherIssuerKeyDigest: ";
+        else if (data.getSignedInfo().getKeyLocator().getKeyNameType() == ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST)
+          cout << "PublisherIssuerCertificateDigest: ";
+        else {
+          cout << "<unrecognized ndn_KeyNameType " << data.getSignedInfo().getKeyLocator().getKeyNameType() << ">" << endl;
+          showKeyNameData = false;
+        }
+        if (showKeyNameData)
+          cout << toHex(data.getSignedInfo().getKeyLocator().getKeyData()) << endl;
       }
-      if (showKeyNameData)
-        cout << toHex(data.getSignedInfo().getKeyLocator().getKeyData()) << endl;
+      else
+        cout << "<no key digest>" << endl;
     }
     else
       cout << "<unrecognized ndn_KeyLocatorType " << data.getSignedInfo().getKeyLocator().getType() << ">" << endl;