blob: cf1c6ea035c5a334f88ce8bb8cdbe041419ca096 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
9 */
10
11#ifndef NDN_KEY_LOCATOR_H
12#define NDN_KEY_LOCATOR_H
13
14#include "ndn-cpp/fields/blob.h"
15#include "ndn-cpp/fields/name.h"
16
17namespace ndn {
18
19/**
20 * @brief Class providing an interface to work with key locators in NDN data packets
21 */
22class KeyLocator
23{
24public:
25 /**
26 * @brief Key locator type
27 *
28 * Key locator can be only of the defined types, i.e., it cannot contain key bits and key name
29 */
30 enum Type
31 {
32 NOTSET=-1, ///< @brief Unset key locator type, any attempt to use KeyLocator of NOTSET type will cause an exception
33 KEY, ///< @brief Key locator contains key bits
34 CERTIFICATE, ///< @brief Key locator contains certificate bits
35 KEYNAME ///< @brief key locator contains name of the key
36 };
37
38 /**
39 * @brief Default constructor
40 */
41 KeyLocator ();
42
43 /**
44 * @brief Copy constructor
45 */
46 KeyLocator (const KeyLocator &keyLocator);
47
48 /**
49 * @brief Destructor
50 */
51 ~KeyLocator ();
52
53 /**
54 * @brief Copy operator
55 */
56 KeyLocator &
57 operator = (const KeyLocator &keyLocator);
58
59 /**
60 * @brief Set type of the key locator
61 * @param type key locator type, @see Type
62 *
63 * If type of the key locator changes, setType will delete any previously allocated
64 * data, allocate appropriate type and store it in m_data
65 */
66 void
67 setType (Type type);
68
69 /**
70 * @brief Get type of the key locator
71 */
72 inline Type
73 getType () const;
74
75 /**
76 * @brief Get const reference to key bits, associated with key locator
77 *
78 * If key locator type is not KEY, then an exception will be thrown
79 */
80 const Blob &
81 getKey () const;
82
83 /**
84 * @brief Get reference to key bits, associated with key locator
85 *
86 * If key locator type is not KEY, then an exception will be thrown
87 */
88 Blob &
89 getKey ();
90
91 /**
92 * @brief Set key bits, associated with key locator
93 * @param key const reference to key bits
94 *
95 * If key locator type is not KEY, then an exception will be thrown
96 */
97 void
98 setKey (const Blob &key);
99
100 /**
101 * @brief Get const reference to certificated bits, associated with key locator
102 *
103 * If key locator type is not CERTIFICATE, then an exception will be thrown
104 */
105 const Blob &
106 getCertificate () const;
107
108 /**
109 * @brief Get reference to certificated bits, associated with key locator
110 *
111 * If key locator type is not CERTIFICATE, then an exception will be thrown
112 */
113 Blob &
114 getCertificate ();
115
116 /**
117 * @brief Set certificated bits, associated with key locator
118 * @param certificate const reference to certificate bits
119 *
120 * If key locator type is not CERTIFICATE, then an exception will be thrown
121 */
122 void
123 setCertificate (const Blob &certificate);
124
125 /**
126 * @brief Get const reference to key name, associated with key locator
127 *
128 * If key locator type is not KEYNAME, then an exception will be thrown
129 */
130 const Name &
131 getKeyName () const;
132
133 /**
134 * @brief Get reference to key name, associated with key locator
135 *
136 * If key locator type is not KEYNAME, then an exception will be thrown
137 */
138 Name &
139 getKeyName ();
140
141 /**
142 * @brief Set key name, associated with key locator
143 * @param name const reference to key name
144 *
145 * If key locator type is not KEYNAME, then an exception will be thrown
146 */
147 void
148 setKeyName (const Name &name);
149
150private:
151 void
152 deleteData ();
153
154private:
155 Type m_type;
156 void *m_data;
157};
158
159inline KeyLocator::Type
160KeyLocator::getType () const
161{
162 return m_type;
163}
164
165
166} // ndn
167
168#endif // NDN_KEY_LOCATOR_H