Skip to content

decode panics on wasm32-unknown-unknown when validate_exp is true #339

Closed
@bakcxoj

Description

@bakcxoj

fn get_current_timestamp() -> u64 uses SystemTime::now() to get the current unix timestamp. Unfortunately, SystemTime functions panic on wasm32-unknown-unknown.

There are a couple of approaches to fix this:

  1. Switch to chrono for getting the timestamp
    pub fn get_current_timestamp() -> u64 {
        chrono::Utc::now().timestamp() as u64
    }
  2. In Validation, allow the user to supply a timestamp
    /// Supply a custom timestamp for checking `exp` and `nbf` claims.
    /// If `None`, will use `SystemTime::now()`.
    ///
    /// Defaults to `None`.
    pub current_timestamp: Option<u64>,

As a long-term solution, I prefer option 2 as it adds no cost, doesn't inflate the dependency tree, and allows for better customization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions