blob: c9037b1933b0d4d1a57366901ba72f6a78f3560b [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 Thompson5cae5e52013-07-10 19:41:20 -070011
12namespace ndn {
13
14class KeyLocator {
15public:
16 KeyLocator()
17 {
18 type_ = (ndn_KeyLocatorType)-1;
19 }
20
21 /**
22 * Set the keyLocatorStruct to point to the values in this key locator, without copying any memory.
23 * WARNING: The resulting pointers in keyLocatorStruct are invalid after a further use of this object which could reallocate memory.
24 * @param keyLocatorStruct a C ndn_KeyLocator struct where the name components array is already allocated.
25 */
26 void get(struct ndn_KeyLocator &keyLocatorStruct) const;
27
28 /**
29 * Clear this key locator, and set the values by copying from the ndn_KeyLocator struct.
30 * @param keyLocatorStruct a C ndn_KeyLocator struct
31 */
32 void set(const struct ndn_KeyLocator &keyLocatorStruct);
33
34 ndn_KeyLocatorType getType() const { return type_; }
35
Jeff Thompson63d02692013-08-16 12:09:07 -070036 const std::vector<unsigned char> &getKeyData() const { return keyData_; }
Jeff Thompson5cae5e52013-07-10 19:41:20 -070037
Jeff Thompson46bd45f2013-08-08 16:46:41 -070038 // TODO: Implement getKeyName.
39
40 void setType(ndn_KeyLocatorType type) { type_ = type; }
41
Jeff Thompson63d02692013-08-16 12:09:07 -070042 void setKeyData(const std::vector<unsigned char> &keyData) { keyData_ = keyData; }
43 void setKeyData(const unsigned char *keyData, unsigned int keyDataLength)
Jeff Thompson46bd45f2013-08-08 16:46:41 -070044 {
Jeff Thompson63d02692013-08-16 12:09:07 -070045 setVector(keyData_, keyData, keyDataLength);
Jeff Thompson46bd45f2013-08-08 16:46:41 -070046 }
47
Jeff Thompson63d02692013-08-16 12:09:07 -070048 /**
49 * @deprecated Use getKeyData().
50 */
51 const std::vector<unsigned char> &getKeyOrCertificate() const { return getKeyData(); }
52
53 /**
54 * @deprecated Use setKeyData.
55 */
56 void setKeyOrCertificate(const std::vector<unsigned char> &keyData) { setKeyData(keyData); }
57
58 /**
59 * @deprecated Use setKeyData.
60 */
61 void setKeyOrCertificate(const unsigned char *keyData, unsigned int keyDataLength) { setKeyData(keyData, keyDataLength); }
62
Jeff Thompson46bd45f2013-08-08 16:46:41 -070063 // TODO: Implement setKeyName.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070064
65private:
66 ndn_KeyLocatorType type_;
Jeff Thompson63d02692013-08-16 12:09:07 -070067 std::vector<unsigned char> keyData_; /**< used if type_ is ndn_KeyLocatorType_KEY or ndn_KeyLocatorType_CERTIFICATE */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070068 // TODO: Implement keyName.
69};
70
71}
72
73#endif