diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cert/cvc/cvc_self.cpp | 2 | ||||
-rw-r--r-- | src/cert/x509/x509opt.cpp | 2 | ||||
-rw-r--r-- | src/cert/x509/x509stor.cpp | 2 | ||||
-rw-r--r-- | src/entropy/hres_timer/hres_timer.cpp | 1 | ||||
-rw-r--r-- | src/utils/time.cpp | 25 | ||||
-rw-r--r-- | src/utils/time.h | 4 |
6 files changed, 20 insertions, 16 deletions
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); |