Skip to content

Commit

Permalink
remove optional iat for KB claims
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulmth committed Jan 14, 2024
1 parent db6670d commit 1460931
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions src/key_binding_jwt_claims.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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<String>,
nonce: String,
aud: String,
issued_at: Option<i64>,
) -> Self {
pub fn new(hasher: &dyn Hasher, jwt: String, disclosures: Vec<String>, 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,
Expand Down

0 comments on commit 1460931

Please sign in to comment.