about summary refs log tree commit diff
path: root/indieauth
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-04 22:01:54 +0300
committerVika <vika@fireburn.ru>2024-08-17 16:05:41 +0300
commit6d0df0fe7caebc44e9f05058c7b4cb9b6fd97ed9 (patch)
tree3aba9b7e95b6af629107a885dac80c29da22c3a8 /indieauth
parent6899c89da7aac13d6f8b092419fab3ae542d48e2 (diff)
kittybox-indieauth: allow using custom RNGs for PKCE
Diffstat (limited to 'indieauth')
-rw-r--r--indieauth/src/pkce.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/indieauth/src/pkce.rs b/indieauth/src/pkce.rs
index bf8d1a0..88444b6 100644
--- a/indieauth/src/pkce.rs
+++ b/indieauth/src/pkce.rs
@@ -47,12 +47,21 @@ impl PKCEVerifier {
     /// Generate a new PKCE verifier string of 128 bytes in length.
     #[allow(clippy::new_without_default)]
     pub fn new() -> Self {
-        let bytes = rand::thread_rng()
+        Self::from_rng(&mut rand::thread_rng())
+    }
+
+    /// Generate a new PKCE string of 128 bytes in length, using
+    /// the provided random number generator.
+    pub fn from_rng(rng: &mut (impl rand::CryptoRng + rand::Rng)) -> Self {
+        use rand::{Rng, distributions::Alphanumeric};
+
+        let bytes = rng
             .sample_iter(&Alphanumeric)
             .take(128)
             .collect::<Vec<u8>>();
         Self(String::from_utf8(bytes).unwrap())
     }
+
 }
 
 /// A PKCE challenge as described in [RFC7636].