@@ -722,13 +722,23 @@ namespace jwt {
722722 if (key.substr (0 , 27 ) == " -----BEGIN CERTIFICATE-----" ) {
723723 auto epkey = helper::extract_pubkey_from_cert<error_category>(key, password, ec);
724724 if (ec) return {};
725- const int len = static_cast <int >(epkey.size ());
725+ // Ensure the size fits into an int before casting
726+ if (epkey.size () > static_cast <std::size_t >((std::numeric_limits<int >::max)())) {
727+ ec = error_category::load_key_bio_write; // Add an appropriate error here
728+ return {};
729+ }
730+ int len = static_cast <int >(epkey.size ());
726731 if (BIO_write (pubkey_bio.get (), epkey.data (), len) != len) {
727732 ec = error_category::load_key_bio_write;
728733 return {};
729734 }
730735 } else {
731- const int len = static_cast <int >(key.size ());
736+ // Ensure the size fits into an int before casting
737+ if (key.size () > static_cast <std::size_t >((std::numeric_limits<int >::max)())) {
738+ ec = error_category::load_key_bio_write; // Add an appropriate error here
739+ return {};
740+ }
741+ int len = static_cast <int >(key.size ());
732742 if (BIO_write (pubkey_bio.get (), key.data (), len) != len) {
733743 ec = error_category::load_key_bio_write;
734744 return {};
@@ -2610,7 +2620,8 @@ namespace jwt {
26102620
26112621 JWT_CLAIM_EXPLICIT basic_claim (typename json_traits::string_type s) : val(std::move(s)) {}
26122622 JWT_CLAIM_EXPLICIT basic_claim (const date& d)
2613- : val(typename json_traits::integer_type (std::chrono::system_clock::to_time_t (d))) {}
2623+ : val(typename json_traits::integer_type (
2624+ std::chrono::duration_cast<std::chrono::seconds>(d.time_since_epoch()).count())) {}
26142625 JWT_CLAIM_EXPLICIT basic_claim (typename json_traits::array_type a) : val(std::move(a)) {}
26152626 JWT_CLAIM_EXPLICIT basic_claim (typename json_traits::value_type v) : val(std::move(v)) {}
26162627 JWT_CLAIM_EXPLICIT basic_claim (const set_t & s) : val(typename json_traits::array_type (s.begin(), s.end())) {}
@@ -2659,9 +2670,8 @@ namespace jwt {
26592670 */
26602671 date as_date () const {
26612672 using std::chrono::system_clock;
2662- if (get_type () == json::type::number)
2663- return system_clock::from_time_t (static_cast <std::time_t >(std::round (as_number ())));
2664- return system_clock::from_time_t (static_cast <std::time_t >(as_integer ()));
2673+ if (get_type () == json::type::number) return date (std::chrono::seconds (std::llround (as_number ())));
2674+ return date (std::chrono::seconds (as_integer ()));
26652675 }
26662676
26672677 /* *
@@ -3246,8 +3256,8 @@ namespace jwt {
32463256 * \param d token expiration timeout
32473257 * \return *this to allow for method chaining
32483258 */
3249- template <class Rep >
3250- builder& set_expires_in (const std::chrono::duration<Rep>& d) {
3259+ template <class Rep , class Period >
3260+ builder& set_expires_in (const std::chrono::duration<Rep, Period >& d) {
32513261 return set_payload_claim (" exp" , basic_claim<json_traits>(clock.now () + d));
32523262 }
32533263 /* *
0 commit comments