Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 10b24be | 2017-07-12 23:23:46 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2019 Regents of the University of California. |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -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 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/data.hpp" |
| 23 | #include "ndn-cxx/encoding/block-helpers.hpp" |
| 24 | #include "ndn-cxx/util/sha256.hpp" |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 28 | BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Data>)); |
| 29 | BOOST_CONCEPT_ASSERT((WireEncodable<Data>)); |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 30 | BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Data>)); |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 31 | BOOST_CONCEPT_ASSERT((WireDecodable<Data>)); |
| 32 | static_assert(std::is_base_of<tlv::Error, Data::Error>::value, |
| 33 | "Data::Error must inherit from tlv::Error"); |
| 34 | |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 35 | Data::Data(const Name& name) |
| 36 | : m_name(name) |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 37 | , m_content(tlv::Content) |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
| 41 | Data::Data(const Block& wire) |
| 42 | { |
| 43 | wireDecode(wire); |
| 44 | } |
| 45 | |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 46 | template<encoding::Tag TAG> |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 47 | size_t |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 48 | Data::wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly) const |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 49 | { |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 50 | // Data ::= DATA-TLV TLV-LENGTH |
| 51 | // Name |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 52 | // MetaInfo? |
| 53 | // Content? |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 54 | // SignatureInfo |
| 55 | // SignatureValue |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 56 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 57 | size_t totalLength = 0; |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 59 | // SignatureValue |
| 60 | if (!wantUnsignedPortionOnly) { |
| 61 | if (!m_signature) { |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 62 | NDN_THROW(Error("Requested wire format, but Data has not been signed")); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 63 | } |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 64 | totalLength += encoder.prependBlock(m_signature.getValue()); |
| 65 | } |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 66 | |
| 67 | // SignatureInfo |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 68 | totalLength += encoder.prependBlock(m_signature.getInfo()); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 69 | |
| 70 | // Content |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 71 | totalLength += encoder.prependBlock(getContent()); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 72 | |
| 73 | // MetaInfo |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 74 | totalLength += getMetaInfo().wireEncode(encoder); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 75 | |
| 76 | // Name |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 77 | totalLength += getName().wireEncode(encoder); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 78 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 79 | if (!wantUnsignedPortionOnly) { |
| 80 | totalLength += encoder.prependVarNumber(totalLength); |
| 81 | totalLength += encoder.prependVarNumber(tlv::Data); |
| 82 | } |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 83 | return totalLength; |
| 84 | } |
| 85 | |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 86 | template size_t |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 87 | Data::wireEncode<encoding::EncoderTag>(EncodingBuffer&, bool) const; |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 88 | |
| 89 | template size_t |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 90 | Data::wireEncode<encoding::EstimatorTag>(EncodingEstimator&, bool) const; |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 92 | const Block& |
| 93 | Data::wireEncode(EncodingBuffer& encoder, const Block& signatureValue) const |
| 94 | { |
| 95 | size_t totalLength = encoder.size(); |
| 96 | totalLength += encoder.appendBlock(signatureValue); |
| 97 | |
Davide Pesavento | 9bd4d98 | 2015-05-13 14:31:19 +0200 | [diff] [blame] | 98 | encoder.prependVarNumber(totalLength); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 99 | encoder.prependVarNumber(tlv::Data); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 100 | |
| 101 | const_cast<Data*>(this)->wireDecode(encoder.block()); |
| 102 | return m_wire; |
| 103 | } |
| 104 | |
| 105 | const Block& |
| 106 | Data::wireEncode() const |
| 107 | { |
| 108 | if (m_wire.hasWire()) |
| 109 | return m_wire; |
| 110 | |
| 111 | EncodingEstimator estimator; |
| 112 | size_t estimatedSize = wireEncode(estimator); |
| 113 | |
| 114 | EncodingBuffer buffer(estimatedSize, 0); |
| 115 | wireEncode(buffer); |
| 116 | |
| 117 | const_cast<Data*>(this)->wireDecode(buffer.block()); |
| 118 | return m_wire; |
| 119 | } |
| 120 | |
| 121 | void |
| 122 | Data::wireDecode(const Block& wire) |
| 123 | { |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 124 | // Data ::= DATA-TLV TLV-LENGTH |
| 125 | // Name |
| 126 | // MetaInfo? |
| 127 | // Content? |
| 128 | // SignatureInfo |
| 129 | // SignatureValue |
| 130 | |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 131 | m_wire = wire; |
| 132 | m_wire.parse(); |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 133 | |
| 134 | auto element = m_wire.elements_begin(); |
| 135 | if (element == m_wire.elements_end() || element->type() != tlv::Name) { |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 136 | NDN_THROW(Error("Name element is missing or out of order")); |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 137 | } |
| 138 | m_name.wireDecode(*element); |
| 139 | int lastElement = 1; // last recognized element index, in spec order |
| 140 | |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 141 | m_metaInfo = MetaInfo(); |
| 142 | m_content = Block(tlv::Content); |
| 143 | m_signature = Signature(); |
| 144 | m_fullName.clear(); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 145 | |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 146 | for (++element; element != m_wire.elements_end(); ++element) { |
| 147 | switch (element->type()) { |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 148 | case tlv::MetaInfo: { |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 149 | if (lastElement >= 2) { |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 150 | NDN_THROW(Error("MetaInfo element is out of order")); |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 151 | } |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 152 | m_metaInfo.wireDecode(*element); |
| 153 | lastElement = 2; |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 154 | break; |
| 155 | } |
| 156 | case tlv::Content: { |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 157 | if (lastElement >= 3) { |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 158 | NDN_THROW(Error("Content element is out of order")); |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 159 | } |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 160 | m_content = *element; |
| 161 | lastElement = 3; |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 162 | break; |
| 163 | } |
| 164 | case tlv::SignatureInfo: { |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 165 | if (lastElement >= 4) { |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 166 | NDN_THROW(Error("SignatureInfo element is out of order")); |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 167 | } |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 168 | m_signature.setInfo(*element); |
| 169 | lastElement = 4; |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 170 | break; |
| 171 | } |
| 172 | case tlv::SignatureValue: { |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 173 | if (lastElement >= 5) { |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 174 | NDN_THROW(Error("SignatureValue element is out of order")); |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 175 | } |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 176 | m_signature.setValue(*element); |
| 177 | lastElement = 5; |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 178 | break; |
| 179 | } |
| 180 | default: { |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 181 | if (tlv::isCriticalType(element->type())) { |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 182 | NDN_THROW(Error("unrecognized element of critical type " + to_string(element->type()))); |
Junxiao Shi | 7d9039b | 2018-04-14 15:56:28 +0000 | [diff] [blame] | 183 | } |
| 184 | break; |
| 185 | } |
| 186 | } |
| 187 | } |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 188 | |
Junxiao Shi | 8b753a2 | 2018-10-24 01:51:40 +0000 | [diff] [blame] | 189 | if (!m_signature) { |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 190 | NDN_THROW(Error("SignatureInfo element is missing")); |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 191 | } |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 194 | const Name& |
| 195 | Data::getFullName() const |
| 196 | { |
| 197 | if (m_fullName.empty()) { |
| 198 | if (!m_wire.hasWire()) { |
Davide Pesavento | 923ba44 | 2019-02-12 22:00:38 -0500 | [diff] [blame] | 199 | NDN_THROW(Error("Cannot compute full name because Data has no wire encoding (not signed)")); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 200 | } |
| 201 | m_fullName = m_name; |
Davide Pesavento | 10b24be | 2017-07-12 23:23:46 -0400 | [diff] [blame] | 202 | m_fullName.appendImplicitSha256Digest(util::Sha256::computeDigest(m_wire.wire(), m_wire.size())); |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | return m_fullName; |
| 206 | } |
| 207 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 208 | void |
| 209 | Data::resetWire() |
| 210 | { |
| 211 | m_wire.reset(); |
| 212 | m_fullName.clear(); |
| 213 | } |
| 214 | |
| 215 | Data& |
| 216 | Data::setName(const Name& name) |
| 217 | { |
| 218 | resetWire(); |
| 219 | m_name = name; |
| 220 | return *this; |
| 221 | } |
| 222 | |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 223 | Data& |
| 224 | Data::setMetaInfo(const MetaInfo& metaInfo) |
| 225 | { |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 226 | resetWire(); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 227 | m_metaInfo = metaInfo; |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 228 | return *this; |
| 229 | } |
| 230 | |
| 231 | const Block& |
| 232 | Data::getContent() const |
| 233 | { |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 234 | if (!m_content.hasWire()) { |
| 235 | const_cast<Block&>(m_content).encode(); |
| 236 | } |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 237 | return m_content; |
| 238 | } |
| 239 | |
| 240 | Data& |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 241 | Data::setContent(const Block& block) |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 242 | { |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 243 | resetWire(); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 244 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 245 | if (block.type() == tlv::Content) { |
| 246 | m_content = block; |
| 247 | } |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 248 | else { |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 249 | m_content = Block(tlv::Content, block); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | return *this; |
| 253 | } |
| 254 | |
| 255 | Data& |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 256 | Data::setContent(const uint8_t* value, size_t valueSize) |
| 257 | { |
| 258 | resetWire(); |
| 259 | m_content = makeBinaryBlock(tlv::Content, value, valueSize); |
| 260 | return *this; |
| 261 | } |
| 262 | |
| 263 | Data& |
Davide Pesavento | 3b101d0 | 2018-07-21 22:44:09 -0400 | [diff] [blame] | 264 | Data::setContent(ConstBufferPtr value) |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 265 | { |
| 266 | resetWire(); |
Davide Pesavento | 3b101d0 | 2018-07-21 22:44:09 -0400 | [diff] [blame] | 267 | m_content = Block(tlv::Content, std::move(value)); |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 268 | return *this; |
| 269 | } |
| 270 | |
| 271 | Data& |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 272 | Data::setSignature(const Signature& signature) |
| 273 | { |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 274 | resetWire(); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 275 | m_signature = signature; |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 276 | return *this; |
| 277 | } |
| 278 | |
| 279 | Data& |
| 280 | Data::setSignatureValue(const Block& value) |
| 281 | { |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 282 | resetWire(); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 283 | m_signature.setValue(value); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 284 | return *this; |
| 285 | } |
| 286 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 287 | Data& |
| 288 | Data::setContentType(uint32_t type) |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 289 | { |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 290 | resetWire(); |
| 291 | m_metaInfo.setType(type); |
| 292 | return *this; |
| 293 | } |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 294 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 295 | Data& |
Junxiao Shi | ebfe4a2 | 2018-04-01 23:53:40 +0000 | [diff] [blame] | 296 | Data::setFreshnessPeriod(time::milliseconds freshnessPeriod) |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 297 | { |
| 298 | resetWire(); |
| 299 | m_metaInfo.setFreshnessPeriod(freshnessPeriod); |
| 300 | return *this; |
| 301 | } |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 302 | |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 303 | Data& |
Junxiao Shi | ebfe4a2 | 2018-04-01 23:53:40 +0000 | [diff] [blame] | 304 | Data::setFinalBlock(optional<name::Component> finalBlockId) |
| 305 | { |
| 306 | resetWire(); |
| 307 | m_metaInfo.setFinalBlock(std::move(finalBlockId)); |
| 308 | return *this; |
| 309 | } |
| 310 | |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 311 | bool |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 312 | operator==(const Data& lhs, const Data& rhs) |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 313 | { |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 314 | return lhs.getName() == rhs.getName() && |
Davide Pesavento | ef654dd | 2019-07-18 20:02:44 -0400 | [diff] [blame^] | 315 | lhs.getMetaInfo().wireEncode() == rhs.getMetaInfo().wireEncode() && |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 316 | lhs.getContent() == rhs.getContent() && |
Davide Pesavento | ef654dd | 2019-07-18 20:02:44 -0400 | [diff] [blame^] | 317 | lhs.getSignature().getSignatureInfo() == rhs.getSignature().getSignatureInfo() && |
| 318 | lhs.getSignature().getValue() == rhs.getSignature().getValue(); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | std::ostream& |
| 322 | operator<<(std::ostream& os, const Data& data) |
| 323 | { |
| 324 | os << "Name: " << data.getName() << "\n"; |
| 325 | os << "MetaInfo: " << data.getMetaInfo() << "\n"; |
| 326 | os << "Content: (size: " << data.getContent().value_size() << ")\n"; |
Junxiao Shi | 81206d5 | 2017-07-23 12:43:22 +0000 | [diff] [blame] | 327 | os << "Signature: (type: " << data.getSignature().getType() |
| 328 | << ", value_length: "<< data.getSignature().getValue().value_size() << ")"; |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 329 | os << std::endl; |
| 330 | |
| 331 | return os; |
| 332 | } |
| 333 | |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 334 | } // namespace ndn |