about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-04 22:08:48 +0300
committerVika <vika@fireburn.ru>2024-08-17 16:05:41 +0300
commitf185df030530ae52fcb60b4cc958ca98da8cfaa1 (patch)
tree868d6f7409294d4f9aa80ec790b6ec8312288354
parent6d0df0fe7caebc44e9f05058c7b4cb9b6fd97ed9 (diff)
downloadkittybox-f185df030530ae52fcb60b4cc958ca98da8cfaa1.tar.zst
kittybox-indieauth: small code cleanups
-rw-r--r--indieauth/src/lib.rs6
-rw-r--r--indieauth/src/pkce.rs14
-rw-r--r--indieauth/src/scopes.rs3
3 files changed, 15 insertions, 8 deletions
diff --git a/indieauth/src/lib.rs b/indieauth/src/lib.rs
index bbabe1f..ce0ef9f 100644
--- a/indieauth/src/lib.rs
+++ b/indieauth/src/lib.rs
@@ -265,6 +265,10 @@ impl axum_core::response::IntoResponse for Profile {
 /// it hasn't been tampered with.
 #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
 pub struct State(String);
+
+// Default doesn't make sense semantically, as there is not an
+// identity value.
+#[allow(clippy::new_without_default)]
 impl State {
     /// Generate a random state string of 128 bytes in length.
     pub fn new() -> Self {
@@ -904,7 +908,7 @@ mod tests {
             code_verifier: PKCEVerifier("helloworld".to_string()),
             code: "hithere".to_owned()
         };
-        let serialized = serde_urlencoded::to_string(&[
+        let serialized = serde_urlencoded::to_string([
             ("grant_type", "authorization_code"),
             ("code", "hithere"),
             ("client_id", "https://kittybox.fireburn.ru/"),
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<str> 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
diff --git a/indieauth/src/scopes.rs b/indieauth/src/scopes.rs
index c664c55..e1df371 100644
--- a/indieauth/src/scopes.rs
+++ b/indieauth/src/scopes.rs
@@ -120,6 +120,9 @@ impl AsRef<[Scope]> for Scopes {
         self.0.as_ref()
     }
 }
+
+// Explicit implementation of ToString because of specific requirements.
+#[allow(clippy::to_string_trait_impl)]
 impl ToString for Scopes {
     fn to_string(&self) -> String {
         self.0.iter()