From f23cef6f66a44c5c1cc8717f74b658d14fde04e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= <dev@ingo-kloecker.de>
Date: Mon, 5 May 2025 16:14:55 +0200
Subject: [PATCH 4/4] cpp: Ensure correct expiration time on 32-bit arch with
 64-bit time_t

* lang/cpp/src/key.cpp (Subkey::expirationTime): Cast away the
signedness of _gpgme_subkey.expires before casting to time_t.
--

_gpgme_subkey.expires stores the expiration as `long int` although the
expiration is always an unsigned value. Casting the value to unsigned
long int before casting it to time_t ensures that we get the correct
expiration value for 64-bit time_t even on 32-bit systems. With signed
32-bit time_t we still get a negative value as before.

GnuPG-bug-id: 7627
---
 lang/cpp/src/key.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp
index 42046aa0..2b14d901 100644
--- a/lang/cpp/src/key.cpp
+++ b/lang/cpp/src/key.cpp
@@ -633,7 +633,7 @@ time_t Subkey::creationTime() const
 
 time_t Subkey::expirationTime() const
 {
-    return static_cast<time_t>(subkey ? subkey->expires : 0);
+    return static_cast<time_t>(static_cast<unsigned long int>(subkey ? subkey->expires : 0));
 }
 
 bool Subkey::neverExpires() const
-- 
2.47.2

