Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
| 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: |
| 34 | class Error : public Tlv::Error |
| 35 | { |
| 36 | public: |
| 37 | explicit |
| 38 | Error(const std::string& what) |
| 39 | : Tlv::Error(what) |
| 40 | { |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | SignatureInfo(); |
| 45 | |
| 46 | explicit |
| 47 | SignatureInfo(Tlv::SignatureTypeValue type); |
| 48 | |
| 49 | SignatureInfo(Tlv::SignatureTypeValue type, const KeyLocator& keyLocator); |
| 50 | |
| 51 | /** |
| 52 | * @brief Generate SignatureInfo from a block |
| 53 | * |
| 54 | * @throws Tlv::Error if supplied block is not formatted correctly |
| 55 | */ |
| 56 | explicit |
| 57 | SignatureInfo(const Block& block); |
| 58 | |
| 59 | /// @brief Set SignatureType |
| 60 | void |
| 61 | setSignatureType(Tlv::SignatureTypeValue type); |
| 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 |
| 106 | template<bool T> |
| 107 | size_t |
| 108 | wireEncode(EncodingImpl<T>& block) const; |
| 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 |