blob: 458348f5ea83d920bd496921058536f06a9c2fa9 [file] [log] [blame]
Yingdi Yu77627ab2015-07-21 16:13:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu0a312e52015-07-22 13:14:53 -07003 * Copyright (c) 2014-2015, Regents of the University of California.
Yingdi Yu77627ab2015-07-21 16:13:49 -07004 *
Yingdi Yu0a312e52015-07-22 13:14:53 -07005 * This file is part of ndn-tools (Named Data Networking Essential Tools).
6 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
Yingdi Yu77627ab2015-07-21 16:13:49 -07007 *
Yingdi Yu0a312e52015-07-22 13:14:53 -07008 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Yingdi Yu77627ab2015-07-21 16:13:49 -070011 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070012 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Yingdi Yu77627ab2015-07-21 16:13:49 -070015 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070016 * You should have received a copy of the GNU General Public License along with
17 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Yingdi Yu77627ab2015-07-21 16:13:49 -070018 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070019 * @author Yingdi Yu <yingdi@cs.ucla.edu>
Yingdi Yu77627ab2015-07-21 16:13:49 -070020 */
21
Yingdi Yu0a312e52015-07-22 13:14:53 -070022#ifndef NDN_TOOLS_PIB_PIB_ENCODING_HPP
23#define NDN_TOOLS_PIB_PIB_ENCODING_HPP
Yingdi Yu77627ab2015-07-21 16:13:49 -070024
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
Yingdi Yu0a312e52015-07-22 13:14:53 -0700316#endif // NDN_TOOLS_PIB_PIB_ENCODING_HPP