Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_KEY_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 9 | #define NDN_KEY_HPP |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 10 | |
| 11 | #include <vector> |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 12 | #include "c/key-types.h" |
Jeff Thompson | 2e6269c | 2013-08-22 10:36:00 -0700 | [diff] [blame] | 13 | #include "name.hpp" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 14 | |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 15 | struct ndn_KeyLocator; |
| 16 | |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 17 | namespace ndn { |
| 18 | |
| 19 | class KeyLocator { |
| 20 | public: |
| 21 | KeyLocator() |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 22 | : type_((ndn_KeyLocatorType)-1), keyNameType_((ndn_KeyNameType)-1) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 23 | { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | /** |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 27 | * Clear the keyData and set the type to none. |
| 28 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 29 | void |
| 30 | clear() |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 31 | { |
| 32 | type_ = (ndn_KeyLocatorType)-1; |
| 33 | keyNameType_ = (ndn_KeyNameType)-1; |
Jeff Thompson | 03616c9 | 2013-09-12 14:30:01 -0700 | [diff] [blame] | 34 | keyData_.reset(); |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /** |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 38 | * Set the keyLocatorStruct to point to the values in this key locator, without copying any memory. |
| 39 | * WARNING: The resulting pointers in keyLocatorStruct are invalid after a further use of this object which could reallocate memory. |
| 40 | * @param keyLocatorStruct a C ndn_KeyLocator struct where the name components array is already allocated. |
| 41 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 42 | void |
| 43 | get(struct ndn_KeyLocator& keyLocatorStruct) const; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Clear this key locator, and set the values by copying from the ndn_KeyLocator struct. |
| 47 | * @param keyLocatorStruct a C ndn_KeyLocator struct |
| 48 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 49 | void |
| 50 | set(const struct ndn_KeyLocator& keyLocatorStruct); |
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 | ndn_KeyLocatorType |
| 53 | getType() const { return type_; } |
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 Blob& |
| 56 | getKeyData() const { return keyData_; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 57 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 58 | const Name& |
| 59 | getKeyName() const { return keyName_; } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 60 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 61 | Name& |
| 62 | getKeyName() { return keyName_; } |
| 63 | |
| 64 | ndn_KeyNameType |
| 65 | getKeyNameType() const { return keyNameType_; } |
| 66 | |
| 67 | void |
| 68 | setType(ndn_KeyLocatorType type) { type_ = type; } |
Jeff Thompson | 2c8dff5 | 2013-11-18 18:17:12 -0800 | [diff] [blame] | 69 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 70 | void |
Jeff Thompson | 2c8dff5 | 2013-11-18 18:17:12 -0800 | [diff] [blame] | 71 | setKeyData(const Blob& keyData) { keyData_ = keyData; } |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 72 | |
Jeff Thompson | e5c53aa | 2013-11-19 10:53:25 -0800 | [diff] [blame] | 73 | void |
| 74 | setKeyName(const Name &keyName) { keyName_ = keyName; } |
Jeff Thompson | 35a2bc1 | 2013-09-17 14:23:13 -0700 | [diff] [blame] | 75 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 76 | void |
| 77 | 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 */ |
Jeff Thompson | 4c9c045 | 2013-09-12 14:10:11 -0700 | [diff] [blame] | 81 | Blob keyData_; /**< An array for the key data as follows: |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 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 |