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-2022 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 {
31 namespace security {
32 inline namespace v2 {
33 
39 {
40 public:
41  class Error : public tlv::Error
42  {
43  public:
44  using tlv::Error::Error;
45  };
46 
47  using iterator = std::map<std::string, std::string>::iterator;
48  using const_iterator = std::map<std::string, std::string>::const_iterator;
49 
50 public:
54  AdditionalDescription() = default;
55 
59  explicit
60  AdditionalDescription(const Block& block);
61 
62  const std::string&
63  get(const std::string& key) const;
64 
65  void
66  set(const std::string& key, const std::string& value);
67 
68  bool
69  has(const std::string& key) const;
70 
71  size_t
72  size() const
73  {
74  return m_info.size();
75  }
76 
77  bool
78  empty() const
79  {
80  return m_info.empty();
81  }
82 
83  iterator
84  begin();
85 
86  iterator
87  end();
88 
90  begin() const;
91 
93  end() const;
94 
97  template<encoding::Tag TAG>
98  size_t
99  wireEncode(EncodingImpl<TAG>& encoder) const;
100 
103  const Block&
104  wireEncode() const;
105 
109  void
110  wireDecode(const Block& wire);
111 
112 private: // EqualityComparable concept
113  // NOTE: the following "hidden friend" operators are available via
114  // argument-dependent lookup only and must be defined inline.
115 
116  friend bool
118  {
119  return lhs.m_info == rhs.m_info;
120  }
121 
122  friend bool
124  {
125  return lhs.m_info != rhs.m_info;
126  }
127 
128 private:
129  std::map<std::string, std::string> m_info;
130 
131  mutable Block m_wire;
132 };
133 
135 
136 std::ostream&
137 operator<<(std::ostream& os, const AdditionalDescription& desc);
138 
139 } // inline namespace v2
140 
141 } // namespace security
142 } // namespace ndn
143 
144 #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
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)
void set(const std::string &key, const std::string &value)
const std::string & get(const std::string &key) const
bool has(const std::string &key) const
void wireDecode(const Block &wire)
Decode ValidityPeriod from TLV block.
AdditionalDescription()=default
Create an empty AdditionalDescription.
friend bool operator!=(const AdditionalDescription &lhs, const AdditionalDescription &rhs)
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
std::ostream & operator<<(std::ostream &os, const AdditionalDescription &desc)
Definition: data.cpp:25