blob: a3784f6ce660f3579c4546d5e6c30708237365eb [file] [log] [blame]
Jeff Thompson5cae5e52013-07-10 19:41:20 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#ifndef NDN_KEY_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_KEY_HPP
Jeff Thompson5cae5e52013-07-10 19:41:20 -07008
9#include <vector>
Jeff Thompson53412192013-08-06 13:35:50 -070010#include "c/key.h"
Jeff Thompson2e6269c2013-08-22 10:36:00 -070011#include "name.hpp"
Jeff Thompson5cae5e52013-07-10 19:41:20 -070012
13namespace ndn {
14
15class KeyLocator {
16public:
17 KeyLocator()
Jeff Thompson7329a132013-08-16 15:57:37 -070018 : type_((ndn_KeyLocatorType)-1), keyNameType_((ndn_KeyNameType)-1)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070019 {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070020 }
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 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070027 void get(struct ndn_KeyLocator& keyLocatorStruct) const;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070028
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 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070033 void set(const struct ndn_KeyLocator& keyLocatorStruct);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070034
35 ndn_KeyLocatorType getType() const { return type_; }
36
Jeff Thompson1656e6a2013-08-29 18:01:48 -070037 const std::vector<unsigned char>& getKeyData() const { return keyData_; }
Jeff Thompson5cae5e52013-07-10 19:41:20 -070038
Jeff Thompson1656e6a2013-08-29 18:01:48 -070039 const Name& getKeyName() const { return keyName_; }
40 Name& getKeyName() { return keyName_; }
Jeff Thompson7329a132013-08-16 15:57:37 -070041
42 ndn_KeyNameType getKeyNameType() const { return keyNameType_; }
Jeff Thompson46bd45f2013-08-08 16:46:41 -070043
44 void setType(ndn_KeyLocatorType type) { type_ = type; }
45
Jeff Thompson1656e6a2013-08-29 18:01:48 -070046 void setKeyData(const std::vector<unsigned char>& keyData) { keyData_ = keyData; }
Jeff Thompson63d02692013-08-16 12:09:07 -070047 void setKeyData(const unsigned char *keyData, unsigned int keyDataLength)
Jeff Thompson46bd45f2013-08-08 16:46:41 -070048 {
Jeff Thompson63d02692013-08-16 12:09:07 -070049 setVector(keyData_, keyData, keyDataLength);
Jeff Thompson46bd45f2013-08-08 16:46:41 -070050 }
51
Jeff Thompson63d02692013-08-16 12:09:07 -070052 /**
53 * @deprecated Use getKeyData().
54 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070055 const std::vector<unsigned char>& getKeyOrCertificate() const { return getKeyData(); }
Jeff Thompson63d02692013-08-16 12:09:07 -070056
57 /**
58 * @deprecated Use setKeyData.
59 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070060 void setKeyOrCertificate(const std::vector<unsigned char>& keyData) { setKeyData(keyData); }
Jeff Thompson63d02692013-08-16 12:09:07 -070061
62 /**
63 * @deprecated Use setKeyData.
64 */
65 void setKeyOrCertificate(const unsigned char *keyData, unsigned int keyDataLength) { setKeyData(keyData, keyDataLength); }
66
Jeff Thompson7329a132013-08-16 15:57:37 -070067 void setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; }
Jeff Thompson5cae5e52013-07-10 19:41:20 -070068
69private:
Jeff Thompson7329a132013-08-16 15:57:37 -070070 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.) */
Jeff Thompson1cf72e92013-08-23 20:38:39 -070080 ndn_KeyNameType keyNameType_; /**< The type of data for keyName_, -1 for none. (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070081};
82
83}
84
85#endif