From fc8663a80699bd0dc69059a4c6a3c9a6b23f631a Mon Sep 17 00:00:00 2001 From: Nora Widdecke Date: Thu, 25 Mar 2021 17:19:15 +0100 Subject: openpgp: Check size of SystemTime. - Gating the 32-bit SystemTime test on the target platform may be incorrect. Instead, check the size of SystemTime. --- openpgp/src/types/timestamp.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/openpgp/src/types/timestamp.rs b/openpgp/src/types/timestamp.rs index af318c29..fc915497 100644 --- a/openpgp/src/types/timestamp.rs +++ b/openpgp/src/types/timestamp.rs @@ -669,15 +669,20 @@ mod tests { } // #668 - // Ensure that, on 32-bit platforms, Timestamps between i32::MAX + 1 and u32::MAX are - // clamped down to i32::MAX, and values below are not altered. - #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "mips"))] + // Ensure that, on systems with a 32-bit time_t, Timestamps between + // i32::MAX + 1 and u32::MAX are clamped down to i32::MAX, and values + // below are not altered. #[test] fn system_time_32_bit() -> Result<()> { + if std::mem::size_of::() != 32 { + return Ok(()) + } + let t1 = Timestamp::from(u32::MAX); - let t2 = Timestamp::from(i32::MAX as u32 + 1); assert_eq!(SystemTime::from(t1), UNIX_EPOCH + SystemDuration::new(i32::MAX as u64, 0)); + + let t2 = Timestamp::from(i32::MAX as u32 + 1); assert_eq!(SystemTime::from(t2), UNIX_EPOCH + SystemDuration::new(i32::MAX as u64, 0)); -- cgit v1.2.3