about summary refs log tree commit diff
path: root/indieauth/src
diff options
context:
space:
mode:
Diffstat (limited to 'indieauth/src')
-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].