util: add literal operators for duration types
Change-Id: I007fa61c80e535c6e4b12e85a32eeeee62fecc3c
Refs: #4468
diff --git a/src/security/command-interest-signer.cpp b/src/security/command-interest-signer.cpp
index 3704a7e..70e80a1 100644
--- a/src/security/command-interest-signer.cpp
+++ b/src/security/command-interest-signer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -35,7 +35,7 @@
{
time::milliseconds timestamp = time::toUnixTimestamp(time::system_clock::now());
if (timestamp <= m_lastUsedTimestamp) {
- timestamp = m_lastUsedTimestamp + time::milliseconds(1);
+ timestamp = m_lastUsedTimestamp + 1_ms;
}
m_lastUsedTimestamp = timestamp;
diff --git a/src/security/v2/certificate-cache.cpp b/src/security/v2/certificate-cache.cpp
index be2b084..9726b7e 100644
--- a/src/security/v2/certificate-cache.cpp
+++ b/src/security/v2/certificate-cache.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -28,11 +28,10 @@
NDN_LOG_INIT(ndn.security.v2.CertificateCache);
-const time::nanoseconds&
+time::nanoseconds
CertificateCache::getDefaultLifetime()
{
- static time::nanoseconds lifetime = time::seconds(3600);
- return lifetime;
+ return 1_h;
}
CertificateCache::CertificateCache(const time::nanoseconds& maxLifetime)
diff --git a/src/security/v2/certificate-cache.hpp b/src/security/v2/certificate-cache.hpp
index a5109a8..53157b4 100644
--- a/src/security/v2/certificate-cache.hpp
+++ b/src/security/v2/certificate-cache.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -118,7 +118,7 @@
refresh();
public:
- static const time::nanoseconds&
+ static time::nanoseconds
getDefaultLifetime();
private:
diff --git a/src/security/v2/certificate-storage.cpp b/src/security/v2/certificate-storage.cpp
index d1638d9..a4d482e 100644
--- a/src/security/v2/certificate-storage.cpp
+++ b/src/security/v2/certificate-storage.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -26,8 +26,8 @@
namespace v2 {
CertificateStorage::CertificateStorage()
- : m_verifiedCertCache(time::hours(1))
- , m_unverifiedCertCache(time::minutes(5))
+ : m_verifiedCertCache(1_h)
+ , m_unverifiedCertCache(5_min)
{
}
diff --git a/src/security/v2/key-chain.cpp b/src/security/v2/key-chain.cpp
index 9f496a1..348f214 100644
--- a/src/security/v2/key-chain.cpp
+++ b/src/security/v2/key-chain.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -549,7 +549,7 @@
// set metainfo
certificate.setContentType(tlv::ContentType_Key);
- certificate.setFreshnessPeriod(time::hours(1));
+ certificate.setFreshnessPeriod(1_h);
// set content
certificate.setContent(key.getPublicKey().data(), key.getPublicKey().size());
@@ -559,7 +559,7 @@
// Note time::system_clock::max() or other NotAfter date results in incorrect encoded value
// because of overflow during conversion to boost::posix_time::ptime (bug #3915).
signatureInfo.setValidityPeriod(ValidityPeriod(time::system_clock::TimePoint(),
- time::system_clock::now() + time::days(20 * 365)));
+ time::system_clock::now() + 20 * 365_days));
sign(certificate, SigningInfo(key).setSignatureInfo(signatureInfo));
diff --git a/src/security/v2/validation-policy-command-interest.hpp b/src/security/v2/validation-policy-command-interest.hpp
index 96a9012..84a7be8 100644
--- a/src/security/v2/validation-policy-command-interest.hpp
+++ b/src/security/v2/validation-policy-command-interest.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -62,7 +62,7 @@
* Setting this option to 0 or negative causes the validator to require exactly same
* timestamp as the system clock, which most likely rejects all command Interests.
*/
- time::nanoseconds gracePeriod = time::seconds(120);
+ time::nanoseconds gracePeriod = 2_min;
/** \brief max number of distinct public keys of which to record the last timestamp
*
@@ -88,7 +88,7 @@
* Setting this option to 0 or negative makes last timestamp records expire immediately
* and causes every command Interest to be processed as initial.
*/
- time::nanoseconds recordLifetime = time::hours(1);
+ time::nanoseconds recordLifetime = 1_h;
};
/** \brief constructor
@@ -157,5 +157,4 @@
} // namespace security
} // namespace ndn
-
#endif // NDN_SECURITY_V2_VALIDATION_POLICY_COMMAND_INTEREST_HPP
diff --git a/src/security/v2/validation-policy-config.cpp b/src/security/v2/validation-policy-config.cpp
index c41a47f..0f0bb84 100644
--- a/src/security/v2/validation-policy-config.cpp
+++ b/src/security/v2/validation-policy-config.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -241,11 +241,11 @@
switch (unit) {
case 'h':
- return time::duration_cast<time::nanoseconds>(time::hours(refreshPeriod));
+ return time::hours(refreshPeriod);
case 'm':
- return time::duration_cast<time::nanoseconds>(time::minutes(refreshPeriod));
+ return time::minutes(refreshPeriod);
case 's':
- return time::duration_cast<time::nanoseconds>(time::seconds(refreshPeriod));
+ return time::seconds(refreshPeriod);
default:
BOOST_THROW_EXCEPTION(Error(std::string("Wrong time unit: ") + unit));
}
@@ -254,7 +254,7 @@
time::nanoseconds
ValidationPolicyConfig::getDefaultRefreshPeriod()
{
- return time::duration_cast<time::nanoseconds>(time::seconds(3600));
+ return 1_h;
}
void
diff --git a/src/security/validity-period.cpp b/src/security/validity-period.cpp
index c30497b..0cd4555 100644
--- a/src/security/validity-period.cpp
+++ b/src/security/validity-period.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -40,7 +40,7 @@
using boost::chrono::time_point_cast;
ValidityPeriod::ValidityPeriod()
- : ValidityPeriod(time::system_clock::TimePoint() + time::nanoseconds(1),
+ : ValidityPeriod(time::system_clock::TimePoint() + 1_ns,
time::system_clock::TimePoint())
{
}