From 1460931fe3f27e3b9958fc1cad0c1d26346e16be Mon Sep 17 00:00:00 2001 From: Abdulrahim Al Methiab Date: Sun, 14 Jan 2024 19:34:02 +0100 Subject: [PATCH] remove optional `iat` for KB claims --- src/key_binding_jwt_claims.rs | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/key_binding_jwt_claims.rs b/src/key_binding_jwt_claims.rs index cc0ce4a..2a10e66 100644 --- a/src/key_binding_jwt_claims.rs +++ b/src/key_binding_jwt_claims.rs @@ -1,15 +1,12 @@ -// Copyright 2020-2023 IOTA Stiftung +// Copyright 2020-2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use std::collections::BTreeMap; -use std::time::SystemTime; - -use itertools::Itertools; -use serde_json::Value; - use crate::Hasher; +use itertools::Itertools; use serde::Deserialize; use serde::Serialize; +use serde_json::Value; +use std::collections::BTreeMap; /// Claims set for key binding JWT. #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] @@ -26,27 +23,10 @@ impl KeyBindingJwtClaims { pub const KB_JWT_HEADER_TYP: &'static str = " kb+jwt"; /// Creates a new [`KeyBindingJwtClaims`]. - /// When `issued_at` is left as None, it will automatically default to the current time. - /// - /// # Panic - /// When `issued_at` is set to `None` and the system returns time earlier than `SystemTime::UNIX_EPOCH`. - pub fn new( - hasher: &dyn Hasher, - jwt: String, - disclosures: Vec, - nonce: String, - aud: String, - issued_at: Option, - ) -> Self { + pub fn new(hasher: &dyn Hasher, jwt: String, disclosures: Vec, nonce: String, aud: String, iat: i64) -> Self { let disclosures = disclosures.iter().join("~"); let sd_jwt = format!("{}~{}~", jwt, disclosures); let hash = hasher.encoded_digest(&sd_jwt); - let iat = issued_at.unwrap_or( - SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .expect("system time error") - .as_secs() as i64, - ); Self { iat, aud,