Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 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 | |
| 25 | #include "encoding/tlv.hpp" |
| 26 | #include "key-locator.hpp" |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 27 | #include "security/validity-period.hpp" |
Alexander Afanasyev | 1c6976d | 2014-07-13 11:40:50 -0700 | [diff] [blame] | 28 | #include <list> |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | |
| 32 | class SignatureInfo |
| 33 | { |
| 34 | public: |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 35 | class Error : public tlv::Error |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 36 | { |
| 37 | public: |
| 38 | explicit |
| 39 | Error(const std::string& what) |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 40 | : tlv::Error(what) |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | SignatureInfo(); |
| 46 | |
| 47 | explicit |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 48 | SignatureInfo(tlv::SignatureTypeValue type); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 49 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 50 | SignatureInfo(tlv::SignatureTypeValue type, const KeyLocator& keyLocator); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * @brief Generate SignatureInfo from a block |
| 54 | * |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 55 | * @throws tlv::Error if supplied block is not formatted correctly |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 56 | */ |
| 57 | explicit |
| 58 | SignatureInfo(const Block& block); |
| 59 | |
| 60 | /// @brief Set SignatureType |
| 61 | void |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 62 | setSignatureType(tlv::SignatureTypeValue type); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 63 | |
| 64 | /// @brief Get SignatureType |
| 65 | int32_t |
| 66 | getSignatureType() const |
| 67 | { |
| 68 | return m_type; |
| 69 | } |
| 70 | |
| 71 | /// @brief Check if KeyLocator is set |
| 72 | bool |
| 73 | hasKeyLocator() const |
| 74 | { |
| 75 | return m_hasKeyLocator; |
| 76 | } |
| 77 | |
| 78 | /// @brief Set KeyLocator |
| 79 | void |
| 80 | setKeyLocator(const KeyLocator& keyLocator); |
| 81 | |
Alexander Afanasyev | a7c7f9d | 2014-07-13 11:51:52 -0700 | [diff] [blame] | 82 | /// @brief Unset KeyLocator |
| 83 | void |
| 84 | unsetKeyLocator(); |
| 85 | |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 86 | /** |
| 87 | * @brief Get KeyLocator |
| 88 | * |
| 89 | * @throws SignatureInfo::Error if keyLocator does not exist |
| 90 | */ |
| 91 | const KeyLocator& |
| 92 | getKeyLocator() const; |
| 93 | |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 94 | /// @brief Set ValidityPeriod |
| 95 | void |
| 96 | setValidityPeriod(const security::ValidityPeriod& validityPeriod); |
| 97 | |
| 98 | /// @brief Unset ValidityPeriod |
| 99 | void |
| 100 | unsetValidityPeriod(); |
| 101 | |
| 102 | /// @brief Get ValidityPeriod |
| 103 | security::ValidityPeriod |
| 104 | getValidityPeriod() const; |
| 105 | |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 106 | /// @brief Append signature type specific tlv block |
| 107 | void |
| 108 | appendTypeSpecificTlv(const Block& block); |
| 109 | |
| 110 | /** |
| 111 | * @brief Get signature type specific tlv block |
| 112 | * |
| 113 | * @throws SignatureInfo::Error if the block does not exist |
| 114 | */ |
| 115 | const Block& |
| 116 | getTypeSpecificTlv(uint32_t type) const; |
| 117 | |
| 118 | /// @brief Encode to a wire format or estimate wire format |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 119 | template<encoding::Tag TAG> |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 120 | size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 121 | wireEncode(EncodingImpl<TAG>& encoder) const; |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 122 | |
| 123 | /// @brief Encode to a wire format |
| 124 | const Block& |
| 125 | wireEncode() const; |
| 126 | |
| 127 | /// @brief Decode from a wire format |
| 128 | void |
| 129 | wireDecode(const Block& wire); |
| 130 | |
| 131 | public: // EqualityComparable concept |
| 132 | bool |
| 133 | operator==(const SignatureInfo& rhs) const; |
| 134 | |
| 135 | bool |
| 136 | operator!=(const SignatureInfo& rhs) const |
| 137 | { |
| 138 | return !(*this == rhs); |
| 139 | } |
| 140 | |
| 141 | private: |
| 142 | int32_t m_type; |
| 143 | bool m_hasKeyLocator; |
| 144 | KeyLocator m_keyLocator; |
| 145 | std::list<Block> m_otherTlvs; |
| 146 | |
| 147 | mutable Block m_wire; |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame^] | 148 | |
| 149 | friend std::ostream& |
| 150 | operator<<(std::ostream& os, const SignatureInfo& info); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame^] | 153 | std::ostream& |
| 154 | operator<<(std::ostream& os, const SignatureInfo& info); |
| 155 | |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 156 | } // namespace ndn |
| 157 | |
| 158 | #endif // NDN_SIGNATURE_INFO_HPP |