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/src/security/certificate.cpp b/src/security/certificate.cpp
index 0312fd5..931a40e 100644
--- a/src/security/certificate.cpp
+++ b/src/security/certificate.cpp
@@ -26,8 +26,8 @@
namespace ndn {
Certificate::Certificate()
- : notBefore_(std::numeric_limits<MillisecondsSince1970>::max())
- , notAfter_(std::numeric_limits<MillisecondsSince1970>::min())
+ : notBefore_(time::system_clock::TimePoint::max())
+ , notAfter_(time::system_clock::TimePoint::min())
{}
Certificate::Certificate(const Data& data)
@@ -47,18 +47,16 @@
bool
Certificate::isTooEarly()
{
- MillisecondsSince1970 now = ndn_getNowMilliseconds();
- if(now < notBefore_)
+ if(time::system_clock::now() < notBefore_)
return true;
else
return false;
}
-bool
+bool
Certificate::isTooLate()
{
- MillisecondsSince1970 now = ndn_getNowMilliseconds();
- if(now > notAfter_)
+ if(time::system_clock::now() > notAfter_)
return true;
else
return false;
@@ -106,7 +104,7 @@
OBufferStream os;
CryptoPP::FileSink sink(os);
-
+
// idCert ::= SEQUENCE {
// validity Validity,
// subject Name,
@@ -126,7 +124,7 @@
// Name ::= CHOICE {
// RDNSequence }
- //
+ //
// RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
DERSequenceEncoder name(idCert);
{
@@ -137,7 +135,7 @@
}
}
name.MessageEnd();
-
+
// SubjectPublicKeyInfo
key_.encode(idCert);
@@ -151,7 +149,7 @@
{
DERSequenceEncoder extensions(idCert);
{
-
+
for(ExtensionList::iterator it = extensionList_.begin();
it != extensionList_.end(); ++it)
{
@@ -168,14 +166,14 @@
setContentType(MetaInfo::TYPE_KEY);
}
-void
+void
Certificate::decode()
{
using namespace CryptoPP;
OBufferStream os;
CryptoPP::StringSource source(getContent().value(), getContent().value_size(), true);
-
+
// idCert ::= SEQUENCE {
// validity Validity,
// subject Name,
@@ -195,7 +193,7 @@
// Name ::= CHOICE {
// RDNSequence }
- //
+ //
// RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
subjectDescriptionList_.clear();
BERSequenceDecoder name(idCert);
@@ -206,7 +204,7 @@
}
}
name.MessageEnd();
-
+
// SubjectPublicKeyInfo ::= SEQUENCE {
// algorithm AlgorithmIdentifier
// keybits BIT STRING }
@@ -235,18 +233,18 @@
idCert.MessageEnd();
}
-void
+void
Certificate::printCertificate(std::ostream &os) const
{
os << "Certificate name:" << endl;
os << " " << getName() << endl;
os << "Validity:" << endl;
{
- os << " NotBefore: " << toIsoString(notBefore_) << endl;
- os << " NotAfter: " << toIsoString(notAfter_) << endl;
+ os << " NotBefore: " << time::toIsoString(notBefore_) << endl;
+ os << " NotAfter: " << time::toIsoString(notAfter_) << endl;
}
- os << "Subject Description:" << endl;
+ os << "Subject Description:" << endl;
for(SubjectDescriptionList::const_iterator it = subjectDescriptionList_.begin();
it != subjectDescriptionList_.end(); ++it)
{
@@ -256,7 +254,7 @@
os << "Public key bits:" << endl;
CryptoPP::Base64Encoder encoder(new CryptoPP::FileSink(os), true, 64);
key_.encode(encoder);
-
+
// ndnboost::iostreams::stream<ndnboost::iostreams::array_source> is((const char*)key_.getKeyDer().buf(), key_.getKeyDer().size());
// ptr_lib::shared_ptr<der::DerNode> keyRoot = der::DerNode::parse(reinterpret_cast<der::InputIterator&> (is));