28 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Data>));
29 BOOST_CONCEPT_ASSERT((WireEncodable<Data>));
30 BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Data>));
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");
46 template<encoding::Tag TAG>
57 size_t totalLength = 0;
60 if (!wantUnsignedPortionOnly) {
62 BOOST_THROW_EXCEPTION(
Error(
"Requested wire format, but Data has not been signed"));
64 totalLength += encoder.prependBlock(m_signature.
getValue());
68 totalLength += encoder.prependBlock(m_signature.
getInfo());
71 totalLength += encoder.prependBlock(
getContent());
79 if (!wantUnsignedPortionOnly) {
80 totalLength += encoder.prependVarNumber(totalLength);
81 totalLength += encoder.prependVarNumber(
tlv::Data);
87 Data::wireEncode<encoding::EncoderTag>(
EncodingBuffer&, bool)
const;
95 size_t totalLength = encoder.
size();
96 totalLength += encoder.appendBlock(signatureValue);
98 encoder.prependVarNumber(totalLength);
111 EncodingEstimator estimator;
114 EncodingBuffer buffer(estimatedSize, 0);
126 bool hasName =
false, hasSigInfo =
false;
135 switch (ele.type()) {
138 BOOST_THROW_EXCEPTION(
Error(
"Name element is out of order"));
147 BOOST_THROW_EXCEPTION(
Error(
"MetaInfo element is out of order"));
155 BOOST_THROW_EXCEPTION(
Error(
"Content element is out of order"));
163 BOOST_THROW_EXCEPTION(
Error(
"SignatureInfo element is out of order"));
172 BOOST_THROW_EXCEPTION(
Error(
"SignatureValue element is out of order"));
180 BOOST_THROW_EXCEPTION(
Error(
"unrecognized element of critical type " +
189 BOOST_THROW_EXCEPTION(
Error(
"Name element is missing"));
192 BOOST_THROW_EXCEPTION(
Error(
"SignatureInfo element is missing"));
199 if (m_fullName.
empty()) {
201 BOOST_THROW_EXCEPTION(
Error(
"Cannot compute full name because Data has no wire encoding (not signed)"));
229 m_metaInfo = metaInfo;
237 const_cast<Block&
>(m_content).encode();
277 m_signature = signature;
339 os <<
"Name: " << data.
getName() <<
"\n";
Data & setContentType(uint32_t type)
Copyright (c) 2013-2017 Regents of the University of California.
const element_container & elements() const
Get container of sub elements.
void wireDecode(const Block &wire)
Decode from wire in NDN Packet Format v0.2 or v0.3.
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.
std::ostream & operator<<(std::ostream &os, const Data &data)
void setInfo(const Block &info)
Decode SignatureInfo from wire format.
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 Signature & getSignature() const
Get Signature.
void resetWire()
Clear wire encoding and cached FullName.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Represents a TLV element of NDN packet format.
const Block & getValue() const
Get SignatureValue.
const MetaInfo & getMetaInfo() const
Get MetaInfo.
size_t size() const
Get size of encoded wire, including Type-Length-Value.
Data & setSignatureValue(const Block &value)
Set SignatureValue.
void setValue(const Block &value)
Set SignatureValue.
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block copying TLV-VALUE from raw buffer.
name::Component getFinalBlockId() const
void reset()
Reset wire buffer of the element.
Represents an absolute name.
size_t value_size() const
Get size of TLV-VALUE aka TLV-LENGTH.
const Block & wireEncode() const
Encode to a Block.
tlv::SignatureTypeValue getType() const
Get SignatureType.
void parse() const
Parse TLV-VALUE into sub elements.
uint32_t type() const
Get TLV-TYPE.
const Name & getName() const
Get name.
Represents a name component.
const Block & getInfo() const
Get SignatureInfo as wire format.
Data & setFreshnessPeriod(time::milliseconds freshnessPeriod)
Data & setFinalBlock(optional< name::Component > finalBlockId)
const Block & getContent() const
Get Content.
const uint8_t * wire() const
Get pointer to encoded wire.
bool empty() const
Check if name is empty.
bool hasWire() const
Check if the Block has fully encoded wire.
ConstBufferPtr computeDigest()
Finalize and return the digest based on all previously supplied inputs.
bool operator==(const Data &lhs, const Data &rhs)
std::string to_string(const V &v)
Data & setMetaInfo(const MetaInfo &metaInfo)
Set MetaInfo.
const Name & getFullName() const
Get full name including implicit digest.
Data & setFinalBlockId(const name::Component &finalBlockId)
void wireDecode(const Block &wire)
Decode name from wire encoding.
Represents a Data packet.
void clear()
Remove all components.
EncodingImpl< EncoderTag > EncodingBuffer
Name & appendImplicitSha256Digest(const ConstBufferPtr &digest)
Append an ImplicitSha256Digest component.
EncodingImpl< EstimatorTag > EncodingEstimator
Holds SignatureInfo and SignatureValue in a Data packet.
shared_ptr< const Buffer > ConstBufferPtr