blob: 9ebb4c45d666486094cd559398005b7342c40f7b [file] [log] [blame]
Yingdi Yu77627ab2015-07-21 16:13:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_PIB_PIB_ENCODING_HPP
23#define NDN_PIB_PIB_ENCODING_HPP
24
25#include "pib-common.hpp"
26#include <ndn-cxx/security/identity-certificate.hpp>
27
28namespace ndn {
29namespace pib {
30
31/**
32 * @brief Abstraction of pib::Identity TLV.
33 *
34 * This class is copyable since it is used by a variety of pib parameters
35 *
36 * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base#Query-Responses
37 */
38class PibIdentity
39{
40public:
41 PibIdentity();
42
43 explicit
44 PibIdentity(const Name& identity);
45
46 explicit
47 PibIdentity(const Block& wire);
48
49 const Name&
50 getIdentity() const
51 {
52 return m_identity;
53 }
54
55 template<bool T>
56 size_t
57 wireEncode(EncodingImpl<T>& block) const;
58
59 const Block&
60 wireEncode() const;
61
62 /**
63 * @brief Decode PibIdentity from a wire encoded block
64 *
65 * @throws tlv::Error if decoding fails
66 */
67 void
68 wireDecode(const Block& wire);
69
70private:
71 Name m_identity;
72
73 mutable Block m_wire;
74};
75
76/**
77 * @brief Abstraction of pib::PublicKey TLV.
78 *
79 * This class is copyable since it is used by a variety of pib parameters
80 *
81 * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base#Query-Responses
82 */
83class PibPublicKey
84{
85public:
86 PibPublicKey();
87
88 PibPublicKey(const Name& keyName, const PublicKey& key);
89
90 explicit
91 PibPublicKey(const Block& wire);
92
93 const Name&
94 getKeyName() const;
95
96 const PublicKey&
97 getPublicKey() const;
98
99 template<bool T>
100 size_t
101 wireEncode(EncodingImpl<T>& block) const;
102
103 const Block&
104 wireEncode() const;
105
106 /**
107 * @brief Decode PibPublicKey from a wire encoded block
108 *
109 * @throws tlv::Error if decoding fails
110 */
111 void
112 wireDecode(const Block& wire);
113
114private:
115 bool m_isValueSet;
116 Name m_keyName;
117 PublicKey m_key;
118
119 mutable Block m_wire;
120};
121
122/**
123 * @brief Abstraction of pib::Certificate TLV.
124 *
125 * This class is copyable since it is used by a variety of pib parameters
126 *
127 * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base#Query-Responses
128 */
129class PibCertificate
130{
131public:
132 PibCertificate();
133
134 explicit
135 PibCertificate(const IdentityCertificate& certificate);
136
137 explicit
138 PibCertificate(const Block& wire);
139
140 const IdentityCertificate&
141 getCertificate() const;
142
143 template<bool T>
144 size_t
145 wireEncode(EncodingImpl<T>& block) const;
146
147 const Block&
148 wireEncode() const;
149
150 /**
151 * @brief Decode PibCertificate from a wire encoded block
152 *
153 * @throws tlv::Error if decoding fails
154 */
155 void
156 wireDecode(const Block& wire);
157
158private:
159 bool m_isValueSet;
160 IdentityCertificate m_certificate;
161
162 mutable Block m_wire;
163};
164
165/**
166 * @brief Abstraction of pib::NameList TLV.
167 *
168 * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base#List-Parameters
169 */
170class PibNameList : noncopyable
171{
172public:
173 PibNameList();
174
175 explicit
176 PibNameList(const std::vector<Name>& names);
177
178 explicit
179 PibNameList(const Block& wire);
180
181 const std::vector<Name>&
182 getNameList() const
183 {
184 return m_names;
185 }
186
187 template<bool T>
188 size_t
189 wireEncode(EncodingImpl<T>& block) const;
190
191 const Block&
192 wireEncode() const;
193
194 /**
195 * @brief Decode PibCertificate from a wire encoded block
196 *
197 * @throws tlv::Error if decoding fails
198 */
199 void
200 wireDecode(const Block& wire);
201
202private:
203 std::vector<Name> m_names;
204
205 mutable Block m_wire;
206};
207
208/**
209 * @brief Abstraction of pib::Error TLV.
210 *
211 * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base#Query-Responses
212 */
213class PibError : noncopyable
214{
215public:
216 PibError();
217
218 explicit
219 PibError(const pib::ErrCode errCode, const std::string& msg = "");
220
221 explicit
222 PibError(const Block& wire);
223
224 pib::ErrCode
225 getErrorCode() const
226 {
227 return m_errCode;
228 }
229
230 const std::string&
231 getErrorMsg() const
232 {
233 return m_msg;
234 }
235
236 template<bool T>
237 size_t
238 wireEncode(EncodingImpl<T>& block) const;
239
240 const Block&
241 wireEncode() const;
242
243 /**
244 * @brief Decode PibCertificate from a wire encoded block
245 *
246 * @throws tlv::Error if decoding fails
247 */
248 void
249 wireDecode(const Block& wire);
250
251private:
252 pib::ErrCode m_errCode;
253 std::string m_msg;
254
255 mutable Block m_wire;
256};
257
258/**
259 * @brief Abstraction of pib::User TLV.
260 *
261 * This class is copyable since it is used by a variety of pib parameters
262 *
263 * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base#Query-Responses
264 */
265class PibUser
266{
267public:
268 PibUser();
269
270 explicit
271 PibUser(const Block& wire);
272
273 void
274 setMgmtCert(const IdentityCertificate& mgmtCert);
275
276 const IdentityCertificate&
277 getMgmtCert() const
278 {
279 return m_mgmtCert;
280 }
281
282 void
283 setTpmLocator(const std::string& tpmLocator);
284
285 const std::string&
286 getTpmLocator() const
287 {
288 return m_tpmLocator;
289 }
290
291 template<bool T>
292 size_t
293 wireEncode(EncodingImpl<T>& block) const;
294
295 const Block&
296 wireEncode() const;
297
298 /**
299 * @brief Decode PibCertificate from a wire encoded block
300 *
301 * @throws tlv::Error if decoding fails
302 */
303 void
304 wireDecode(const Block& wire);
305
306private:
307 IdentityCertificate m_mgmtCert;
308 std::string m_tpmLocator;
309
310 mutable Block m_wire;
311};
312
313} // namespace pib
314} // namespace ndn
315
316#endif // NDN_PIB_PIB_ENCODING_HPP