Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -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 | |
| 22 | #ifndef NDN_SIGNATURE_INFO_HPP |
| 23 | #define NDN_SIGNATURE_INFO_HPP |
| 24 | |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 25 | #include "key-locator.hpp" |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 26 | #include "security/validity-period.hpp" |
Alexander Afanasyev | 1c6976d | 2014-07-13 11:40:50 -0700 | [diff] [blame] | 27 | #include <list> |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 28 | |
| 29 | namespace ndn { |
| 30 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 31 | /** @brief Represents a SignatureInfo TLV element |
| 32 | */ |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 33 | class SignatureInfo |
| 34 | { |
| 35 | public: |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 36 | class Error : public tlv::Error |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 37 | { |
| 38 | public: |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 39 | using tlv::Error::Error; |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 42 | /** @brief Create an invalid SignatureInfo |
| 43 | */ |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 44 | SignatureInfo(); |
| 45 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 46 | /** @brief Create with specified type |
| 47 | */ |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 48 | explicit |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 49 | SignatureInfo(tlv::SignatureTypeValue type); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 50 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 51 | /** @brief Create with specified type and KeyLocator |
| 52 | */ |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 53 | SignatureInfo(tlv::SignatureTypeValue type, const KeyLocator& keyLocator); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 54 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 55 | /** @brief Create from wire encoding |
| 56 | * @throw tlv::Error decode error |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 57 | */ |
| 58 | explicit |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 59 | SignatureInfo(const Block& wire); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 60 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 61 | /** @brief Fast encoding or block size estimation |
| 62 | * @param encoder EncodingEstimator or EncodingBuffer instance |
| 63 | */ |
| 64 | template<encoding::Tag TAG> |
| 65 | size_t |
| 66 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 67 | |
| 68 | /** @brief Encode to wire format |
| 69 | */ |
| 70 | const Block& |
| 71 | wireEncode() const; |
| 72 | |
| 73 | /** @brief Decode from wire format |
| 74 | * @throw tlv::Error decode error |
| 75 | */ |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 76 | void |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 77 | wireDecode(const Block& wire); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 78 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 79 | public: // field access |
| 80 | /** @brief Get SignatureType |
| 81 | * @return tlv::SignatureTypeValue, or -1 to indicate invalid SignatureInfo |
| 82 | */ |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 83 | int32_t |
| 84 | getSignatureType() const |
| 85 | { |
| 86 | return m_type; |
| 87 | } |
| 88 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 89 | /** @brief Set SignatureType |
| 90 | */ |
| 91 | void |
| 92 | setSignatureType(tlv::SignatureTypeValue type); |
| 93 | |
| 94 | /** @brief Check if KeyLocator exists |
| 95 | */ |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 96 | bool |
| 97 | hasKeyLocator() const |
| 98 | { |
| 99 | return m_hasKeyLocator; |
| 100 | } |
| 101 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 102 | /** @brief Get KeyLocator |
| 103 | * @throw Error KeyLocator does not exist |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 104 | */ |
| 105 | const KeyLocator& |
| 106 | getKeyLocator() const; |
| 107 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 108 | /** @brief Set KeyLocator |
| 109 | */ |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 110 | void |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 111 | setKeyLocator(const KeyLocator& keyLocator); |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 112 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 113 | /** @brief Unset KeyLocator |
| 114 | */ |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 115 | void |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 116 | unsetKeyLocator(); |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 117 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 118 | /** @brief Get ValidityPeriod |
| 119 | * @throw Error ValidityPeriod does not exist |
| 120 | */ |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 121 | security::ValidityPeriod |
| 122 | getValidityPeriod() const; |
| 123 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 124 | /** @brief Set ValidityPeriod |
| 125 | */ |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 126 | void |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 127 | setValidityPeriod(const security::ValidityPeriod& validityPeriod); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 128 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 129 | /** @brief Unset ValidityPeriod |
| 130 | */ |
| 131 | void |
| 132 | unsetValidityPeriod(); |
| 133 | |
| 134 | /** @brief Get SignatureType-specific sub-element |
| 135 | * @param type TLV-TYPE of sub-element |
| 136 | * @throw Error sub-element of specified type does not exist |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 137 | */ |
| 138 | const Block& |
| 139 | getTypeSpecificTlv(uint32_t type) const; |
| 140 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 141 | /** @brief Append SignatureType-specific sub-element |
| 142 | */ |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 143 | void |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 144 | appendTypeSpecificTlv(const Block& element); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 145 | |
| 146 | private: |
| 147 | int32_t m_type; |
| 148 | bool m_hasKeyLocator; |
| 149 | KeyLocator m_keyLocator; |
| 150 | std::list<Block> m_otherTlvs; |
| 151 | |
| 152 | mutable Block m_wire; |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 153 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 154 | friend bool |
| 155 | operator==(const SignatureInfo& lhs, const SignatureInfo& rhs); |
| 156 | |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 157 | friend std::ostream& |
| 158 | operator<<(std::ostream& os, const SignatureInfo& info); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 161 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(SignatureInfo); |
| 162 | |
Junxiao Shi | a9181d7 | 2017-08-13 16:47:45 +0000 | [diff] [blame] | 163 | bool |
| 164 | operator==(const SignatureInfo& lhs, const SignatureInfo& rhs); |
| 165 | |
| 166 | inline bool |
| 167 | operator!=(const SignatureInfo& lhs, const SignatureInfo& rhs) |
| 168 | { |
| 169 | return !(lhs == rhs); |
| 170 | } |
| 171 | |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 172 | std::ostream& |
| 173 | operator<<(std::ostream& os, const SignatureInfo& info); |
| 174 | |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 175 | } // namespace ndn |
| 176 | |
| 177 | #endif // NDN_SIGNATURE_INFO_HPP |