23 #include "../encoding/block-helpers.hpp" 24 #include "../util/concepts.hpp" 29 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ValidityPeriod>));
33 static_assert(std::is_base_of<tlv::Error, ValidityPeriod::Error>::value,
34 "ValidityPeriod::Error must inherit from tlv::Error");
40 using boost::chrono::time_point_cast;
44 : m_notBefore(time_point_cast<TimePoint::duration>(notBefore + TimePoint::duration(1) -
45 time::system_clock::TimePoint::duration(1)))
46 , m_notAfter(time_point_cast<TimePoint::duration>(notAfter))
55 template<encoding::Tag TAG>
59 size_t totalLength = 0;
64 totalLength += encoder.prependVarNumber(totalLength);
87 m_wire = buffer.block();
97 BOOST_THROW_EXCEPTION(
Error(
"The supplied block does not contain wire format"));
104 BOOST_THROW_EXCEPTION(
Error(
"Unexpected TLV type when decoding ValidityPeriod"));
107 BOOST_THROW_EXCEPTION(
Error(
"Does not have two sub-TLVs"));
113 BOOST_THROW_EXCEPTION(
Error(
"Invalid NotBefore or NotAfter field"));
117 m_notBefore = time_point_cast<TimePoint::duration>(
119 m_notAfter = time_point_cast<TimePoint::duration>(
122 catch (
const std::bad_cast&) {
123 BOOST_THROW_EXCEPTION(
Error(
"Invalid date format in NOT-BEFORE or NOT-AFTER field"));
132 m_notBefore = time_point_cast<TimePoint::duration>(notBefore + TimePoint::duration(1) -
133 time::system_clock::TimePoint::duration(1));
134 m_notAfter = time_point_cast<TimePoint::duration>(notAfter);
138 std::pair<time::system_clock::TimePoint, time::system_clock::TimePoint>
141 return std::make_pair(m_notBefore, m_notAfter);
147 return m_notBefore < now && now < m_notAfter;
153 return (this->m_notBefore == other.m_notBefore &&
154 this->m_notAfter == other.m_notAfter);
160 return !(*
this == other);
bool hasWire() const
Check if the Block has fully encoded wire.
Copyright (c) 2011-2015 Regents of the University of California.
bool operator!=(const ValidityPeriod &other) const
system_clock::TimePoint fromIsoString(const std::string &isoString)
Convert from the ISO string (YYYYMMDDTHHMMSS,fffffffff) representation to the internal time format...
const Block & wireEncode() const
Encode ValidityPeriod into TLV block.
bool operator==(const ValidityPeriod &other) const
EncodingImpl< EstimatorTag > EncodingEstimator
ValidityPeriod()=default
Set validity period (UNIX epoch, UNIX epoch) that is always invalid.
void parse() const
Parse wire buffer into subblocks.
Class representing a wire element of NDN-TLV packet format.
bool isValid(const time::system_clock::TimePoint &now=time::system_clock::now()) const
Check if now falls within the validity period.
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Helper to prepend TLV block type type with value from a string value.
static const size_t NOT_BEFORE_OFFSET
std::string readString(const Block &block)
Helper to read a string value from a block.
ValidityPeriod & setPeriod(const time::system_clock::TimePoint ¬Before, const time::system_clock::TimePoint ¬After)
Set validity period (notBefore, notAfter)
std::ostream & operator<<(std::ostream &os, const AdditionalDescription &other)
a concept check for TLV abstraction with .wireEncode method
Abstraction of validity period.
EncodingImpl< EncoderTag > EncodingBuffer
static const size_t ISO_DATETIME_SIZE
std::pair< time::system_clock::TimePoint, time::system_clock::TimePoint > getPeriod() const
Get the stored validity period.
void reset()
Reset wire buffer of the element.
size_t elements_size() const
static const size_t NOT_AFTER_OFFSET
std::string toIsoString(const system_clock::TimePoint &timePoint)
Convert to the ISO string representation of the time (YYYYMMDDTHHMMSS,fffffffff)
const element_container & elements() const
Get all subelements.
void wireDecode(const Block &wire)
Decode ValidityPeriod from TLV block.
a concept check for TLV abstraction with .wireEncode method
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...