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