37 template<encoding::Tag TAG>
49 size_t totalLength = 0;
52 if (!wantUnsignedPortionOnly) {
53 if (!m_signatureInfo) {
54 NDN_THROW(
Error(
"Requested wire format, but Data has not been signed"));
73 if (!wantUnsignedPortionOnly) {
74 totalLength += encoder.prependVarNumber(totalLength);
75 totalLength += encoder.prependVarNumber(
tlv::Data);
81 Data::wireEncode<encoding::EncoderTag>(
EncodingBuffer&,
bool)
const;
89 size_t totalLength = encoder.
size();
91 totalLength += encoder.appendVarNumber(signature.size());
92 totalLength += encoder.appendBytes(signature);
94 encoder.prependVarNumber(totalLength);
141 m_signatureInfo = {};
142 m_signatureValue = {};
146 for (++element; element != m_wire.
elements_end(); ++element) {
147 switch (element->type()) {
149 if (lastElement >= 2) {
157 if (lastElement >= 3) {
160 m_content = *element;
165 if (lastElement >= 4) {
173 if (lastElement >= 5) {
176 m_signatureValue = *element;
191 if (!m_signatureInfo) {
194 if (!m_signatureValue.
isValid()) {
202 if (m_fullName.
empty()) {
204 NDN_THROW(
Error(
"Cannot compute full name because Data has no wire encoding (not signed)"));
223 if (name != m_name) {
233 m_metaInfo = metaInfo;
242 NDN_THROW(std::invalid_argument(
"Content block must be valid"));
276 NDN_THROW(std::invalid_argument(
"Content buffer cannot be null"));
297 m_signatureInfo =
info;
314 NDN_THROW(std::invalid_argument(
"SignatureValue buffer cannot be null"));
339 if (type != m_metaInfo.
getType()) {
379 os <<
"Name: " << data.
getName() <<
"\n"
Represents a TLV element of the NDN packet format.
element_const_iterator elements_begin() const noexcept
Equivalent to elements().begin().
element_const_iterator find(uint32_t type) const
Find the first sub-element of the specified TLV-TYPE.
size_t size() const
Returns the size of the encoded wire, i.e., of the whole TLV.
element_const_iterator elements_end() const noexcept
Equivalent to elements().end().
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
bool isValid() const noexcept
Check if the Block is valid.
void encode()
Encode sub-elements into TLV-VALUE.
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
void reset() noexcept
Reset the Block to a default-constructed state.
void parse() const
Parse TLV-VALUE into sub-elements.
const_iterator value_begin() const noexcept
Get begin iterator of TLV-VALUE.
size_t value_size() const noexcept
Return the size of TLV-VALUE, i.e., the TLV-LENGTH.
Represents a Data packet.
int32_t getSignatureType() const noexcept
Get the SignatureType.
void wireDecode(const Block &wire)
Decode from wire.
InputBuffers extractSignedRanges() const
Extract ranges of Data covered by the signature.
Data & setContent(const Block &block)
Set Content from a Block.
Data(const Name &name=Name())
Construct an unsigned Data packet with given name and empty Content.
const MetaInfo & getMetaInfo() const noexcept
Get the MetaInfo element.
void resetWire()
Clear wire encoding and cached FullName.
Data & setFreshnessPeriod(time::milliseconds freshnessPeriod)
Set the FreshnessPeriod.
const Block & wireEncode() const
Encode into a Block.
const Name & getFullName() const
Get the full name (including implicit digest).
bool hasContent() const noexcept
Return whether this Data has a Content element.
Data & setFinalBlock(std::optional< name::Component > finalBlockId)
Set the FinalBlockId.
Data & setSignatureValue(span< const uint8_t > value)
Set SignatureValue by copying from a contiguous sequence of bytes.
const SignatureInfo & getSignatureInfo() const noexcept
Get the SignatureInfo element.
const Name & getName() const noexcept
Get the Data name.
const Block & getSignatureValue() const noexcept
Get the SignatureValue element.
Data & setSignatureInfo(const SignatureInfo &info)
Set the SignatureInfo element.
Data & setName(const Name &name)
Set the Data name.
const Block & getContent() const noexcept
Get the Content element.
Data & setContentType(uint32_t type)
Set the ContentType.
Data & setMetaInfo(const MetaInfo &metaInfo)
Set the MetaInfo element.
Data & unsetContent()
Remove the Content element.
Represents an absolute name.
Name & appendImplicitSha256Digest(ConstBufferPtr digest)
Append an ImplicitSha256Digest component.
bool empty() const noexcept
Checks if the name is empty, i.e., has no components.
void clear()
Remove all components.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend wire encoding to encoder.
void wireDecode(const Block &wire)
Decode name from wire encoding.
Represents a SignatureInfo or InterestSignatureInfo TLV element.
size_t wireEncode(EncodingImpl< TAG > &encoder, Type type=Type::Data) const
Fast encoding or block size estimation.
void wireDecode(const Block &wire, Type type=Type::Data)
Decode from wire format.
ConstBufferPtr computeDigest()
Finalize and return the digest based on all previously supplied inputs.
EncodingImpl< EstimatorTag > EncodingEstimator
Block makeStringBlock(uint32_t type, std::string_view value)
Create a TLV block containing a string.
Block makeBinaryBlock(uint32_t type, span< const uint8_t > value)
Create a TLV block copying the TLV-VALUE from a byte range.
EncodingImpl< EncoderTag > EncodingBuffer
size_t prependBlock(EncodingImpl< TAG > &encoder, const Block &block)
Prepend a TLV element.
std::string to_string(const errinfo_stacktrace &x)
::boost::chrono::milliseconds milliseconds
constexpr bool isCriticalType(uint32_t type) noexcept
Determine whether a TLV-TYPE is "critical" for evolvability purpose.
SignatureTypeValue
SignatureType values.
bool operator==(const Data &lhs, const Data &rhs)
std::ostream & operator<<(std::ostream &os, const Data &data)
std::shared_ptr< const Buffer > ConstBufferPtr