From f185df030530ae52fcb60b4cc958ca98da8cfaa1 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 4 Aug 2024 22:08:48 +0300 Subject: kittybox-indieauth: small code cleanups --- indieauth/src/pkce.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'indieauth/src/pkce.rs') diff --git a/indieauth/src/pkce.rs b/indieauth/src/pkce.rs index 88444b6..852ce0a 100644 --- a/indieauth/src/pkce.rs +++ b/indieauth/src/pkce.rs @@ -1,22 +1,18 @@ use serde::{Serialize, Deserialize}; -use rand::{Rng, distributions::Alphanumeric}; use sha2::{Sha256, Digest}; use data_encoding::BASE64URL; /// Methods to use for PKCE challenges. -#[derive(PartialEq, Eq, Copy, Clone, Debug, Serialize, Deserialize, /*Default*/)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Serialize, Deserialize, Default)] pub enum PKCEMethod { /// Base64-encoded SHA256 hash of an ASCII string. - //#[default] + #[default] S256, /// Plain string by itself. Please don't use this. #[serde(rename = "snake_case")] Plain } -// manual impl until Rust 1.62 hits nixos-unstable -impl Default for PKCEMethod { - fn default() -> Self { PKCEMethod::S256 } -} + impl PKCEMethod { /// Return a string representing a PKCE method as it would be serialized. pub fn as_str(&self) -> &'static str { @@ -37,6 +33,9 @@ impl AsRef for PKCEVerifier { self.0.as_str() } } + +// We don't need Display here, this is not a user-facing value. +#[allow(clippy::to_string_trait_impl)] impl ToString for PKCEVerifier { fn to_string(&self) -> String { self.0.clone() @@ -84,6 +83,7 @@ impl PKCEChallenge { let mut hasher = Sha256::new(); hasher.update(code_verifier.as_ref()); let mut challenge = BASE64URL.encode(&hasher.finalize()); + // Trim padding challenge.retain(|c| c != '='); challenge -- cgit 1.4.1