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_UPDATE_PARAM_HPP |
| 23 | #define NDN_TOOLS_PIB_UPDATE_PARAM_HPP |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 24 | |
| 25 | #include "pib-common.hpp" |
| 26 | #include "pib-encoding.hpp" |
| 27 | #include <ndn-cxx/name.hpp> |
| 28 | #include <ndn-cxx/security/identity-certificate.hpp> |
| 29 | |
| 30 | namespace ndn { |
| 31 | namespace pib { |
| 32 | |
| 33 | /** |
| 34 | * @brief UpdateParam is the abstraction of PIB Update parameter. |
| 35 | * |
| 36 | * PibUpdateParam := PIB-UPDATE-PARAM-TYPE TLV-LENGTH |
| 37 | * (PibIdentity | PibPublicKey | PibCertificate) |
| 38 | * PibDefaultOpt |
| 39 | * |
| 40 | * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PublicKey_Info_Base#Update-Parameters |
| 41 | */ |
| 42 | |
| 43 | class UpdateParam : noncopyable |
| 44 | { |
| 45 | public: |
| 46 | class Error : public tlv::Error |
| 47 | { |
| 48 | public: |
| 49 | explicit |
| 50 | Error(const std::string& what) |
| 51 | : tlv::Error(what) |
| 52 | { |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | UpdateParam(); |
| 57 | |
| 58 | explicit |
| 59 | UpdateParam(const PibUser& user); |
| 60 | |
| 61 | explicit |
| 62 | UpdateParam(const Name& identity, DefaultOpt defaultOpt = DEFAULT_OPT_NO); |
| 63 | |
| 64 | UpdateParam(const Name& keyName, const PublicKey& key, DefaultOpt defaultOpt = DEFAULT_OPT_NO); |
| 65 | |
| 66 | explicit |
| 67 | UpdateParam(const IdentityCertificate& certificate, DefaultOpt defaultOpt = DEFAULT_OPT_NO); |
| 68 | |
| 69 | explicit |
| 70 | UpdateParam(const Block& wire); |
| 71 | |
| 72 | tlv::pib::ParamType |
| 73 | getParamType() const |
| 74 | { |
| 75 | return tlv::pib::UpdateParam; |
| 76 | } |
| 77 | |
| 78 | tlv::pib::EntityType |
| 79 | getEntityType() const |
| 80 | { |
| 81 | return m_entityType; |
| 82 | } |
| 83 | |
| 84 | const PibUser& |
| 85 | getUser() const; |
| 86 | |
| 87 | const PibIdentity& |
| 88 | getIdentity() const; |
| 89 | |
| 90 | const PibPublicKey& |
| 91 | getPublicKey() const; |
| 92 | |
| 93 | const PibCertificate& |
| 94 | getCertificate() const; |
| 95 | |
| 96 | pib::DefaultOpt |
| 97 | getDefaultOpt() const |
| 98 | { |
| 99 | return m_defaultOpt; |
| 100 | } |
| 101 | |
| 102 | /// @brief Encode to a wire format or estimate wire format |
| 103 | template<bool T> |
| 104 | size_t |
| 105 | wireEncode(EncodingImpl<T>& block) const; |
| 106 | |
| 107 | /// @brief Encode to a wire format |
| 108 | const Block& |
| 109 | wireEncode() const; |
| 110 | |
| 111 | /** |
| 112 | * @brief Decode GetParam from a wire encoded block |
| 113 | * |
| 114 | * @throws Error if decoding fails |
| 115 | */ |
| 116 | void |
| 117 | wireDecode(const Block& wire); |
| 118 | |
| 119 | public: |
| 120 | static const std::string VERB; |
| 121 | |
| 122 | private: |
| 123 | tlv::pib::EntityType m_entityType; |
| 124 | PibUser m_user; |
| 125 | PibIdentity m_identity; |
| 126 | PibPublicKey m_key; |
| 127 | PibCertificate m_certificate; |
| 128 | pib::DefaultOpt m_defaultOpt; |
| 129 | |
| 130 | mutable Block m_wire; |
| 131 | }; |
| 132 | |
| 133 | } // namespace pib |
| 134 | } // namespace ndn |
| 135 | |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 136 | #endif // NDN_TOOLS_PIB_UPDATE_PARAM_HPP |