From 34eca9c51215485c70492d6edea3513ada1c8895 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 7 Apr 2020 14:12:29 +0530 Subject: always round timestamps before signature creation/verification --- src/util/time.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/util/time.ts') diff --git a/src/util/time.ts b/src/util/time.ts index ea4f8ca8d..f296aba12 100644 --- a/src/util/time.ts +++ b/src/util/time.ts @@ -49,6 +49,7 @@ export function getTimestampNow(): Timestamp { export function getDurationRemaining( deadline: Timestamp, now = getTimestampNow(), + ): Duration { if (deadline.t_ms === "never") { return { d_ms: "forever" }; @@ -72,6 +73,19 @@ export function timestampMin(t1: Timestamp, t2: Timestamp): Timestamp { return { t_ms: Math.min(t1.t_ms, t2.t_ms) }; } +/** + * Truncate a timestamp so that that it represents a multiple + * of seconds. The timestamp is always rounded down. + */ +export function timestampTruncateToSecond(t1: Timestamp): Timestamp { + if (t1.t_ms === "never") { + return { t_ms: "never" }; + } + return { + t_ms: Math.floor(t1.t_ms / 1000) * 1000, + }; +} + export function durationMin(d1: Duration, d2: Duration): Duration { if (d1.d_ms === "forever") { return { d_ms: d2.d_ms }; -- cgit v1.2.3