diff --git a/src/librepgp/stream-sig.cpp b/src/librepgp/stream-sig.cpp index cba39f7ff..40e676e9e 100644 --- a/src/librepgp/stream-sig.cpp +++ b/src/librepgp/stream-sig.cpp @@ -73,7 +73,7 @@ signature_hash_key(const pgp_key_pkt_t &key, rnp::Hash &hash, pgp_version_t pgpv break; } case PGP_V5: { - assert(key.pub_data.size() < ((size_t) 1 << 32)); + assert(key.pub_data.size() < ((uint64_t) 1 << 32)); uint8_t hdr[5] = {0x9A, 0x00, 0x00, 0x00, 0x00}; write_uint32(hdr + 1, key.pub_data.size()); hash.add(&hdr, 5); @@ -82,7 +82,7 @@ signature_hash_key(const pgp_key_pkt_t &key, rnp::Hash &hash, pgp_version_t pgpv } #if defined(ENABLE_CRYPTO_REFRESH) case PGP_V6: { - assert(key.pub_data.size() < ((size_t) 1 << 32)); + assert(key.pub_data.size() < ((uint64_t) 1 << 32)); uint8_t hdr[5] = {0x9b, 0x00, 0x00, 0x00, 0x00}; write_uint32(hdr + 1, key.pub_data.size()); hash.add(hdr, sizeof(hdr)); diff --git a/src/tests/cli_tests.py b/src/tests/cli_tests.py index 9ffdef585..93277cf70 100755 --- a/src/tests/cli_tests.py +++ b/src/tests/cli_tests.py @@ -10,6 +10,7 @@ import time import unittest import random +import ctypes from platform import architecture from cli_common import (file_text, find_utility, is_windows, list_upto, @@ -61,6 +62,13 @@ def escape_regex(str): return '^' + ''.join((c, "[\\x{:02X}]".format(ord(c)))[0 <= ord(c) <= 0x20 \ or c in ['[',']','(',')','|','"','$','.','*','^','$','\\','+','?','{','}']] for c in str) + '$' +def time_t_is_greater_than_32bit() -> bool: + if hasattr(ctypes, 'c_time_t'): + return ctypes.sizeof(ctypes.c_time_t) > 4 + else: + # probably Python < 3.12, just guess based on sys.maxsize + return sys.maxsize > 2 ** 32 + UNICODE_LATIN_CAPITAL_A_GRAVE = unichr(192) UNICODE_LATIN_SMALL_A_GRAVE = unichr(224) UNICODE_LATIN_CAPITAL_A_MACRON = unichr(256) @@ -3761,7 +3769,6 @@ def test_interactive_password(self): def test_set_current_time(self): # Too old date - is64bit = sys.maxsize > 2 ** 32 gparam = ['--homedir', RNPDIR2, '--notty', '--password', PASSWORD, '--generate-key', '--numbits', '1024', '--current-time'] rparam = ['--homedir', RNPDIR2, '--notty', '--remove-key'] ret, out, err = run_proc(RNPK, gparam + ['1950-01-02', '--userid', 'key-1950']) @@ -3839,7 +3846,7 @@ def test_set_current_time(self): # Try too distant date for expiration ret, out, err = run_proc(RNPK, gparam + ['2024-02-29', '--expiration', '3024-02-29', '--userid', 'key-2924']) - if is64bit: + if time_t_is_greater_than_32bit(): self.assertEqual(ret, 1) self.assertRegex(err, r'(?s)^.*Expiration time exceeds 32-bit value.*$') self.assertRegex(err, r'(?s)^.*Failed to set primary key expiration..*$')