Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 22 | #ifndef NDN_SECURITY_V2_ADDITIONAL_DESCRIPTION_HPP |
| 23 | #define NDN_SECURITY_V2_ADDITIONAL_DESCRIPTION_HPP |
Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 25 | #include "../../common.hpp" |
| 26 | #include "../../encoding/tlv.hpp" |
| 27 | #include "../../encoding/block.hpp" |
Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 28 | #include <map> |
| 29 | |
| 30 | namespace ndn { |
| 31 | namespace security { |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 32 | namespace v2 { |
Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * @brief Abstraction of AdditionalDescription |
| 36 | * @sa docs/tutorials/certificate-format.rst |
| 37 | */ |
| 38 | class AdditionalDescription |
| 39 | { |
| 40 | public: |
| 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 | |
| 54 | public: |
Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 55 | /** |
| 56 | * @brief Create an empty AdditionalDescription |
| 57 | */ |
| 58 | AdditionalDescription() = default; |
| 59 | |
| 60 | /** |
| 61 | * @brief Create AdditionalDescription from @p block |
| 62 | */ |
| 63 | explicit |
| 64 | AdditionalDescription(const Block& block); |
| 65 | |
| 66 | const std::string& |
| 67 | get(const std::string& key) const; |
| 68 | |
| 69 | void |
| 70 | set(const std::string& key, const std::string& value); |
| 71 | |
| 72 | bool |
| 73 | has(const std::string& key) const; |
| 74 | |
| 75 | size_t |
| 76 | size() const |
| 77 | { |
| 78 | return m_info.size(); |
| 79 | } |
| 80 | |
| 81 | iterator |
| 82 | begin(); |
| 83 | |
| 84 | iterator |
| 85 | end(); |
| 86 | |
| 87 | const_iterator |
| 88 | begin() const; |
| 89 | |
| 90 | const_iterator |
| 91 | end() const; |
| 92 | |
| 93 | /** @brief Fast encoding or block size estimation |
| 94 | */ |
| 95 | template<encoding::Tag TAG> |
| 96 | size_t |
| 97 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 98 | |
| 99 | /** @brief Encode ValidityPeriod into TLV block |
| 100 | */ |
| 101 | const Block& |
| 102 | wireEncode() const; |
| 103 | |
| 104 | /** @brief Decode ValidityPeriod from TLV block |
| 105 | * @throw Error when an invalid TLV block supplied |
| 106 | */ |
| 107 | void |
| 108 | wireDecode(const Block& wire); |
| 109 | |
| 110 | public: // EqualityComparable concept |
Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 111 | bool |
| 112 | operator==(const AdditionalDescription& other) const; |
| 113 | |
| 114 | bool |
| 115 | operator!=(const AdditionalDescription& other) const; |
| 116 | |
| 117 | private: |
Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 118 | std::map<std::string, std::string> m_info; |
| 119 | |
| 120 | mutable Block m_wire; |
| 121 | }; |
| 122 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame^] | 123 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(AdditionalDescription); |
| 124 | |
Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 125 | std::ostream& |
| 126 | operator<<(std::ostream& os, const AdditionalDescription& period); |
| 127 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 128 | } // namespace v2 |
| 129 | |
| 130 | using v2::AdditionalDescription; |
| 131 | |
Yingdi Yu | ea38294 | 2015-07-17 23:20:44 -0700 | [diff] [blame] | 132 | } // namespace security |
| 133 | } // namespace ndn |
| 134 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 135 | #endif // NDN_SECURITY_V2_ADDITIONAL_DESCRIPTION_HPP |