Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 2 | /* |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2020 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 22 | #ifndef NDN_CXX_DATA_HPP |
| 23 | #define NDN_CXX_DATA_HPP |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 25 | #include "ndn-cxx/detail/packet-base.hpp" |
| 26 | #include "ndn-cxx/encoding/block.hpp" |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 27 | #include "ndn-cxx/meta-info.hpp" |
| 28 | #include "ndn-cxx/name.hpp" |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 29 | #include "ndn-cxx/signature.hpp" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 30 | |
| 31 | namespace ndn { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 33 | /** @brief Represents a %Data packet. |
| 34 | * @sa https://named-data.net/doc/NDN-packet-spec/0.3/data.html |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 35 | */ |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 36 | class Data : public PacketBase, public std::enable_shared_from_this<Data> |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 37 | { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 38 | public: |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 39 | class Error : public tlv::Error |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 40 | { |
| 41 | public: |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 42 | using tlv::Error::Error; |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 43 | }; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 44 | |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 45 | /** @brief Construct an unsigned Data packet with given @p name and empty Content. |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 46 | * @warning In certain contexts that use `Data::shared_from_this()`, Data must be created using |
| 47 | * `std::make_shared`. Otherwise, `shared_from_this()` may trigger undefined behavior. |
| 48 | * One example where this is necessary is storing Data into a subclass of InMemoryStorage. |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 49 | */ |
Junxiao Shi | 9b84535 | 2017-07-24 05:04:56 +0000 | [diff] [blame] | 50 | explicit |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 51 | Data(const Name& name = Name()); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 52 | |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 53 | /** @brief Construct a Data packet by decoding from @p wire. |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 54 | * @param wire TLV block of type tlv::Data; may be signed or unsigned. |
| 55 | * @warning In certain contexts that use `Data::shared_from_this()`, Data must be created using |
| 56 | * `std::make_shared`. Otherwise, `shared_from_this()` may trigger undefined behavior. |
| 57 | * One example where this is necessary is storing Data into a subclass of InMemoryStorage. |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 58 | */ |
| 59 | explicit |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 60 | Data(const Block& wire); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 61 | |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 62 | /** @brief Prepend wire encoding to @p encoder |
| 63 | * @param encoder EncodingEstimator or EncodingBuffer instance. |
| 64 | * @param wantUnsignedPortionOnly If true, prepend only Name, MetaInfo, Content, and |
| 65 | * SignatureInfo to @p encoder, but omit SignatureValue and the outermost TLV |
| 66 | * Type and Length of the Data element. This is intended to be used with |
| 67 | * wireEncode(EncodingBuffer&, const Block&) const. |
| 68 | * @throw Error %Signature is not present and @p wantUnsignedPortionOnly is false. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 69 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 70 | template<encoding::Tag TAG> |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 71 | size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 72 | wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly = false) const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 73 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 74 | /** @brief Finalize Data packet encoding with the specified SignatureValue |
| 75 | * @param encoder EncodingBuffer containing Name, MetaInfo, Content, and SignatureInfo, but |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 76 | * without SignatureValue and the outermost Type-Length of the Data element. |
| 77 | * @param signatureValue SignatureValue element. |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 78 | * |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 79 | * This method is intended to be used in concert with `wireEncode(encoder, true)`, e.g.: |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 80 | * @code |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 81 | * Data data; |
| 82 | * ... |
| 83 | * EncodingBuffer encoder; |
| 84 | * data.wireEncode(encoder, true); |
| 85 | * ... |
| 86 | * Block signatureValue = <sign_over_unsigned_portion>(encoder.buf(), encoder.size()); |
| 87 | * data.wireEncode(encoder, signatureValue) |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 88 | * @endcode |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 89 | */ |
| 90 | const Block& |
| 91 | wireEncode(EncodingBuffer& encoder, const Block& signatureValue) const; |
| 92 | |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 93 | /** @brief Encode into a Block. |
| 94 | * @pre Data must be signed. |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 95 | */ |
| 96 | const Block& |
| 97 | wireEncode() const; |
| 98 | |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 99 | /** @brief Decode from @p wire. |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 100 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 101 | void |
| 102 | wireDecode(const Block& wire); |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 103 | |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 104 | /** @brief Check if this instance has cached wire encoding. |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 105 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 106 | bool |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 107 | hasWire() const noexcept |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 108 | { |
| 109 | return m_wire.hasWire(); |
| 110 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 111 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 112 | /** @brief Get full name including implicit digest |
| 113 | * @pre hasWire() == true; i.e. wireEncode() must have been called |
| 114 | * @throw Error Data has no wire encoding |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 115 | */ |
| 116 | const Name& |
| 117 | getFullName() const; |
| 118 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 119 | public: // Data fields |
| 120 | /** @brief Get name |
| 121 | */ |
| 122 | const Name& |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 123 | getName() const noexcept |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 124 | { |
| 125 | return m_name; |
| 126 | } |
| 127 | |
| 128 | /** @brief Set name |
| 129 | * @return a reference to this Data, to allow chaining |
| 130 | */ |
| 131 | Data& |
| 132 | setName(const Name& name); |
| 133 | |
| 134 | /** @brief Get MetaInfo |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 135 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 136 | const MetaInfo& |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 137 | getMetaInfo() const noexcept |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 138 | { |
| 139 | return m_metaInfo; |
| 140 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 141 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 142 | /** @brief Set MetaInfo |
| 143 | * @return a reference to this Data, to allow chaining |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 144 | */ |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 145 | Data& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 146 | setMetaInfo(const MetaInfo& metaInfo); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 147 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 148 | /** @brief Get Content |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 149 | * |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 150 | * The Content value is accessible through value()/value_size() or value_begin()/value_end() |
| 151 | * methods of the Block class. |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 152 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 153 | const Block& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 154 | getContent() const; |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 155 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 156 | /** @brief Set Content from a Block |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 157 | * |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 158 | * If the block's TLV-TYPE is Content, it will be used directly as this Data's Content element. |
| 159 | * Otherwise, the block will be nested into a Content element. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 160 | * |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 161 | * @return a reference to this Data, to allow chaining |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 162 | */ |
| 163 | Data& |
| 164 | setContent(const Block& block); |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 165 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 166 | /** @brief Set Content by copying from a raw buffer |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 167 | * @param value pointer to the first octet of the value |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 168 | * @param valueSize size of the buffer |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 169 | * @return a reference to this Data, to allow chaining |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 170 | */ |
| 171 | Data& |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 172 | setContent(const uint8_t* value, size_t valueSize); |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 173 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 174 | /** @brief Set Content from a shared buffer |
| 175 | * @param value buffer containing the TLV-VALUE of the content; must not be nullptr |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 176 | * @return a reference to this Data, to allow chaining |
| 177 | */ |
| 178 | Data& |
Davide Pesavento | 3b101d0 | 2018-07-21 22:44:09 -0400 | [diff] [blame] | 179 | setContent(ConstBufferPtr value); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 180 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 181 | /** @brief Get Signature |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 182 | * @deprecated Use getSignatureInfo and getSignatureValue |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 183 | */ |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 184 | [[deprecated("use getSignatureInfo and getSignatureValue")]] |
| 185 | Signature |
| 186 | getSignature() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 187 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 188 | /** @brief Set Signature |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 189 | * @deprecated Use setSignatureInfo and setSignatureValue |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 190 | * @return a reference to this Data, to allow chaining |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 191 | */ |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 192 | [[deprecated("use setSignatureInfo and setSignatureValue")]] |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 193 | Data& |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 194 | setSignature(const Signature& signature); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 195 | |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 196 | /** @brief Get SignatureInfo |
| 197 | */ |
| 198 | const SignatureInfo& |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 199 | getSignatureInfo() const noexcept |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 200 | { |
| 201 | return m_signatureInfo; |
| 202 | } |
| 203 | |
| 204 | /** @brief Set SignatureInfo |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 205 | * |
| 206 | * This is a low-level function that should not normally be called directly by applications. |
| 207 | * Instead, provide a SignatureInfo to the SigningInfo object passed to KeyChain::sign(). |
| 208 | * |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 209 | * @return a reference to this Data, to allow chaining |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 210 | * @warning SignatureInfo is overwritten when the packet is signed via KeyChain::sign(). |
| 211 | * @sa SigningInfo |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 212 | */ |
| 213 | Data& |
| 214 | setSignatureInfo(const SignatureInfo& info); |
| 215 | |
| 216 | /** @brief Get SignatureValue |
| 217 | */ |
| 218 | const Block& |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 219 | getSignatureValue() const noexcept |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 220 | { |
| 221 | return m_signatureValue; |
| 222 | } |
| 223 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 224 | /** @brief Set SignatureValue |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 225 | * @param value buffer containing the TLV-VALUE of the SignatureValue; must not be nullptr |
| 226 | * |
| 227 | * This is a low-level function that should not normally be called directly by applications. |
| 228 | * Instead, use KeyChain::sign() to sign the packet. |
| 229 | * |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 230 | * @return a reference to this Data, to allow chaining |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 231 | * @warning SignatureValue is overwritten when the packet is signed via KeyChain::sign(). |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 232 | */ |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 233 | Data& |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 234 | setSignatureValue(ConstBufferPtr value); |
Yingdi Yu | a4e5767 | 2014-02-06 11:16:17 -0800 | [diff] [blame] | 235 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 236 | public: // MetaInfo fields |
| 237 | uint32_t |
| 238 | getContentType() const |
| 239 | { |
| 240 | return m_metaInfo.getType(); |
| 241 | } |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 242 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 243 | Data& |
| 244 | setContentType(uint32_t type); |
| 245 | |
Junxiao Shi | ebfe4a2 | 2018-04-01 23:53:40 +0000 | [diff] [blame] | 246 | time::milliseconds |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 247 | getFreshnessPeriod() const |
| 248 | { |
| 249 | return m_metaInfo.getFreshnessPeriod(); |
| 250 | } |
| 251 | |
| 252 | Data& |
Junxiao Shi | ebfe4a2 | 2018-04-01 23:53:40 +0000 | [diff] [blame] | 253 | setFreshnessPeriod(time::milliseconds freshnessPeriod); |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 254 | |
Junxiao Shi | ebfe4a2 | 2018-04-01 23:53:40 +0000 | [diff] [blame] | 255 | const optional<name::Component>& |
| 256 | getFinalBlock() const |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 257 | { |
Junxiao Shi | ebfe4a2 | 2018-04-01 23:53:40 +0000 | [diff] [blame] | 258 | return m_metaInfo.getFinalBlock(); |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | Data& |
Junxiao Shi | ebfe4a2 | 2018-04-01 23:53:40 +0000 | [diff] [blame] | 262 | setFinalBlock(optional<name::Component> finalBlockId); |
| 263 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame] | 264 | public: // SignatureInfo fields |
| 265 | /** @brief Get SignatureType |
| 266 | * @return tlv::SignatureTypeValue, or -1 to indicate the signature is invalid |
| 267 | */ |
| 268 | int32_t |
| 269 | getSignatureType() const noexcept |
| 270 | { |
| 271 | return m_signatureInfo.getSignatureType(); |
| 272 | } |
| 273 | |
| 274 | /** @brief Get KeyLocator |
| 275 | */ |
| 276 | optional<KeyLocator> |
| 277 | getKeyLocator() const noexcept |
| 278 | { |
| 279 | return m_signatureInfo.hasKeyLocator() ? make_optional(m_signatureInfo.getKeyLocator()) : nullopt; |
| 280 | } |
| 281 | |
Spyridon Mastorakis | 3b54e85 | 2015-04-07 08:03:25 -0700 | [diff] [blame] | 282 | protected: |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 283 | /** @brief Clear wire encoding and cached FullName |
| 284 | * @note This does not clear the SignatureValue. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 285 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 286 | void |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 287 | resetWire(); |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 288 | |
| 289 | private: |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 290 | Name m_name; |
| 291 | MetaInfo m_metaInfo; |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 292 | Block m_content; |
Eric Newberry | a3c8bd1 | 2020-05-15 17:27:07 -0700 | [diff] [blame] | 293 | SignatureInfo m_signatureInfo; |
| 294 | Block m_signatureValue; |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 295 | |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 296 | mutable Block m_wire; |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 297 | mutable Name m_fullName; ///< cached FullName computed from m_wire |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 298 | }; |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 299 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 300 | #ifndef DOXYGEN |
| 301 | extern template size_t |
| 302 | Data::wireEncode<encoding::EncoderTag>(EncodingBuffer&, bool) const; |
| 303 | |
| 304 | extern template size_t |
| 305 | Data::wireEncode<encoding::EstimatorTag>(EncodingEstimator&, bool) const; |
| 306 | #endif |
| 307 | |
Alexander Afanasyev | a0c5f83 | 2014-06-19 13:27:56 -0700 | [diff] [blame] | 308 | std::ostream& |
| 309 | operator<<(std::ostream& os, const Data& data); |
Alexander Afanasyev | 809805d | 2014-02-17 17:20:33 -0800 | [diff] [blame] | 310 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 311 | bool |
| 312 | operator==(const Data& lhs, const Data& rhs); |
| 313 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 314 | inline bool |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 315 | operator!=(const Data& lhs, const Data& rhs) |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 316 | { |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 317 | return !(lhs == rhs); |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 318 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 319 | |
Alexander Afanasyev | fadc97d | 2014-01-03 13:22:10 -0800 | [diff] [blame] | 320 | } // namespace ndn |
| 321 | |
Davide Pesavento | 905d40f | 2020-06-09 21:33:25 -0400 | [diff] [blame] | 322 | #endif // NDN_CXX_DATA_HPP |