blob: d5142ae61bdefe396f09b3175fd17aab07561d28 [file] [log] [blame]
Yingdi Yuea382942015-07-17 23:20:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev2fa59392016-07-29 17:24:23 -07003 * Copyright (c) 2013-2016 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:
44 explicit
45 Error(const std::string& what)
46 : tlv::Error(what)
47 {
48 }
49 };
50
51 typedef std::map<std::string, std::string>::iterator iterator;
52 typedef std::map<std::string, std::string>::const_iterator const_iterator;
53
54public:
55
56 /**
57 * @brief Create an empty AdditionalDescription
58 */
59 AdditionalDescription() = default;
60
61 /**
62 * @brief Create AdditionalDescription from @p block
63 */
64 explicit
65 AdditionalDescription(const Block& block);
66
67 const std::string&
68 get(const std::string& key) const;
69
70 void
71 set(const std::string& key, const std::string& value);
72
73 bool
74 has(const std::string& key) const;
75
76 size_t
77 size() const
78 {
79 return m_info.size();
80 }
81
82 iterator
83 begin();
84
85 iterator
86 end();
87
88 const_iterator
89 begin() const;
90
91 const_iterator
92 end() const;
93
94 /** @brief Fast encoding or block size estimation
95 */
96 template<encoding::Tag TAG>
97 size_t
98 wireEncode(EncodingImpl<TAG>& encoder) const;
99
100 /** @brief Encode ValidityPeriod into TLV block
101 */
102 const Block&
103 wireEncode() const;
104
105 /** @brief Decode ValidityPeriod from TLV block
106 * @throw Error when an invalid TLV block supplied
107 */
108 void
109 wireDecode(const Block& wire);
110
111public: // EqualityComparable concept
112
113 bool
114 operator==(const AdditionalDescription& other) const;
115
116 bool
117 operator!=(const AdditionalDescription& other) const;
118
119private:
120
121 std::map<std::string, std::string> m_info;
122
123 mutable Block m_wire;
124};
125
126std::ostream&
127operator<<(std::ostream& os, const AdditionalDescription& period);
128
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700129} // namespace v2
130
131using v2::AdditionalDescription;
132
Yingdi Yuea382942015-07-17 23:20:44 -0700133} // namespace security
134} // namespace ndn
135
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700136#endif // NDN_SECURITY_V2_ADDITIONAL_DESCRIPTION_HPP