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