NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
validity-period.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2022 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_SECURITY_VALIDITY_PERIOD_HPP
23 #define NDN_CXX_SECURITY_VALIDITY_PERIOD_HPP
24 
26 #include "ndn-cxx/encoding/tlv.hpp"
28 #include "ndn-cxx/util/time.hpp"
29 
30 namespace ndn {
31 namespace security {
32 
38 {
39 public:
40  class Error : public tlv::Error
41  {
42  public:
43  using tlv::Error::Error;
44  };
45 
54  static ValidityPeriod
55  makeRelative(time::seconds validFrom, time::seconds validUntil,
57 
61 
64  explicit
65  ValidityPeriod(const Block& block);
66 
76  const time::system_clock::TimePoint& notAfter);
77 
82  bool
84 
95  const time::system_clock::TimePoint& notAfter);
96 
99  std::pair<time::system_clock::TimePoint, time::system_clock::TimePoint>
100  getPeriod() const;
101 
104  template<encoding::Tag TAG>
105  size_t
106  wireEncode(EncodingImpl<TAG>& encoder) const;
107 
110  const Block&
111  wireEncode() const;
112 
116  void
117  wireDecode(const Block& wire);
118 
119 private: // EqualityComparable concept
120  // NOTE: the following "hidden friend" operators are available via
121  // argument-dependent lookup only and must be defined inline.
122 
123  friend bool
124  operator==(const ValidityPeriod& lhs, const ValidityPeriod& rhs)
125  {
126  return !(lhs != rhs);
127  }
128 
129  friend bool
130  operator!=(const ValidityPeriod& lhs, const ValidityPeriod& rhs)
131  {
132  return lhs.m_notBefore != rhs.m_notBefore ||
133  lhs.m_notAfter != rhs.m_notAfter;
134  }
135 
136 private:
137  typedef boost::chrono::time_point<time::system_clock, time::seconds> TimePoint;
138 
139  TimePoint m_notBefore;
140  TimePoint m_notAfter;
141 
142  mutable Block m_wire;
143 };
144 
146 
147 std::ostream&
148 operator<<(std::ostream& os, const ValidityPeriod& period);
149 
150 } // namespace security
151 } // namespace ndn
152 
153 #endif // NDN_CXX_SECURITY_VALIDITY_PERIOD_HPP
boost::chrono::seconds seconds
Definition: time.hpp:47
Copyright (c) 2011-2015 Regents of the University of California.
const Block & wireEncode() const
Encode ValidityPeriod into TLV block.
static ValidityPeriod makeRelative(time::seconds validFrom, time::seconds validUntil, const time::system_clock::TimePoint &now=time::system_clock::now())
Construct ValidityPeriod relative to a timepoint.
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(SafeBag)
Represents a TLV element of the NDN packet format.
Definition: block.hpp:44
bool isValid(const time::system_clock::TimePoint &now=time::system_clock::now()) const
Check if now falls within the validity period.
ValidityPeriod & setPeriod(const time::system_clock::TimePoint &notBefore, const time::system_clock::TimePoint &notAfter)
Set validity period [notBefore, notAfter].
static time_point now() noexcept
Definition: time.cpp:46
Common includes and macros used throughout the library.
Represents a ValidityPeriod TLV element.
std::pair< time::system_clock::TimePoint, time::system_clock::TimePoint > getPeriod() const
Get the stored validity period.
friend bool operator!=(const ValidityPeriod &lhs, const ValidityPeriod &rhs)
friend bool operator==(const ValidityPeriod &lhs, const ValidityPeriod &rhs)
ValidityPeriod()
Set validity period [UNIX epoch + 1 nanosecond, UNIX epoch] that is always invalid.
void wireDecode(const Block &wire)
Decode ValidityPeriod from TLV block.
std::ostream & operator<<(std::ostream &os, const SigningInfo &si)
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
represents an error in TLV encoding or decoding
Definition: tlv.hpp:52
time_point TimePoint
Definition: time.hpp:203