Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 4 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 5 | * 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 Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 7 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 8 | * 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 Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 11 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 12 | * 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 Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 15 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 16 | * 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 Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 18 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 19 | * @author Yingdi Yu <yingdi@cs.ucla.edu> |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 22 | #ifndef NDN_TOOLS_PIB_PIB_ENCODING_HPP |
| 23 | #define NDN_TOOLS_PIB_PIB_ENCODING_HPP |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 24 | |
| 25 | #include "pib-common.hpp" |
| 26 | #include <ndn-cxx/security/identity-certificate.hpp> |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace 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 | */ |
| 38 | class PibIdentity |
| 39 | { |
| 40 | public: |
| 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 | |
| 70 | private: |
| 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 | */ |
| 83 | class PibPublicKey |
| 84 | { |
| 85 | public: |
| 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 | |
| 114 | private: |
| 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 | */ |
| 129 | class PibCertificate |
| 130 | { |
| 131 | public: |
| 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 | |
| 158 | private: |
| 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 | */ |
| 170 | class PibNameList : noncopyable |
| 171 | { |
| 172 | public: |
| 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 | |
| 202 | private: |
| 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 | */ |
| 213 | class PibError : noncopyable |
| 214 | { |
| 215 | public: |
| 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 | |
| 251 | private: |
| 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 | */ |
| 265 | class PibUser |
| 266 | { |
| 267 | public: |
| 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 | |
| 306 | private: |
| 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 Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 316 | #endif // NDN_TOOLS_PIB_PIB_ENCODING_HPP |