taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

commit 2c6788738c5f4784874e62c91e32dab4550c4626
parent 2fcc1cc40646cf14e20226dcfc1315da02988297
Author: Antoine A <>
Date:   Thu, 24 Sep 2026 12:55:33 +0200

common: more fixes

Diffstat:
Mcommon/taler-common/src/config.rs | 21+++++++++++++++++++--
Mcommon/taler-common/src/types/time.rs | 5+++--
2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/common/taler-common/src/config.rs b/common/taler-common/src/config.rs @@ -997,7 +997,12 @@ impl<'cfg, 'arg> Section<'cfg, 'arg> { pub fn duration(&self, option: &'arg str) -> Value<'arg, Duration> { self.value("temporal", option, |it| { let tmp = SignedDuration::from_str(it).map_err(|e| e.to_string())?; - Ok::<_, String>(Duration::from_millis(tmp.as_millis() as u64)) + if tmp < SignedDuration::ZERO { + return Err("temporal must not be negative".to_owned()); + } + let millis = + u64::try_from(tmp.as_millis()).map_err(|_| "temporal overflow".to_owned())?; + Ok::<_, String>(Duration::from_millis(millis)) }) } @@ -1050,6 +1055,7 @@ mod test { fmt::{Debug, Display}, fs::{File, Permissions}, os::unix::fs::PermissionsExt, + time::Duration, }; use tracing::error; @@ -1231,7 +1237,6 @@ mod test { for (raws, expected) in wellformed { for raw in *raws { let cfg = conf(&format!("[section]\nvalue={raw}")); - dbg!(&cfg); assert_eq!( *expected, lambda(&cfg.section("section"), "value").require().unwrap() @@ -1373,6 +1378,18 @@ mod test { } #[test] + fn duration() { + routine( + "temporal", + |sect, value| sect.duration(value), + &[(&["1.5s", "1500ms"], Duration::from_secs_f64(1.5))], + &[(&["-1s", "-1ns"], |_| { + format!("temporal must not be negative") + })], + ) + } + + #[test] fn map() { #[derive(Debug, PartialEq, Eq)] enum Mode { diff --git a/common/taler-common/src/types/time.rs b/common/taler-common/src/types/time.rs @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2024, 2025, 2026 Taler Systems SA + Copyright (C) 2024-2026 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -74,7 +74,8 @@ impl<'de> Deserialize<'de> for TalerTimestamp { match tmp.t_s { Value::Number(s) => { if let Some(since_epoch_s) = s.as_u64() { - jiff::Timestamp::from_second(since_epoch_s as i64) + let seconds = i64::try_from(since_epoch_s).map_err(Error::custom)?; + jiff::Timestamp::from_second(seconds) .map(Self::Timestamp) .map_err(Error::custom) } else {