all: Refactoring work with time using boost::chrono
Now the library has two clocks: time::steady_clock and
time::system_clock, following (boost|std)::chrono. In addition to
standard now() method, the library contains several helpers to convert
to/from UnixTimestamp (microsecond resolution) and IsoString (optional
microsecond resolution). The IsoString conversions use
boost::posix_time routines, since boost::chrono supports extended IO
support only starting boost version 1.52 (Boost Chrono V2).
This commit breaks compatibility with previous API. All time-related
Data/Interest calls must explicitly use time units to specify
FreshnessPeriod/InterestLifetime.
Brief usage/conversion guide:
- creation of time units does not support double/float types. If
necessary to create time unit from double, ``ndn::duration<double>`` (for
seconds) needs to be used instead. In some cases, this would also
require ``ndn::duration_cast``, if the target is not ``ndn::nanoseconds``.
- ndn::getNow, ndn::ndn_getNowMilliseconds, ndn::time::now are all
removed in favor of the now() method in a specific clock:
* time::system_clock::now();
* time::steady_clock::now();
- When necessary to convert system_clock::TimePoint to unix timestamp,
``time::toUnixTimestamp`` can be used. This method return number of
milliseconds since UNIX epoch as ``ndn::time::milliseconds`` type.
Use count() method to obtain number as an integral value.
Change-Id: Icd688bc6766e008d60c3d2888173627874526e47
Refs: #1152
diff --git a/tests/security/test-keychain.cpp b/tests/security/test-keychain.cpp
index 3e9b4fc..8a76b79 100644
--- a/tests/security/test-keychain.cpp
+++ b/tests/security/test-keychain.cpp
@@ -7,7 +7,6 @@
#include <boost/test/unit_test.hpp>
#include "security/key-chain.hpp"
-#include "util/time.hpp"
using namespace std;
@@ -19,7 +18,8 @@
{
KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
- Name identity(string("/TestKeyChain/ExportIdentity/") + boost::lexical_cast<std::string>(time::now()));
+ Name identity("/TestKeyChain/ExportIdentity/");
+ identity.appendVersion();
keyChain.createIdentity(identity);
shared_ptr<SecuredBag> exported = keyChain.exportIdentity(identity, "1234");
@@ -60,28 +60,30 @@
{
KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
- Name identity(string("/TestKeyChain/PrepareIdentityCertificate/") + boost::lexical_cast<std::string>(time::now()));
+ Name identity("/TestKeyChain/PrepareIdentityCertificate/");
+ identity.appendVersion();
keyChain.createIdentity(identity);
vector<CertificateSubjectDescription> subjectDescription;
Name lowerIdentity = identity;
- lowerIdentity.append("Lower").append(boost::lexical_cast<std::string>(time::now()));
+ lowerIdentity.append("Lower").appendVersion();
Name lowerKeyName = keyChain.generateRSAKeyPair(lowerIdentity, true);
shared_ptr<IdentityCertificate> idCert
= keyChain.prepareUnsignedIdentityCertificate(lowerKeyName, identity,
- time::now() / 1000000,
- time::now() / 1000000 + 630720000,
+ time::system_clock::now(),
+ time::system_clock::now() + time::days(365),
subjectDescription);
BOOST_CHECK(static_cast<bool>(idCert));
BOOST_CHECK(idCert->getName().getPrefix(5) == Name().append(identity).append("KEY").append("Lower"));
- Name anotherIdentity(string("/TestKeyChain/PrepareIdentityCertificate/Another/") + boost::lexical_cast<std::string>(time::now()));
+ Name anotherIdentity("/TestKeyChain/PrepareIdentityCertificate/Another/");
+ anotherIdentity.appendVersion();
Name anotherKeyName = keyChain.generateRSAKeyPair(anotherIdentity, true);
shared_ptr<IdentityCertificate> idCert2
= keyChain.prepareUnsignedIdentityCertificate(anotherKeyName, identity,
- time::now() / 1000000,
- time::now() / 1000000 + 630720000,
+ time::system_clock::now(),
+ time::system_clock::now() + time::days(365),
subjectDescription);
BOOST_CHECK(static_cast<bool>(idCert2));
BOOST_CHECK(idCert2->getName().getPrefix(5) == Name().append(anotherIdentity).append("KEY"));
@@ -90,8 +92,8 @@
Name wrongKeyName1;
shared_ptr<IdentityCertificate> idCert3
= keyChain.prepareUnsignedIdentityCertificate(wrongKeyName1, identity,
- time::now() / 1000000,
- time::now() / 1000000 + 630720000,
+ time::system_clock::now(),
+ time::system_clock::now() + time::days(365),
subjectDescription);
BOOST_CHECK(!static_cast<bool>(idCert3));
@@ -99,8 +101,8 @@
Name wrongKeyName2("/TestKeyChain/PrepareIdentityCertificate");
shared_ptr<IdentityCertificate> idCert4
= keyChain.prepareUnsignedIdentityCertificate(wrongKeyName2, identity,
- time::now() / 1000000,
- time::now() / 1000000 + 630720000,
+ time::system_clock::now(),
+ time::system_clock::now() + time::days(365),
subjectDescription);
BOOST_CHECK(!static_cast<bool>(idCert4));
@@ -108,8 +110,8 @@
Name wrongKeyName3("/TestKeyChain/PrepareIdentityCertificate/ksk-1234");
shared_ptr<IdentityCertificate> idCert5
= keyChain.prepareUnsignedIdentityCertificate(wrongKeyName3, identity,
- time::now() / 1000000,
- time::now() / 1000000 + 630720000,
+ time::system_clock::now(),
+ time::system_clock::now() + time::days(365),
subjectDescription);
BOOST_CHECK(!static_cast<bool>(idCert5));