27 #include <boost/range/adaptor/reversed.hpp> 31 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<SignatureInfo>));
36 "SignatureInfo::Error must inherit from tlv::Error");
42 , m_keyLocator(
std::
move(keyLocator))
51 template<encoding::Tag TAG>
73 size_t totalLength = 0;
77 for (
const auto& block : m_otherTlvs | boost::adaptors::reversed) {
82 totalLength += m_keyLocator->wireEncode(encoder);
86 static_cast<uint64_t>(m_type));
88 totalLength += encoder.prependVarNumber(totalLength);
106 EncodingEstimator estimator;
107 size_t estimatedSize =
wireEncode(estimator, type);
109 EncodingBuffer buffer(estimatedSize, 0);
112 m_wire = buffer.block();
130 size_t lastCriticalElement = 0;
131 for (
const auto& element : m_wire.
elements()) {
132 switch (element.type()) {
134 if (lastCriticalElement > 0) {
135 NDN_THROW(
Error(
"SignatureType element is repeated or out-of-order"));
137 m_type = readNonNegativeIntegerAs<tlv::SignatureTypeValue>(element);
138 lastCriticalElement = 1;
142 if (lastCriticalElement > 1) {
143 NDN_THROW(
Error(
"KeyLocator element is repeated or out-of-order"));
145 m_keyLocator.emplace(element);
146 lastCriticalElement = 2;
151 if (element.value_size() < 1) {
154 m_otherTlvs.push_back(element);
161 m_otherTlvs.push_back(element);
169 m_otherTlvs.push_back(element);
182 if (type != m_type) {
195 return *m_keyLocator;
201 if (keyLocator != m_keyLocator) {
212 if (it == m_otherTlvs.end()) {
213 NDN_THROW(
Error(
"ValidityPeriod does not exist in SignatureInfo"));
221 if (!validityPeriod) {
230 optional<std::vector<uint8_t>>
234 if (it == m_otherTlvs.end()) {
237 return std::vector<uint8_t>(it->value_begin(), it->value_end());
252 optional<time::system_clock::time_point>
256 if (it == m_otherTlvs.end()) {
279 if (it == m_otherTlvs.end()) {
300 auto it = findOtherTlv(type);
301 if (it == m_otherTlvs.end()) {
310 auto existingIt = std::find_if(m_otherTlvs.begin(), m_otherTlvs.end(), [&block] (
const Block& b) {
311 return b.type() == block.
type();
313 if (existingIt == m_otherTlvs.end()) {
317 else if (*existingIt != block) {
326 auto it = std::remove_if(m_otherTlvs.begin(), m_otherTlvs.end(), [type] (
const Block& block) {
327 return block.type() == type;
330 if (it != m_otherTlvs.end()) {
331 m_otherTlvs.erase(it, m_otherTlvs.end());
336 std::vector<Block>::const_iterator
337 SignatureInfo::findOtherTlv(uint32_t type)
const 339 return std::find_if(m_otherTlvs.begin(), m_otherTlvs.end(), [type] (
const Block& block) {
340 return block.type() == type;
347 return lhs.m_type == rhs.m_type &&
348 lhs.m_keyLocator == rhs.m_keyLocator &&
349 lhs.m_otherTlvs == rhs.m_otherTlvs;
356 return os <<
"Invalid SignatureInfo";
363 if (!info.m_otherTlvs.empty()) {
365 for (
const auto& block : info.m_otherTlvs) {
366 switch (block.type()) {
378 os <<
"SeqNum=" << *info.
getSeqNum() <<
" ";
384 os << block.type() <<
" ";
SignatureInfo & setSeqNum(optional< uint64_t > seqNum)
Append or replace SignatureSeqNum.
friend std::ostream & operator<<(std::ostream &os, const SignatureInfo &info)
Copyright (c) 2011-2015 Regents of the University of California.
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Represents a SignatureInfo or InterestSignatureInfo TLV element.
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
std::string to_string(const T &val)
constexpr bool isCriticalType(uint32_t type)
Determine whether a TLV-TYPE is "critical" for evolvability purpose.
optional< uint64_t > getSeqNum() const
Get SignatureSeqNum.
SignatureInfo & setValidityPeriod(optional< security::ValidityPeriod > validityPeriod)
Append or replace ValidityPeriod.
int32_t getSignatureType() const noexcept
Get SignatureType.
void parse() const
Parse TLV-VALUE into sub-elements.
Represents a TLV element of the NDN packet format.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block containing a non-negative integer.
milliseconds toUnixTimestamp(const system_clock::time_point &point)
Convert system_clock::time_point to UNIX timestamp.
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
optional< Block > getCustomTlv(uint32_t type) const
Get first custom TLV element with the specified TLV-TYPE.
optional< time::system_clock::time_point > getTime() const
Get SignatureTime.
const element_container & elements() const
Get container of sub-elements.
a concept check for TLV abstraction with .wireEncode method
friend bool operator==(const SignatureInfo &lhs, const SignatureInfo &rhs)
Represents a ValidityPeriod TLV element.
NDN_CXX_NODISCARD constexpr std::underlying_type_t< T > to_underlying(T val) noexcept
system_clock::time_point fromUnixTimestamp(milliseconds duration)
Convert UNIX timestamp to system_clock::time_point.
bool hasKeyLocator() const noexcept
Check if KeyLocator is present.
optional< std::vector< uint8_t > > getNonce() const
Get SignatureNonce.
void reset() noexcept
Reset the Block to a default-constructed state.
SignatureInfo & setTime(optional< time::system_clock::time_point > time=time::system_clock::now())
Append or replace SignatureTime.
SignatureTypeValue
SignatureType values.
Block makeBinaryBlock(uint32_t type, span< const uint8_t > value)
Create a TLV block copying the TLV-VALUE from a byte range.
SignatureInfo & setSignatureType(tlv::SignatureTypeValue type)
Set SignatureType.
SignatureInfo & setNonce(optional< span< const uint8_t >> nonce)
Append or replace SignatureNonce.
size_t wireEncode(EncodingImpl< TAG > &encoder, Type type=Type::Data) const
Fast encoding or block size estimation.
void removeCustomTlv(uint32_t type)
Remove all arbitrary TLV elements with the specified TLV-TYPE from this SignatureInfo.
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
SignatureInfo & setKeyLocator(optional< KeyLocator > keyLocator)
Set KeyLocator.
size_t prependBlock(EncodingImpl< TAG > &encoder, const Block &block)
Prepend a TLV element.
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
void addCustomTlv(Block block)
Append an arbitrary TLV element to this SignatureInfo.
a concept check for TLV abstraction with .wireEncode method
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
void wireDecode(const Block &wire, Type type=Type::Data)
Decode from wire format.
EncodingImpl< EncoderTag > EncodingBuffer
const nullopt_t nullopt((nullopt_t::init()))
EncodingImpl< EstimatorTag > EncodingEstimator
security::ValidityPeriod getValidityPeriod() const
Get ValidityPeriod.
boost::chrono::milliseconds milliseconds