Represents a Data packet. More...
#include <data.hpp>
Classes | |
class | Error |
Public Member Functions | |
Data (const Name &name=Name()) | |
Construct an unsigned Data packet with given name and empty Content. More... | |
Data (const Block &wire) | |
Construct a Data packet by decoding from wire . More... | |
template<encoding::Tag TAG> | |
size_t | wireEncode (EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const |
Prepend wire encoding to encoder . More... | |
const Block & | wireEncode (EncodingBuffer &encoder, span< const uint8_t > signature) const |
Finalize Data packet encoding with the specified signature. More... | |
const Block & | wireEncode () const |
Encode into a Block. More... | |
void | wireDecode (const Block &wire) |
Decode from wire . More... | |
bool | hasWire () const noexcept |
Check if this instance has cached wire encoding. More... | |
const Name & | getFullName () const |
Get full name including implicit digest. More... | |
const Name & | getName () const noexcept |
Get name. More... | |
Data & | setName (const Name &name) |
Set name. More... | |
const MetaInfo & | getMetaInfo () const noexcept |
Get MetaInfo. More... | |
Data & | setMetaInfo (const MetaInfo &metaInfo) |
Set MetaInfo. More... | |
bool | hasContent () const noexcept |
Return whether this Data has a Content element. More... | |
const Block & | getContent () const noexcept |
Get the Content element. More... | |
Data & | setContent (const Block &block) |
Set Content from a Block. More... | |
Data & | setContent (span< const uint8_t > value) |
Set Content by copying from a contiguous sequence of bytes. More... | |
Data & | setContent (const uint8_t *value, size_t length) |
Set Content by copying from a raw buffer. More... | |
Data & | setContent (ConstBufferPtr value) |
Set Content from a shared buffer. More... | |
Data & | unsetContent () |
Remove the Content element. More... | |
const SignatureInfo & | getSignatureInfo () const noexcept |
Get SignatureInfo. More... | |
Data & | setSignatureInfo (const SignatureInfo &info) |
Set SignatureInfo. More... | |
const Block & | getSignatureValue () const noexcept |
Get SignatureValue. More... | |
Data & | setSignatureValue (ConstBufferPtr value) |
Set SignatureValue. More... | |
InputBuffers | extractSignedRanges () const |
Extract ranges of Data covered by the signature. More... | |
uint32_t | getContentType () const |
Data & | setContentType (uint32_t type) |
time::milliseconds | getFreshnessPeriod () const |
Data & | setFreshnessPeriod (time::milliseconds freshnessPeriod) |
const optional< name::Component > & | getFinalBlock () const |
Data & | setFinalBlock (optional< name::Component > finalBlockId) |
int32_t | getSignatureType () const noexcept |
Get SignatureType. More... | |
optional< KeyLocator > | getKeyLocator () const noexcept |
Get KeyLocator. More... | |
Public Member Functions inherited from ndn::PacketBase | |
uint64_t | getCongestionMark () const |
get the value of the CongestionMark tag More... | |
void | setCongestionMark (uint64_t mark) |
set the CongestionMark tag to the specified value More... | |
Public Member Functions inherited from ndn::TagHost | |
template<typename T > | |
shared_ptr< T > | getTag () const |
get a tag item More... | |
template<typename T > | |
void | setTag (shared_ptr< T > tag) const |
set a tag item More... | |
template<typename T > | |
void | removeTag () const |
remove tag item More... | |
Protected Member Functions | |
void | resetWire () |
Clear wire encoding and cached FullName. More... | |
Represents a Data packet.
Construct an unsigned Data packet with given name
and empty Content.
Data::shared_from_this()
, Data must be created using std::make_shared
. Otherwise, shared_from_this()
may trigger undefined behavior. One example where this is necessary is storing Data into a subclass of InMemoryStorage.
|
explicit |
Construct a Data packet by decoding from wire
.
wire | TLV block of type tlv::Data; may be signed or unsigned. |
Data::shared_from_this()
, Data must be created using std::make_shared
. Otherwise, shared_from_this()
may trigger undefined behavior. One example where this is necessary is storing Data into a subclass of InMemoryStorage. Definition at line 39 of file data.cpp.
References wireDecode().
size_t ndn::Data::wireEncode | ( | EncodingImpl< TAG > & | encoder, |
bool | wantUnsignedPortionOnly = false |
||
) | const |
Prepend wire encoding to encoder
.
encoder | EncodingEstimator or EncodingBuffer instance. |
wantUnsignedPortionOnly | If true, prepend only Name, MetaInfo, Content, and SignatureInfo to encoder , but omit SignatureValue and the outermost TLV Type and Length of the Data element. This is intended to be used with wireEncode(EncodingBuffer&, span<const uint8_t>) const. |
Error | Signature is not present and wantUnsignedPortionOnly is false. |
Definition at line 46 of file data.cpp.
References ndn::SignatureInfo::Data, ndn::tlv::Data, hasContent(), NDN_THROW, ndn::encoding::prependBlock(), ndn::MetaInfo::wireEncode(), ndn::SignatureInfo::wireEncode(), and ndn::Name::wireEncode().
Referenced by ndn::Face::Impl::putData(), ndn::util::DummyClientFace::receive(), ndn::security::v2::KeyChain::sign(), and ndn::security::SafeBag::wireEncode().
const Block & ndn::Data::wireEncode | ( | EncodingBuffer & | encoder, |
span< const uint8_t > | signature | ||
) | const |
Finalize Data packet encoding with the specified signature.
encoder | EncodingBuffer containing Name, MetaInfo, Content, and SignatureInfo, but without SignatureValue and the outermost Type-Length of the Data element. |
signature | Raw signature bytes, without TLV Type and Length; this will become the TLV-VALUE of the SignatureValue element added to the packet. |
This method is intended to be used in concert with wireEncode(encoder, true)
, e.g.:
Definition at line 94 of file data.cpp.
References ndn::tlv::Data, ndn::tlv::SignatureValue, ndn::Block::size(), and wireDecode().
const Block & ndn::Data::wireEncode | ( | ) | const |
Encode into a Block.
Definition at line 109 of file data.cpp.
References ndn::Block::hasWire(), and wireDecode().
Referenced by extractSignedRanges().
void ndn::Data::wireDecode | ( | const Block & | wire | ) |
Decode from wire
.
Definition at line 125 of file data.cpp.
References ndn::Name::clear(), ndn::tlv::Content, ndn::tlv::Data, ndn::Block::elements_begin(), ndn::Block::elements_end(), ndn::tlv::isCriticalType(), ndn::Block::isValid(), ndn::tlv::MetaInfo, ndn::tlv::Name, NDN_THROW, ndn::Block::parse(), ndn::tlv::SignatureInfo, ndn::tlv::SignatureValue, ndn::to_string(), ndn::Block::type(), ndn::MetaInfo::wireDecode(), ndn::SignatureInfo::wireDecode(), and ndn::Name::wireDecode().
Referenced by Data(), ndn::Link::wireDecode(), ndn::security::SafeBag::wireDecode(), and wireEncode().
|
inlinenoexcept |
Check if this instance has cached wire encoding.
Definition at line 111 of file data.hpp.
References getFullName().
const Name & ndn::Data::getFullName | ( | ) | const |
Get full name including implicit digest.
Definition at line 207 of file data.cpp.
References ndn::Name::appendImplicitSha256Digest(), ndn::util::Sha256::computeDigest(), ndn::Name::empty(), ndn::Block::hasWire(), and NDN_THROW.
Referenced by nfd::cs::compareDataWithData(), nfd::cs::compareQueryWithData(), hasWire(), ndn::InMemoryStorage::insert(), and ndn::Interest::matchesData().
|
inlinenoexcept |
Get name.
Definition at line 127 of file data.hpp.
References setName().
Referenced by ndn::security::v2::KeyChain::addCertificate(), nfd::fw::Strategy::afterContentStoreHit(), nfd::fw::SelfLearningStrategy::afterReceiveData(), nfd::fw::Strategy::afterReceiveData(), nfd::fw::SelfLearningStrategy::afterReceiveNack(), nfd::fw::asf::AsfStrategy::beforeSatisfyInterest(), nfd::fw::AccessStrategy::beforeSatisfyInterest(), nfd::fw::Strategy::beforeSatisfyInterest(), ndn::security::v2::Certificate::Certificate(), ndn::security::v2::ValidationPolicySimpleHierarchy::checkPolicy(), ndn::security::v2::validator_config::ValidationPolicyConfig::checkPolicy(), nfd::cs::compareDataWithData(), nfd::cs::compareQueryWithData(), ndn::security::v2::CertificateFetcherFromNetwork::dataCallback(), ndn::security::v2::CertificateBundleFetcher::doFetch(), nfd::pit::Pit::findAllDataMatches(), ndn::security::v2::Certificate::getIdentity(), ndn::security::v2::Certificate::getIssuerId(), ndn::security::v2::Certificate::getKeyId(), ndn::security::v2::Certificate::getKeyName(), ndn::security::v2::KeyChain::importSafeBag(), nfd::cs::Cs::insert(), ndn::security::v2::CertificateCache::insert(), ndn::security::v2::KeyChain::makeCertificate(), ndn::Interest::matchesData(), ndn::MetadataObject::MetadataObject(), nfd::Forwarder::onDataUnsolicited(), nfd::Forwarder::onIncomingData(), nfd::Forwarder::onOutgoingData(), ndn::security::v2::operator<<(), ndn::operator<<(), ndn::operator==(), ndn::Face::Impl::putData(), ndn::mgmt::Dispatcher::removeTopPrefix(), nfd::fw::Strategy::satisfyInterest(), ndn::security::v2::KeyChain::setDefaultCertificate(), ndn::util::NotificationSubscriberBase::stop(), ndn::util::SegmentFetcher::stop(), ndn::security::v2::Validator::validate(), and ndn::security::v2::DataValidationState::~DataValidationState().
Set name.
Definition at line 228 of file data.cpp.
References resetWire().
Referenced by getName(), and ndn::security::v2::parseLocatorUri().
|
inlinenoexcept |
Get MetaInfo.
Definition at line 141 of file data.hpp.
References setMetaInfo().
Referenced by ndn::operator<<(), and ndn::operator==().
Set MetaInfo.
Definition at line 238 of file data.cpp.
References resetWire().
Referenced by getMetaInfo().
|
inlinenoexcept |
Return whether this Data has a Content element.
Definition at line 156 of file data.hpp.
Referenced by ndn::operator<<(), and wireEncode().
|
inlinenoexcept |
Get the Content element.
If the element is not present (hasContent() == false), an invalid Block will be returned.
The value of the returned Content Block (if valid) can be accessed through
Definition at line 175 of file data.hpp.
References setContent(), and unsetContent().
Referenced by ndn::security::v2::KeyChain::addCertificate(), ndn::security::v2::Certificate::Certificate(), ndn::security::v2::CertificateBundleFetcher::doFetch(), ndn::security::v2::Certificate::getPublicKey(), ndn::security::v2::KeyChain::makeCertificate(), ndn::MetadataObject::MetadataObject(), ndn::security::v2::operator<<(), ndn::operator<<(), ndn::operator==(), ndn::util::SegmentFetcher::stop(), ndn::Link::wireDecode(), and ndn::nfd::Controller::~Controller().
Set Content from a Block.
block | TLV block to be used as Content; must be valid |
If the block's TLV-TYPE is tlv::Content, it will be used directly as this Data's Content element. Otherwise, the block will be nested into a Content element.
Definition at line 246 of file data.cpp.
References ndn::tlv::Content, ndn::Block::encode(), ndn::Block::isValid(), NDN_THROW, resetWire(), and ndn::Block::type().
Referenced by getContent(), ndn::Link::Link(), ndn::MetadataObject::makeData(), ndn::security::v2::parseLocatorUri(), and setContent().
Data & ndn::Data::setContent | ( | span< const uint8_t > | value | ) |
Set Content by copying from a contiguous sequence of bytes.
value | buffer with the TLV-VALUE of the content |
Definition at line 264 of file data.cpp.
References ndn::tlv::Content, ndn::encoding::makeBinaryBlock(), and resetWire().
Data & ndn::Data::setContent | ( | const uint8_t * | value, |
size_t | length | ||
) |
Set Content by copying from a raw buffer.
value | buffer with the TLV-VALUE of the content; may be nullptr if length is zero |
length | size of the buffer |
Definition at line 272 of file data.cpp.
References NDN_THROW, and setContent().
Data & ndn::Data::setContent | ( | ConstBufferPtr | value | ) |
Set Content from a shared buffer.
value | buffer with the TLV-VALUE of the content; must not be nullptr |
Definition at line 282 of file data.cpp.
References ndn::tlv::Content, nonstd::optional_lite::std11::move(), NDN_THROW, and resetWire().
Data & ndn::Data::unsetContent | ( | ) |
Remove the Content element.
Definition at line 294 of file data.cpp.
References resetWire().
Referenced by getContent().
|
inlinenoexcept |
Get SignatureInfo.
Definition at line 229 of file data.hpp.
References info, and setSignatureInfo().
Referenced by ndn::security::v2::Certificate::getExtension(), ndn::security::v2::getKeyLocatorName(), ndn::security::v2::Certificate::getValidityPeriod(), ndn::security::v2::Certificate::isValid(), ndn::security::v2::operator<<(), ndn::operator==(), and ndn::security::parse().
Data & ndn::Data::setSignatureInfo | ( | const SignatureInfo & | info | ) |
Set SignatureInfo.
This is a low-level function that should not normally be called directly by applications. Instead, provide a SignatureInfo to the SigningInfo object passed to KeyChain::sign().
Definition at line 302 of file data.cpp.
References info, and resetWire().
Referenced by getSignatureInfo(), and ndn::security::v2::KeyChain::sign().
|
inlinenoexcept |
Get SignatureValue.
Definition at line 249 of file data.hpp.
References extractSignedRanges(), and setSignatureValue().
Referenced by ndn::operator<<(), ndn::operator==(), and ndn::security::parse().
Data & ndn::Data::setSignatureValue | ( | ConstBufferPtr | value | ) |
Set SignatureValue.
value | buffer containing the TLV-VALUE of the SignatureValue; must not be nullptr |
This is a low-level function that should not normally be called directly by applications. Instead, use KeyChain::sign() to sign the packet.
Definition at line 310 of file data.cpp.
References nonstd::optional_lite::std11::move(), NDN_THROW, resetWire(), and ndn::tlv::SignatureValue.
Referenced by getSignatureValue().
InputBuffers ndn::Data::extractSignedRanges | ( | ) | const |
Extract ranges of Data covered by the signature.
Definition at line 322 of file data.cpp.
References bufs, ndn::Block::find(), ndn::tlv::SignatureValue, ndn::Block::value_begin(), and wireEncode().
Referenced by getSignatureValue(), and ndn::security::parse().
|
inline |
Definition at line 275 of file data.hpp.
References setContentType().
Referenced by ndn::security::v2::Certificate::Certificate(), ndn::MetadataObject::MetadataObject(), and ndn::Link::wireDecode().
Data & ndn::Data::setContentType | ( | uint32_t | type | ) |
Definition at line 336 of file data.cpp.
References ndn::MetaInfo::getType(), resetWire(), and ndn::MetaInfo::setType().
Referenced by ndn::security::v2::Certificate::Certificate(), getContentType(), ndn::Link::Link(), and ndn::security::v2::parseLocatorUri().
|
inline |
Definition at line 284 of file data.hpp.
References setFreshnessPeriod().
Referenced by ndn::security::v2::Certificate::Certificate(), ndn::Interest::matchesData(), nfd::Forwarder::onContentStoreHit(), and nfd::Forwarder::onIncomingData().
Data & ndn::Data::setFreshnessPeriod | ( | time::milliseconds | freshnessPeriod | ) |
Definition at line 346 of file data.cpp.
References ndn::MetaInfo::getFreshnessPeriod(), resetWire(), and ndn::MetaInfo::setFreshnessPeriod().
Referenced by getFreshnessPeriod(), ndn::MetadataObject::makeData(), and ndn::security::v2::parseLocatorUri().
|
inline |
Definition at line 293 of file data.hpp.
References setFinalBlock().
Referenced by ndn::security::v2::CertificateBundleFetcher::doFetch(), and ndn::util::SegmentFetcher::stop().
Data & ndn::Data::setFinalBlock | ( | optional< name::Component > | finalBlockId | ) |
Definition at line 356 of file data.cpp.
References ndn::MetaInfo::getFinalBlock(), nonstd::optional_lite::std11::move(), resetWire(), and ndn::MetaInfo::setFinalBlock().
Referenced by getFinalBlock().
|
inlinenoexcept |
Get SignatureType.
Definition at line 306 of file data.hpp.
Referenced by ndn::security::v2::validator_config::ValidationPolicyConfig::checkPolicy(), ndn::security::v2::operator<<(), and ndn::operator<<().
|
inlinenoexcept |
Get KeyLocator.
Definition at line 314 of file data.hpp.
References nonstd::optional_lite::make_optional(), nonstd::optional_lite::nullopt, ndn::operator<<(), ndn::operator==(), and resetWire().
Referenced by ndn::security::v2::operator<<().
|
protected |
Clear wire encoding and cached FullName.
Definition at line 221 of file data.cpp.
References ndn::Name::clear(), and ndn::Block::reset().
Referenced by getKeyLocator(), setContent(), setContentType(), setFinalBlock(), setFreshnessPeriod(), setMetaInfo(), setName(), setSignatureInfo(), setSignatureValue(), and unsetContent().