additional-description.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 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_CXX_SECURITY_ADDITIONAL_DESCRIPTION_HPP
23 #define NDN_CXX_SECURITY_ADDITIONAL_DESCRIPTION_HPP
24 
26 #include "ndn-cxx/encoding/tlv.hpp"
27 
28 #include <map>
29 
30 namespace ndn::security {
31 
36 class AdditionalDescription : private boost::equality_comparable<AdditionalDescription>
37 {
38 public:
39  class Error : public tlv::Error
40  {
41  public:
42  using tlv::Error::Error;
43  };
44 
45  using iterator = std::map<std::string, std::string>::iterator;
46  using const_iterator = std::map<std::string, std::string>::const_iterator;
47 
48 public:
52  AdditionalDescription() = default;
53 
57  explicit
58  AdditionalDescription(const Block& block);
59 
60  const std::string&
61  get(const std::string& key) const;
62 
63  void
64  set(const std::string& key, const std::string& value);
65 
66  bool
67  has(const std::string& key) const;
68 
69  size_t
70  size() const
71  {
72  return m_info.size();
73  }
74 
75  bool
76  empty() const
77  {
78  return m_info.empty();
79  }
80 
81  iterator
82  begin();
83 
84  iterator
85  end();
86 
88  begin() const;
89 
91  end() const;
92 
95  template<encoding::Tag TAG>
96  size_t
97  wireEncode(EncodingImpl<TAG>& encoder) const;
98 
101  const Block&
102  wireEncode() const;
103 
107  void
108  wireDecode(const Block& wire);
109 
110 private: // non-member operators
111  // NOTE: the following "hidden friend" operators are available via
112  // argument-dependent lookup only and must be defined inline.
113  // boost::equality_comparable provides != operator.
114 
115  friend bool
117  {
118  return lhs.m_info == rhs.m_info;
119  }
120 
121 private:
122  std::map<std::string, std::string> m_info;
123 
124  mutable Block m_wire;
125 };
126 
128 
129 std::ostream&
130 operator<<(std::ostream& os, const AdditionalDescription& desc);
131 
132 } // namespace ndn::security
133 
134 #endif // NDN_CXX_SECURITY_ADDITIONAL_DESCRIPTION_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
Represents an AdditionalDescription TLV element.
std::map< std::string, std::string >::const_iterator const_iterator
bool has(const std::string &key) const
std::map< std::string, std::string >::iterator iterator
const Block & wireEncode() const
Encode ValidityPeriod into TLV block.
friend bool operator==(const AdditionalDescription &lhs, const AdditionalDescription &rhs)
const std::string & get(const std::string &key) const
void wireDecode(const Block &wire)
Decode ValidityPeriod from TLV block.
AdditionalDescription()=default
Create an empty AdditionalDescription.
void set(const std::string &key, const std::string &value)
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:28
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
Contains the ndn-cxx security framework.
std::ostream & operator<<(std::ostream &os, const AdditionalDescription &desc)
@ AdditionalDescription
Definition: tlv.hpp:110