3232#include < rapidjson/writer.h>
3333#include " Constants.h"
3434#include " ResponseFromJsonBuilder.h"
35+ #include " Rfc1123Helper.h"
3536#include " olp/core/http/NetworkResponse.h"
3637#include " olp/core/http/NetworkUtils.h"
3738#include " olp/core/logging/Log.h"
@@ -58,7 +59,6 @@ constexpr auto kOauthTimestamp = "oauth_timestamp";
5859constexpr auto kOauthSignatureMethod = " oauth_signature_method" ;
5960constexpr auto kVersion = " 1.0" ;
6061constexpr auto kHmac = " HMAC-SHA256" ;
61- constexpr auto kLogTag = " AuthenticationClientUtils" ;
6262
6363std::string Base64Encode (const Crypto::Sha256Digest& digest) {
6464 std::string ret = olp::utils::Base64Encode (digest.data (), digest.size ());
@@ -98,52 +98,10 @@ namespace client = olp::client;
9898
9999constexpr auto kDate = " date" ;
100100
101- #ifdef _WIN32
102- // Windows does not have ::strptime and ::timegm
103101std::time_t ParseTime (const std::string& value) {
104- std::tm tm = {};
105- std::istringstream ss (value);
106- ss >> std::get_time (&tm, " %a, %d %b %Y %H:%M:%S %z" );
107- return _mkgmtime (&tm);
102+ return internal::ParseRfc1123GmtNoExceptions (value);
108103}
109104
110- #else
111-
112- std::string TrimDateHeaderValue (const std::string& value) {
113- const auto begin = value.find_first_not_of (" \t\r\n " );
114- if (begin == std::string::npos) {
115- return {};
116- }
117- const auto end = value.find_last_not_of (" \t\r\n " );
118- return value.substr (begin, end - begin + 1 );
119- }
120-
121- std::time_t ParseTime (const std::string& value) {
122- std::tm tm = {};
123- const auto trimmed_value = TrimDateHeaderValue (value);
124-
125- // Use a C locale to keep RFC1123 parsing locale-independent.
126- // Literal "GMT" avoids platform-specific %Z behaviour.
127- locale_t c_locale = newlocale (LC_ALL_MASK, " C" , (locale_t )0 );
128- if (c_locale == (locale_t )0 ) {
129- OLP_SDK_LOG_WARNING (kLogTag , " Failed to create C locale" );
130- return static_cast <std::time_t >(-1 );
131- }
132-
133- const auto parsed_until = ::strptime_l (
134- trimmed_value.c_str (), " %a, %d %b %Y %H:%M:%S GMT" , &tm, c_locale);
135- freelocale (c_locale);
136-
137- if (parsed_until != trimmed_value.c_str () + trimmed_value.size ()) {
138- OLP_SDK_LOG_WARNING (kLogTag , " Timestamp is not fully parsed " << value);
139- return static_cast <std::time_t >(-1 );
140- }
141-
142- return timegm (&tm);
143- }
144-
145- #endif
146-
147105porting::optional<std::time_t > GetTimestampFromHeaders (
148106 const olp::http::Headers& headers) {
149107 auto it =
0 commit comments