Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #ifndef NDN_KEY_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 7 | #define NDN_KEY_HPP |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 8 | |
| 9 | #include <vector> |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 10 | #include "c/key.h" |
Jeff Thompson | 2e6269c | 2013-08-22 10:36:00 -0700 | [diff] [blame] | 11 | #include "name.hpp" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | class KeyLocator { |
| 16 | public: |
| 17 | KeyLocator() |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 18 | : type_((ndn_KeyLocatorType)-1), keyNameType_((ndn_KeyNameType)-1) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 19 | { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | /** |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 23 | * Clear the keyData and set the type to none. |
| 24 | */ |
| 25 | void clear() |
| 26 | { |
| 27 | type_ = (ndn_KeyLocatorType)-1; |
| 28 | keyNameType_ = (ndn_KeyNameType)-1; |
Jeff Thompson | 4c9c045 | 2013-09-12 14:10:11 -0700 | [diff] [blame^] | 29 | keyData_ = Blob(0, 0); |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | /** |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 33 | * Set the keyLocatorStruct to point to the values in this key locator, without copying any memory. |
| 34 | * WARNING: The resulting pointers in keyLocatorStruct are invalid after a further use of this object which could reallocate memory. |
| 35 | * @param keyLocatorStruct a C ndn_KeyLocator struct where the name components array is already allocated. |
| 36 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 37 | void get(struct ndn_KeyLocator& keyLocatorStruct) const; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Clear this key locator, and set the values by copying from the ndn_KeyLocator struct. |
| 41 | * @param keyLocatorStruct a C ndn_KeyLocator struct |
| 42 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 43 | void set(const struct ndn_KeyLocator& keyLocatorStruct); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 44 | |
| 45 | ndn_KeyLocatorType getType() const { return type_; } |
| 46 | |
Jeff Thompson | 4c9c045 | 2013-09-12 14:10:11 -0700 | [diff] [blame^] | 47 | const Blob& getKeyData() const { return keyData_; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 48 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 49 | const Name& getKeyName() const { return keyName_; } |
| 50 | Name& getKeyName() { return keyName_; } |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 51 | |
| 52 | ndn_KeyNameType getKeyNameType() const { return keyNameType_; } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 53 | |
| 54 | void setType(ndn_KeyLocatorType type) { type_ = type; } |
| 55 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 56 | void setKeyData(const std::vector<unsigned char>& keyData) { keyData_ = keyData; } |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 57 | void setKeyData(const unsigned char *keyData, unsigned int keyDataLength) |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 58 | { |
Jeff Thompson | 4c9c045 | 2013-09-12 14:10:11 -0700 | [diff] [blame^] | 59 | keyData_ = Blob(keyData, keyDataLength); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 60 | } |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
Jeff Thompson | 4c9c045 | 2013-09-12 14:10:11 -0700 | [diff] [blame^] | 63 | * Set keyData to point to an existing byte array. IMPORTANT: After calling this constructor, |
| 64 | * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it. |
| 65 | * @param keyData A pointer to a vector with the byte array. This takes another reference and does not copy the bytes. |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 66 | */ |
Jeff Thompson | 4c9c045 | 2013-09-12 14:10:11 -0700 | [diff] [blame^] | 67 | void setKeyData(const ptr_lib::shared_ptr<std::vector<unsigned char> > &keyData) { keyData_ = keyData; } |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 68 | |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 69 | void setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 70 | |
| 71 | private: |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 72 | ndn_KeyLocatorType type_; /**< -1 for none */ |
Jeff Thompson | 4c9c045 | 2013-09-12 14:10:11 -0700 | [diff] [blame^] | 73 | Blob keyData_; /**< An array for the key data as follows: |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 74 | * If type_ is ndn_KeyLocatorType_KEY, the key data. |
| 75 | * If type_ is ndn_KeyLocatorType_CERTIFICATE, the certificate data. |
| 76 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST, the publisher public key digest. |
| 77 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST, the publisher certificate digest. |
| 78 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST, the publisher issuer key digest. |
| 79 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST, the publisher issuer certificate digest. |
| 80 | */ |
| 81 | Name keyName_; /**< The key name (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */ |
Jeff Thompson | 1cf72e9 | 2013-08-23 20:38:39 -0700 | [diff] [blame] | 82 | ndn_KeyNameType keyNameType_; /**< The type of data for keyName_, -1 for none. (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | } |
| 86 | |
| 87 | #endif |