File: 0006-Test-for-32-bit-time_t-more-cleanly.patch

package info (click to toggle)
rnp 0.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,656 kB
  • sloc: cpp: 74,613; python: 5,272; ansic: 5,035; sh: 1,661; makefile: 25
file content (57 lines) | stat: -rw-r--r-- 2,411 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Date: Fri, 10 Oct 2025 12:43:11 -0400
Subject: Test for 32-bit time_t more cleanly.

Many systems with 32-bit memory space (e.g. debian's armhf platform)
in fact have a 32-bit time_t.

Recent versions of python (3.12 and higher) have a much better test
for sizeof(time_t).  If that's available, RNP should use that instead
of the clumsier sys.maxsize.
---
 src/tests/cli_tests.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/tests/cli_tests.py b/src/tests/cli_tests.py
index 0c52113..98b250c 100755
--- a/src/tests/cli_tests.py
+++ b/src/tests/cli_tests.py
@@ -10,6 +10,7 @@ import tempfile
 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 @@ class Misc(unittest.TestCase):
 
     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 @@ class Misc(unittest.TestCase):
 
         # 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..*$')