blob: 16281f9b81236eb05d9db044230b9f026c085c67 [file] [log] [blame]
Yingdi Yuea382942015-07-17 23:20:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento88a0d812017-08-19 21:31:42 -04002/*
Junxiao Shi68b53852018-07-25 13:56:38 -06003 * Copyright (c) 2013-2018 Regents of the University of California.
Yingdi Yuea382942015-07-17 23:20:44 -07004 *
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
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070022#ifndef NDN_SECURITY_V2_ADDITIONAL_DESCRIPTION_HPP
23#define NDN_SECURITY_V2_ADDITIONAL_DESCRIPTION_HPP
Yingdi Yuea382942015-07-17 23:20:44 -070024
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070025#include "../../common.hpp"
26#include "../../encoding/tlv.hpp"
27#include "../../encoding/block.hpp"
Yingdi Yuea382942015-07-17 23:20:44 -070028#include <map>
29
30namespace ndn {
31namespace security {
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070032namespace v2 {
Yingdi Yuea382942015-07-17 23:20:44 -070033
34/**
35 * @brief Abstraction of AdditionalDescription
36 * @sa docs/tutorials/certificate-format.rst
37 */
38class AdditionalDescription
39{
40public:
41 class Error : public tlv::Error
42 {
43 public:
Junxiao Shi68b53852018-07-25 13:56:38 -060044 using tlv::Error::Error;
Yingdi Yuea382942015-07-17 23:20:44 -070045 };
46
47 typedef std::map<std::string, std::string>::iterator iterator;
48 typedef std::map<std::string, std::string>::const_iterator const_iterator;
49
50public:
Yingdi Yuea382942015-07-17 23:20:44 -070051 /**
52 * @brief Create an empty AdditionalDescription
53 */
54 AdditionalDescription() = default;
55
56 /**
57 * @brief Create AdditionalDescription from @p block
58 */
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
Alexander Afanasyev464da532017-09-02 12:16:32 -040077 bool
78 empty() const
79 {
80 return m_info.empty();
81 }
82
Yingdi Yuea382942015-07-17 23:20:44 -070083 iterator
84 begin();
85
86 iterator
87 end();
88
89 const_iterator
90 begin() const;
91
92 const_iterator
93 end() const;
94
95 /** @brief Fast encoding or block size estimation
96 */
97 template<encoding::Tag TAG>
98 size_t
99 wireEncode(EncodingImpl<TAG>& encoder) const;
100
101 /** @brief Encode ValidityPeriod into TLV block
102 */
103 const Block&
104 wireEncode() const;
105
106 /** @brief Decode ValidityPeriod from TLV block
107 * @throw Error when an invalid TLV block supplied
108 */
109 void
110 wireDecode(const Block& wire);
111
112public: // EqualityComparable concept
Yingdi Yuea382942015-07-17 23:20:44 -0700113 bool
114 operator==(const AdditionalDescription& other) const;
115
116 bool
117 operator!=(const AdditionalDescription& other) const;
118
119private:
Yingdi Yuea382942015-07-17 23:20:44 -0700120 std::map<std::string, std::string> m_info;
121
122 mutable Block m_wire;
123};
124
Davide Pesavento88a0d812017-08-19 21:31:42 -0400125NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(AdditionalDescription);
126
Yingdi Yuea382942015-07-17 23:20:44 -0700127std::ostream&
128operator<<(std::ostream& os, const AdditionalDescription& period);
129
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700130} // namespace v2
131
132using v2::AdditionalDescription;
133
Yingdi Yuea382942015-07-17 23:20:44 -0700134} // namespace security
135} // namespace ndn
136
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700137#endif // NDN_SECURITY_V2_ADDITIONAL_DESCRIPTION_HPP