Make KeyLocator.keyData_ a Blob.
diff --git a/ndn-cpp/key.cpp b/ndn-cpp/key.cpp
index 6cdae60..bbd6877 100644
--- a/ndn-cpp/key.cpp
+++ b/ndn-cpp/key.cpp
@@ -16,7 +16,7 @@
keyLocatorStruct.keyDataLength = keyData_.size();
if (keyData_.size() > 0)
- keyLocatorStruct.keyData = (unsigned char *)&keyData_[0];
+ keyLocatorStruct.keyData = (unsigned char *)keyData_.buf();
else
keyLocatorStruct.keyData = 0;
@@ -27,7 +27,7 @@
void KeyLocator::set(const struct ndn_KeyLocator& keyLocatorStruct)
{
type_ = keyLocatorStruct.type;
- setVector(keyData_, keyLocatorStruct.keyData, keyLocatorStruct.keyDataLength);
+ keyData_ = Blob(keyLocatorStruct.keyData, keyLocatorStruct.keyDataLength);
if (keyLocatorStruct.type == ndn_KeyLocatorType_KEYNAME) {
keyName_.set(keyLocatorStruct.keyName);
keyNameType_ = keyLocatorStruct.keyNameType;
diff --git a/ndn-cpp/key.hpp b/ndn-cpp/key.hpp
index 6cf449e..0717e1b 100644
--- a/ndn-cpp/key.hpp
+++ b/ndn-cpp/key.hpp
@@ -26,7 +26,7 @@
{
type_ = (ndn_KeyLocatorType)-1;
keyNameType_ = (ndn_KeyNameType)-1;
- keyData_.clear();
+ keyData_ = Blob(0, 0);
}
/**
@@ -44,7 +44,7 @@
ndn_KeyLocatorType getType() const { return type_; }
- const std::vector<unsigned char>& getKeyData() const { return keyData_; }
+ const Blob& getKeyData() const { return keyData_; }
const Name& getKeyName() const { return keyName_; }
Name& getKeyName() { return keyName_; }
@@ -56,29 +56,21 @@
void setKeyData(const std::vector<unsigned char>& keyData) { keyData_ = keyData; }
void setKeyData(const unsigned char *keyData, unsigned int keyDataLength)
{
- setVector(keyData_, keyData, keyDataLength);
+ keyData_ = Blob(keyData, keyDataLength);
}
-
- /**
- * @deprecated Use getKeyData().
- */
- const std::vector<unsigned char>& getKeyOrCertificate() const { return getKeyData(); }
-
- /**
- * @deprecated Use setKeyData.
- */
- void setKeyOrCertificate(const std::vector<unsigned char>& keyData) { setKeyData(keyData); }
/**
- * @deprecated Use setKeyData.
+ * Set keyData to point to an existing byte array. IMPORTANT: After calling this constructor,
+ * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it.
+ * @param keyData A pointer to a vector with the byte array. This takes another reference and does not copy the bytes.
*/
- void setKeyOrCertificate(const unsigned char *keyData, unsigned int keyDataLength) { setKeyData(keyData, keyDataLength); }
+ void setKeyData(const ptr_lib::shared_ptr<std::vector<unsigned char> > &keyData) { keyData_ = keyData; }
void setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; }
private:
ndn_KeyLocatorType type_; /**< -1 for none */
- std::vector<unsigned char> keyData_; /**< A pointer to a pre-allocated buffer for the key data as follows:
+ Blob keyData_; /**< An array for the key data as follows:
* If type_ is ndn_KeyLocatorType_KEY, the key data.
* If type_ is ndn_KeyLocatorType_CERTIFICATE, the certificate data.
* If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST, the publisher public key digest.
diff --git a/ndn-cpp/security/key-chain.cpp b/ndn-cpp/security/key-chain.cpp
index c456036..4a19869 100644
--- a/ndn-cpp/security/key-chain.cpp
+++ b/ndn-cpp/security/key-chain.cpp
@@ -137,7 +137,7 @@
const unsigned char *publicKeyDer;
unsigned int publicKeyDerLength;
if (data.getSignature().getKeyLocator().getType() == ndn_KeyLocatorType_KEY) {
- publicKeyDer = &data.getSignature().getKeyLocator().getKeyData().front();
+ publicKeyDer = data.getSignature().getKeyLocator().getKeyData().buf();
publicKeyDerLength = data.getSignature().getKeyLocator().getKeyData().size();
}
else