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 | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2015 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" |
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 | |
| 31 | class SignatureInfo |
| 32 | { |
| 33 | public: |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 34 | class Error : public tlv::Error |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 35 | { |
| 36 | public: |
| 37 | explicit |
| 38 | Error(const std::string& what) |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 39 | : tlv::Error(what) |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | SignatureInfo(); |
| 45 | |
| 46 | explicit |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 47 | SignatureInfo(tlv::SignatureTypeValue type); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 48 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 49 | SignatureInfo(tlv::SignatureTypeValue type, const KeyLocator& keyLocator); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * @brief Generate SignatureInfo from a block |
| 53 | * |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 54 | * @throws tlv::Error if supplied block is not formatted correctly |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 55 | */ |
| 56 | explicit |
| 57 | SignatureInfo(const Block& block); |
| 58 | |
| 59 | /// @brief Set SignatureType |
| 60 | void |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 61 | setSignatureType(tlv::SignatureTypeValue type); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 62 | |
| 63 | /// @brief Get SignatureType |
| 64 | int32_t |
| 65 | getSignatureType() const |
| 66 | { |
| 67 | return m_type; |
| 68 | } |
| 69 | |
| 70 | /// @brief Check if KeyLocator is set |
| 71 | bool |
| 72 | hasKeyLocator() const |
| 73 | { |
| 74 | return m_hasKeyLocator; |
| 75 | } |
| 76 | |
| 77 | /// @brief Set KeyLocator |
| 78 | void |
| 79 | setKeyLocator(const KeyLocator& keyLocator); |
| 80 | |
Alexander Afanasyev | a7c7f9d | 2014-07-13 11:51:52 -0700 | [diff] [blame] | 81 | /// @brief Unset KeyLocator |
| 82 | void |
| 83 | unsetKeyLocator(); |
| 84 | |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 85 | /** |
| 86 | * @brief Get KeyLocator |
| 87 | * |
| 88 | * @throws SignatureInfo::Error if keyLocator does not exist |
| 89 | */ |
| 90 | const KeyLocator& |
| 91 | getKeyLocator() const; |
| 92 | |
| 93 | /// @brief Append signature type specific tlv block |
| 94 | void |
| 95 | appendTypeSpecificTlv(const Block& block); |
| 96 | |
| 97 | /** |
| 98 | * @brief Get signature type specific tlv block |
| 99 | * |
| 100 | * @throws SignatureInfo::Error if the block does not exist |
| 101 | */ |
| 102 | const Block& |
| 103 | getTypeSpecificTlv(uint32_t type) const; |
| 104 | |
| 105 | /// @brief Encode to a wire format or estimate wire format |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 106 | template<encoding::Tag TAG> |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 107 | size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 108 | wireEncode(EncodingImpl<TAG>& block) const; |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 109 | |
| 110 | /// @brief Encode to a wire format |
| 111 | const Block& |
| 112 | wireEncode() const; |
| 113 | |
| 114 | /// @brief Decode from a wire format |
| 115 | void |
| 116 | wireDecode(const Block& wire); |
| 117 | |
| 118 | public: // EqualityComparable concept |
| 119 | bool |
| 120 | operator==(const SignatureInfo& rhs) const; |
| 121 | |
| 122 | bool |
| 123 | operator!=(const SignatureInfo& rhs) const |
| 124 | { |
| 125 | return !(*this == rhs); |
| 126 | } |
| 127 | |
| 128 | private: |
| 129 | int32_t m_type; |
| 130 | bool m_hasKeyLocator; |
| 131 | KeyLocator m_keyLocator; |
| 132 | std::list<Block> m_otherTlvs; |
| 133 | |
| 134 | mutable Block m_wire; |
| 135 | }; |
| 136 | |
| 137 | } // namespace ndn |
| 138 | |
| 139 | #endif // NDN_SIGNATURE_INFO_HPP |