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; |
| 29 | keyData_.clear(); |
| 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 | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 47 | const std::vector<unsigned char>& 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 | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 59 | setVector(keyData_, keyData, keyDataLength); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 62 | /** |
| 63 | * @deprecated Use getKeyData(). |
| 64 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 65 | const std::vector<unsigned char>& getKeyOrCertificate() const { return getKeyData(); } |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * @deprecated Use setKeyData. |
| 69 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 70 | void setKeyOrCertificate(const std::vector<unsigned char>& keyData) { setKeyData(keyData); } |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * @deprecated Use setKeyData. |
| 74 | */ |
| 75 | void setKeyOrCertificate(const unsigned char *keyData, unsigned int keyDataLength) { setKeyData(keyData, keyDataLength); } |
| 76 | |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 77 | void setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 78 | |
| 79 | private: |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 80 | ndn_KeyLocatorType type_; /**< -1 for none */ |
| 81 | std::vector<unsigned char> keyData_; /**< A pointer to a pre-allocated buffer for the key data as follows: |
| 82 | * If type_ is ndn_KeyLocatorType_KEY, the key data. |
| 83 | * If type_ is ndn_KeyLocatorType_CERTIFICATE, the certificate data. |
| 84 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST, the publisher public key digest. |
| 85 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST, the publisher certificate digest. |
| 86 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST, the publisher issuer key digest. |
| 87 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST, the publisher issuer certificate digest. |
| 88 | */ |
| 89 | 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] | 90 | 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] | 91 | }; |
| 92 | |
| 93 | } |
| 94 | |
| 95 | #endif |