blob: 6cf2a1bcddbe62693cb53998e4891872e98e8181 [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 */
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 Thompson63d02692013-08-16 12:09:07 -070037 const std::vector<unsigned char> &getKeyData() const { return keyData_; }
Jeff Thompson5cae5e52013-07-10 19:41:20 -070038
Jeff Thompson7329a132013-08-16 15:57:37 -070039 const Name &getKeyName() const { return keyName_; }
40 Name &getKeyName() { return keyName_; }
41
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 Thompson63d02692013-08-16 12:09:07 -070046 void setKeyData(const std::vector<unsigned char> &keyData) { keyData_ = keyData; }
47 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 */
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 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.) */
80 ndn_KeyNameType keyNameType_; /**< The type of data for keyName_ (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070081};
82
83}
84
85#endif