light_openid/nonce.rs
1use crate::utils::crypt_utils::sha256_str;
2
3/// A Nonce used for authentication requests
4#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
5pub struct Nonce(uuid::Uuid);
6
7impl Default for Nonce {
8 fn default() -> Self {
9 Self::new()
10 }
11}
12
13impl Nonce {
14 /// Generate a new nonce
15 pub fn new() -> Self {
16 Self(uuid::Uuid::new_v4())
17 }
18
19 /// Get a hash of the nonce
20 pub fn hash(&self) -> String {
21 sha256_str(self.0.as_bytes())
22 }
23}