blob: 739faf9e7adf54b7b7b491db3b721afd1f87fb83 [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_UPDATE_PARAM_HPP
23#define NDN_TOOLS_PIB_UPDATE_PARAM_HPP
Yingdi Yu77627ab2015-07-21 16:13:49 -070024
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
30namespace ndn {
31namespace 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
43class UpdateParam : noncopyable
44{
45public:
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
119public:
120 static const std::string VERB;
121
122private:
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 Yu0a312e52015-07-22 13:14:53 -0700136#endif // NDN_TOOLS_PIB_UPDATE_PARAM_HPP