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 | /** |
| 23 | * Set the keyLocatorStruct to point to the values in this key locator, without copying any memory. |
| 24 | * WARNING: The resulting pointers in keyLocatorStruct are invalid after a further use of this object which could reallocate memory. |
| 25 | * @param keyLocatorStruct a C ndn_KeyLocator struct where the name components array is already allocated. |
| 26 | */ |
| 27 | void get(struct ndn_KeyLocator &keyLocatorStruct) const; |
| 28 | |
| 29 | /** |
| 30 | * Clear this key locator, and set the values by copying from the ndn_KeyLocator struct. |
| 31 | * @param keyLocatorStruct a C ndn_KeyLocator struct |
| 32 | */ |
| 33 | void set(const struct ndn_KeyLocator &keyLocatorStruct); |
| 34 | |
| 35 | ndn_KeyLocatorType getType() const { return type_; } |
| 36 | |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 37 | const std::vector<unsigned char> &getKeyData() const { return keyData_; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 38 | |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 39 | const Name &getKeyName() const { return keyName_; } |
| 40 | Name &getKeyName() { return keyName_; } |
| 41 | |
| 42 | ndn_KeyNameType getKeyNameType() const { return keyNameType_; } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 43 | |
| 44 | void setType(ndn_KeyLocatorType type) { type_ = type; } |
| 45 | |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 46 | void setKeyData(const std::vector<unsigned char> &keyData) { keyData_ = keyData; } |
| 47 | void setKeyData(const unsigned char *keyData, unsigned int keyDataLength) |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 48 | { |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 49 | setVector(keyData_, keyData, keyDataLength); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 52 | /** |
| 53 | * @deprecated Use getKeyData(). |
| 54 | */ |
| 55 | const std::vector<unsigned char> &getKeyOrCertificate() const { return getKeyData(); } |
| 56 | |
| 57 | /** |
| 58 | * @deprecated Use setKeyData. |
| 59 | */ |
| 60 | void setKeyOrCertificate(const std::vector<unsigned char> &keyData) { setKeyData(keyData); } |
| 61 | |
| 62 | /** |
| 63 | * @deprecated Use setKeyData. |
| 64 | */ |
| 65 | void setKeyOrCertificate(const unsigned char *keyData, unsigned int keyDataLength) { setKeyData(keyData, keyDataLength); } |
| 66 | |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 67 | void setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 68 | |
| 69 | private: |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 70 | ndn_KeyLocatorType type_; /**< -1 for none */ |
| 71 | std::vector<unsigned char> keyData_; /**< A pointer to a pre-allocated buffer for the key data as follows: |
| 72 | * If type_ is ndn_KeyLocatorType_KEY, the key data. |
| 73 | * If type_ is ndn_KeyLocatorType_CERTIFICATE, the certificate data. |
| 74 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST, the publisher public key digest. |
| 75 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST, the publisher certificate digest. |
| 76 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST, the publisher issuer key digest. |
| 77 | * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST, the publisher issuer certificate digest. |
| 78 | */ |
| 79 | Name keyName_; /**< The key name (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */ |
| 80 | ndn_KeyNameType keyNameType_; /**< The type of data for keyName_ (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } |
| 84 | |
| 85 | #endif |