aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-12-01 15:36:30 +0000
committerlloyd <[email protected]>2009-12-01 15:36:30 +0000
commit29e9b23500d101f01988a33e8f1a6aaab39d5f7d (patch)
tree28fdc5244d6b618b09a4b0d80fd1708a56401e77
parent9ffe4441271ff41fd33fc3965c191e62bce36453 (diff)
Most files including <botan/time.h> actually just needed <chrono>
Clean up implementation of calendar_value() a bit
-rw-r--r--doc/examples/ca.cpp2
-rw-r--r--doc/examples/gen_certs.cpp2
-rw-r--r--src/cert/cvc/cvc_self.cpp2
-rw-r--r--src/cert/x509/x509opt.cpp2
-rw-r--r--src/cert/x509/x509stor.cpp2
-rw-r--r--src/entropy/hres_timer/hres_timer.cpp1
-rw-r--r--src/utils/time.cpp25
-rw-r--r--src/utils/time.h4
8 files changed, 22 insertions, 18 deletions
diff --git a/doc/examples/ca.cpp b/doc/examples/ca.cpp
index 8be0fa527..8ca6228c2 100644
--- a/doc/examples/ca.cpp
+++ b/doc/examples/ca.cpp
@@ -15,11 +15,11 @@
#include <botan/botan.h>
#include <botan/x509_ca.h>
-#include <botan/time.h>
using namespace Botan;
#include <iostream>
#include <memory>
+#include <chrono>
int main(int argc, char* argv[])
{
diff --git a/doc/examples/gen_certs.cpp b/doc/examples/gen_certs.cpp
index 557c6f46e..5f943ff3a 100644
--- a/doc/examples/gen_certs.cpp
+++ b/doc/examples/gen_certs.cpp
@@ -7,7 +7,7 @@
#include <botan/rsa.h>
#include <botan/x509self.h>
#include <botan/x509_ca.h>
-#include <botan/time.h>
+#include <chrono>
using namespace Botan;
diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp
index 3b764644f..ae10838ac 100644
--- a/src/cert/cvc/cvc_self.cpp
+++ b/src/cert/cvc/cvc_self.cpp
@@ -14,7 +14,7 @@
#include <botan/look_pk.h>
#include <botan/cvc_req.h>
#include <botan/cvc_ado.h>
-#include <botan/time.h>
+#include <chrono>
#include <sstream>
namespace Botan {
diff --git a/src/cert/x509/x509opt.cpp b/src/cert/x509/x509opt.cpp
index a2547e30a..8d235ad5d 100644
--- a/src/cert/x509/x509opt.cpp
+++ b/src/cert/x509/x509opt.cpp
@@ -8,7 +8,7 @@
#include <botan/x509self.h>
#include <botan/oids.h>
#include <botan/parsing.h>
-#include <botan/time.h>
+#include <chrono>
namespace Botan {
diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp
index a055602a8..80507c1dd 100644
--- a/src/cert/x509/x509stor.cpp
+++ b/src/cert/x509/x509stor.cpp
@@ -10,8 +10,8 @@
#include <botan/pubkey.h>
#include <botan/look_pk.h>
#include <botan/oids.h>
-#include <botan/time.h>
#include <algorithm>
+#include <chrono>
#include <memory>
namespace Botan {
diff --git a/src/entropy/hres_timer/hres_timer.cpp b/src/entropy/hres_timer/hres_timer.cpp
index 74ea801c4..0f75583ef 100644
--- a/src/entropy/hres_timer/hres_timer.cpp
+++ b/src/entropy/hres_timer/hres_timer.cpp
@@ -7,7 +7,6 @@
#include <botan/hres_timer.h>
#include <botan/cpuid.h>
-#include <botan/time.h>
#if defined(BOTAN_TARGET_OS_IS_WINDOWS)
#include <windows.h>
diff --git a/src/utils/time.cpp b/src/utils/time.cpp
index 1c64c820e..97804813d 100644
--- a/src/utils/time.cpp
+++ b/src/utils/time.cpp
@@ -43,25 +43,26 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
return res;
}
-}
-
-/*
-* Convert a time_t to a struct tm
-*/
-calendar_point calendar_value(
- const std::chrono::system_clock::time_point& time_point)
+std::tm do_gmtime(time_t time_val)
{
- time_t time_val = std::chrono::system_clock::to_time_t(time_point);
-
// Race condition: std::gmtime is not assured thread safe,
// and C++ does not include gmtime_r. Use a mutex here?
std::tm* tm_p = std::gmtime(&time_val);
if (tm_p == 0)
- throw Encoding_Error("time_t_to_tm could not convert");
+ throw Encoding_Error("calendar_value could not convert with gmtime");
+ return *tm_p;
+ }
- std::tm tm = *tm_p;
- // Race is over here
+}
+
+/*
+* Convert a time_point to a calendar_point
+*/
+calendar_point calendar_value(
+ const std::chrono::system_clock::time_point& time_point)
+ {
+ std::tm tm = do_gmtime(std::chrono::system_clock::to_time_t(time_point));
return calendar_point(tm.tm_year + 1900,
tm.tm_mon + 1,
diff --git a/src/utils/time.h b/src/utils/time.h
index 28b777efe..bd1c8fb06 100644
--- a/src/utils/time.h
+++ b/src/utils/time.h
@@ -29,6 +29,10 @@ struct BOTAN_DLL calendar_point
year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {}
};
+/*
+* @param time_point a time point from the system clock
+* @returns calendar_point object representing this time point
+*/
BOTAN_DLL calendar_point calendar_value(
const std::chrono::system_clock::time_point& time_point);