28 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Data>));
32 static_assert(std::is_base_of<tlv::Error, Data::Error>::value,
33 "Data::Error must inherit from tlv::Error");
45 template<encoding::Tag TAG>
57 size_t totalLength = 0;
60 if (!wantUnsignedPortionOnly) {
61 if (!m_signatureInfo) {
62 NDN_THROW(
Error(
"Requested wire format, but Data has not been signed"));
64 totalLength += encoder.prependBlock(m_signatureValue);
72 totalLength += encoder.prependBlock(m_content);
81 if (!wantUnsignedPortionOnly) {
82 totalLength += encoder.prependVarNumber(totalLength);
83 totalLength += encoder.prependVarNumber(
tlv::Data);
89 Data::wireEncode<encoding::EncoderTag>(
EncodingBuffer&, bool)
const;
97 size_t totalLength = encoder.
size();
98 totalLength += encoder.appendBlock(signatureValue);
100 encoder.prependVarNumber(totalLength);
113 EncodingEstimator estimator;
116 EncodingBuffer buffer(estimatedSize, 0);
147 m_signatureInfo = {};
148 m_signatureValue = {};
152 for (++element; element != m_wire.
elements_end(); ++element) {
153 switch (element->type()) {
155 if (lastElement >= 2) {
163 if (lastElement >= 3) {
166 m_content = *element;
171 if (lastElement >= 4) {
179 if (lastElement >= 5) {
182 m_signatureValue = *element;
197 if (!m_signatureInfo) {
200 if (!m_signatureValue.
isValid()) {
208 if (m_fullName.
empty()) {
210 NDN_THROW(
Error(
"Cannot compute full name because Data has no wire encoding (not signed)"));
229 if (name != m_name) {
239 m_metaInfo = metaInfo;
248 NDN_THROW(std::invalid_argument(
"Content block must be valid"));
265 if (value ==
nullptr && length != 0) {
266 NDN_THROW(std::invalid_argument(
"Content buffer cannot be nullptr"));
277 if (value ==
nullptr) {
278 NDN_THROW(std::invalid_argument(
"Content buffer cannot be nullptr"));
297 return Signature(m_signatureInfo, m_signatureValue);
304 m_signatureValue = signature.
getValue();
312 m_signatureInfo = info;
320 if (value ==
nullptr) {
321 NDN_THROW(std::invalid_argument(
"SignatureValue buffer cannot be nullptr"));
337 bufs.emplace_back(m_wire.
value(),
338 std::distance(m_wire.
value_begin(), lastSignedIt->end()));
345 if (type != m_metaInfo.
getType()) {
385 os <<
"Name: " << data.
getName() <<
"\n" const Block & wireEncode() const
Encode into a Block.
Data & setContentType(uint32_t type)
Represents a SignatureInfo or InterestSignatureInfo TLV element.
void wireDecode(const Block &wire)
Decode from wire.
std::string to_string(const T &val)
Data & setSignatureValue(ConstBufferPtr value)
Set SignatureValue.
Data & setSignature(const Signature &signature)
Set Signature.
constexpr bool isCriticalType(uint32_t type)
Determine whether a TLV-TYPE is "critical" for evolvability purpose.
Data & setName(const Name &name)
Set name.
Name & appendImplicitSha256Digest(ConstBufferPtr digest)
Append an ImplicitSha256Digest component.
std::ostream & operator<<(std::ostream &os, const Data &data)
Data(const Name &name=Name())
Construct an unsigned Data packet with given name and empty Content.
Data & setContent(const Block &block)
Set Content from a Block.
const uint8_t * wire() const
Return a raw pointer to the beginning of the encoded wire.
size_t value_size() const noexcept
Return the size of TLV-VALUE, aka TLV-LENGTH.
void parse() const
Parse TLV-VALUE into sub-elements.
void resetWire()
Clear wire encoding and cached FullName.
Represents a TLV element of the NDN packet format.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
element_const_iterator elements_begin() const
Equivalent to elements().begin()
const Block & getSignatureValue() const noexcept
Get SignatureValue.
Buffer::const_iterator value_begin() const
Get begin iterator of TLV-VALUE.
int32_t getSignatureType() const noexcept
Get SignatureType.
a concept check for TLV abstraction with .wireEncode method
size_t size() const
Return the size of the encoded wire, i.e.
element_const_iterator elements_end() const
Equivalent to elements().end()
Data & setSignatureInfo(const SignatureInfo &info)
Set SignatureInfo.
element_const_iterator find(uint32_t type) const
Find the first sub-element of the specified TLV-TYPE.
void reset() noexcept
Reset the Block to a default-constructed state.
InputBuffers extractSignedRanges() const
Extract ranges of Data covered by the signature.
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block copying TLV-VALUE from raw buffer.
const Block & getValue() const
Get SignatureValue.
const Name & getName() const noexcept
Get name.
Represents an absolute name.
const MetaInfo & getMetaInfo() const noexcept
Get MetaInfo.
SignatureTypeValue
SignatureType values.
const Name & getFullName() const
Get full name including implicit digest.
size_t wireEncode(EncodingImpl< TAG > &encoder, Type type=Type::Data) const
Fast encoding or block size estimation.
bool isValid() const noexcept
Check if the Block is valid.
const uint8_t * value() const noexcept
Return a raw pointer to the beginning of TLV-VALUE.
Data & setFreshnessPeriod(time::milliseconds freshnessPeriod)
void encode()
Encode sub-elements into TLV-VALUE.
Data & setFinalBlock(optional< name::Component > finalBlockId)
const Block & getContent() const noexcept
Get the Content element.
Data & unsetContent()
Remove the Content element.
bool empty() const
Checks if the name is empty, i.e.
ConstBufferPtr computeDigest()
Finalize and return the digest based on all previously supplied inputs.
bool operator==(const Data &lhs, const Data &rhs)
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Data & setMetaInfo(const MetaInfo &metaInfo)
Set MetaInfo.
void wireDecode(const Block &wire)
Decode name from wire encoding.
a concept check for TLV abstraction with .wireEncode method
const SignatureInfo & getSignatureInfo() const
Get SignatureInfo.
Represents a Data packet.
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
bool hasContent() const noexcept
Return whether this Data has a Content element.
void clear()
Remove all components.
Signature getSignature() const
Get Signature.
void wireDecode(const Block &wire, Type type=Type::Data)
Decode from wire format.
EncodingImpl< EncoderTag > EncodingBuffer
uint32_t type() const
Return the TLV-TYPE of the Block.
EncodingImpl< EstimatorTag > EncodingEstimator
const SignatureInfo & getSignatureInfo() const noexcept
Get SignatureInfo.
Holds SignatureInfo and SignatureValue in a Data packet.
shared_ptr< const Buffer > ConstBufferPtr