light-openid 2.0.4

Lightweight OpenID primitives & client
Documentation
use crate::utils::crypt_utils::sha256_str;

/// A Nonce used for authentication requests
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
pub struct Nonce(uuid::Uuid);

impl Default for Nonce {
    fn default() -> Self {
        Self::new()
    }
}

impl Nonce {
    /// Generate a new nonce
    pub fn new() -> Self {
        Self(uuid::Uuid::new_v4())
    }

    /// Get a hash of the nonce
    pub fn hash(&self) -> String {
        sha256_str(self.0.as_bytes())
    }
}