23 #include "../encoding/block-helpers.hpp" 24 #include "../util/concepts.hpp" 29 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ValidityPeriod>));
34 "ValidityPeriod::Error must inherit from tlv::Error");
40 using boost::chrono::time_point_cast;
44 time::system_clock::TimePoint())
50 : m_notBefore(time_point_cast<TimePoint::duration>(notBefore + TimePoint::duration(1) -
51 time::system_clock::TimePoint::duration(1)))
52 , m_notAfter(time_point_cast<TimePoint::duration>(notAfter))
61 template<encoding::Tag TAG>
65 size_t totalLength = 0;
70 totalLength += encoder.prependVarNumber(totalLength);
89 m_wire = buffer.block();
99 BOOST_THROW_EXCEPTION(
Error(
"The supplied block does not contain wire format"));
106 BOOST_THROW_EXCEPTION(
Error(
"Unexpected TLV type when decoding ValidityPeriod"));
109 BOOST_THROW_EXCEPTION(
Error(
"Does not have two sub-TLVs"));
115 BOOST_THROW_EXCEPTION(
Error(
"Invalid NotBefore or NotAfter field"));
119 m_notBefore = time_point_cast<TimePoint::duration>(
121 m_notAfter = time_point_cast<TimePoint::duration>(
124 catch (
const std::bad_cast&) {
125 BOOST_THROW_EXCEPTION(
Error(
"Invalid date format in NOT-BEFORE or NOT-AFTER field"));
134 m_notBefore = time_point_cast<TimePoint::duration>(notBefore + TimePoint::duration(1) -
135 time::system_clock::TimePoint::duration(1));
136 m_notAfter = time_point_cast<TimePoint::duration>(notAfter);
140 std::pair<time::system_clock::TimePoint, time::system_clock::TimePoint>
143 return std::make_pair(m_notBefore, m_notAfter);
149 return m_notBefore <= now && now <= m_notAfter;
155 return (this->m_notBefore == other.m_notBefore &&
156 this->m_notAfter == other.m_notAfter);
162 return !(*
this == other);
Copyright (c) 2011-2015 Regents of the University of California.
const element_container & elements() const
Get container of sub elements.
system_clock::TimePoint fromIsoString(const std::string &isoString)
Convert from the ISO string (YYYYMMDDTHHMMSS,fffffffff) representation to the internal time format...
Represents a TLV element of NDN packet format.
bool operator==(const ValidityPeriod &other) const
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
static const size_t NOT_BEFORE_OFFSET
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
ValidityPeriod & setPeriod(const time::system_clock::TimePoint ¬Before, const time::system_clock::TimePoint ¬After)
Set validity period [notBefore, notAfter].
Catch-all error for security policy errors that don't fit in other categories.
a concept check for TLV abstraction with .wireEncode method
Abstraction of validity period.
std::pair< time::system_clock::TimePoint, time::system_clock::TimePoint > getPeriod() const
Get the stored validity period.
static const size_t ISO_DATETIME_SIZE
bool operator!=(const ValidityPeriod &other) const
const Block & wireEncode() const
Encode ValidityPeriod into TLV block.
size_t elements_size() const
Equivalent to elements().size()
void reset()
Reset wire buffer of the element.
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)
void parse() const
Parse TLV-VALUE into sub elements.
uint32_t type() const
Get TLV-TYPE.
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(SafeBag)
bool hasWire() const
Check if the Block has fully encoded wire.
bool isValid(const time::system_clock::TimePoint &now=time::system_clock::now()) const
Check if now falls within the validity period.
ValidityPeriod()
Set validity period [UNIX epoch + 1 nanosecond, UNIX epoch] that is always invalid.
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 ...
std::ostream & operator<<(std::ostream &os, const SigningInfo &si)
EncodingImpl< EncoderTag > EncodingBuffer
EncodingImpl< EstimatorTag > EncodingEstimator