data: Converting Data packet and related fields to TLV
Change-Id: Ie7a6db7352384f14a830046e65a953a2d9bbb71c
diff --git a/include/ndn-cpp/key-locator.hpp b/include/ndn-cpp/key-locator.hpp
index 5c1f6c1..f6c6f9d 100644
--- a/include/ndn-cpp/key-locator.hpp
+++ b/include/ndn-cpp/key-locator.hpp
@@ -8,88 +8,71 @@
#ifndef NDN_KEY_LOCATOR_HPP
#define NDN_KEY_LOCATOR_HPP
-#include <vector>
-#include "c/key-types.h"
+#include "encoding/tlv-element.hpp"
#include "name.hpp"
-struct ndn_KeyLocator;
-
namespace ndn {
-
+
+namespace error {
+struct KeyLocator : public std::runtime_error { KeyLocator(const std::string &what) : std::runtime_error(what) {} };
+} // error
+
class KeyLocator {
public:
+ enum {
+ KeyLocator_None = -1,
+ KeyLocator_Name = 0
+ };
+
KeyLocator()
- : type_((ndn_KeyLocatorType)-1), keyNameType_((ndn_KeyNameType)-1)
+ : type_(KeyLocator_None)
{
}
-
- /**
- * Clear the keyData and set the type to none.
- */
- void
- clear()
- {
- type_ = (ndn_KeyLocatorType)-1;
- keyNameType_ = (ndn_KeyNameType)-1;
- keyData_.reset();
- }
-
- /**
- * Set the keyLocatorStruct to point to the values in this key locator, without copying any memory.
- * WARNING: The resulting pointers in keyLocatorStruct are invalid after a further use of this object which could reallocate memory.
- * @param keyLocatorStruct a C ndn_KeyLocator struct where the name components array is already allocated.
- */
- void
- get(struct ndn_KeyLocator& keyLocatorStruct) const;
-
- /**
- * Clear this key locator, and set the values by copying from the ndn_KeyLocator struct.
- * @param keyLocatorStruct a C ndn_KeyLocator struct
- */
- void
- set(const struct ndn_KeyLocator& keyLocatorStruct);
- ndn_KeyLocatorType
+ inline bool
+ empty() const
+ {
+ return type_ == KeyLocator_None;
+ }
+
+ uint32_t
getType() const { return type_; }
- const Blob&
- getKeyData() const { return keyData_; }
-
- const Name&
- getKeyName() const { return keyName_; }
-
- Name&
- getKeyName() { return keyName_; }
-
- ndn_KeyNameType
- getKeyNameType() const { return keyNameType_; }
-
void
- setType(ndn_KeyLocatorType type) { type_ = type; }
+ setType(uint32_t type) { type_ = type; }
+ const Block&
+ getValue() const { return value_; }
+
void
- setKeyData(const Blob& keyData) { keyData_ = keyData; }
+ setValue(const Block &value) { value_ = value; }
+
+ ////////////////////////////////////////////////////////
+ // Helper methods for different types of key locators
+ //
+ // For now only Name type is actually supported
+
+ Name
+ getName() const
+ {
+ if (type_ != KeyLocator_Name)
+ throw error::KeyLocator("Requested Name, but KeyLocator is not of the Name type");
+
+ return Name(getValue());
+ }
void
- setKeyName(const Name &keyName) { keyName_ = keyName; }
+ setName(const Name &name)
+ {
+ type_ = KeyLocator_Name;
+ value_ = name.wireEncode();
+ }
- void
- setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; }
-
private:
- ndn_KeyLocatorType type_; /**< -1 for none */
- 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.
- * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST, the publisher certificate digest.
- * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST, the publisher issuer key digest.
- * 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_, -1 for none. (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
+ uint32_t type_;
+ Block value_;
};
-
+
}
#endif