about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/login.rs8
-rw-r--r--src/main.rs3
-rw-r--r--src/media/storage/file.rs16
5 files changed, 16 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 66064b3..532723c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1876,7 +1876,6 @@ dependencies = [
  "async-trait",
  "axum",
  "axum-extra",
- "base64 0.22.1",
  "bytes",
  "chrono",
  "clap",
@@ -1885,7 +1884,6 @@ dependencies = [
  "faker_rand",
  "futures",
  "futures-util",
- "hex",
  "html5ever",
  "http-cache-reqwest",
  "hyper",
diff --git a/Cargo.toml b/Cargo.toml
index 18081ac..467ad08 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -124,7 +124,6 @@ argon2 = { version = "0.5.3", features = ["std"] }
 async-trait = "0.1.83"
 axum = { workspace = true, features = ["multipart", "json", "form", "macros"] }
 axum-extra = { version = "0.9.6", features = ["cookie", "cookie-signed", "typed-header"] }
-base64 = "0.22.1"
 bytes = "1.9.0"
 chrono = { workspace = true }
 clap = { workspace = true, features = ["derive"], optional = true }
@@ -132,7 +131,6 @@ data-encoding = { workspace = true }
 either = "1.13.0"
 futures = { workspace = true }
 futures-util = { workspace = true }
-hex = "0.4.3"
 html5ever = "=0.27.0"
 http-cache-reqwest = { version = "0.15.0", default-features = false, features = ["manager-moka"] }
 hyper = "1.5.2"
diff --git a/src/login.rs b/src/login.rs
index 646c832..19bfaf7 100644
--- a/src/login.rs
+++ b/src/login.rs
@@ -332,7 +332,13 @@ async fn client_metadata<S: Storage + Send + Sync + 'static>(
         digest.update(b" ");
         digest.update(crate::OAUTH2_SOFTWARE_ID.as_bytes());
 
-        let etag = String::from("W/") + &hex::encode(digest.finalize());
+        let etag = {
+            let mut etag = String::with_capacity(66);
+            etag.push_str("W/");
+            data_encoding::HEXLOWER.encode_append(&digest.finalize(), &mut etag);
+
+            etag
+        };
         axum_extra::headers::ETag::from_str(&etag).unwrap()
     };
     if let Some(cached) = cached {
diff --git a/src/main.rs b/src/main.rs
index 3aee6c3..f57b0be 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,3 @@
-use base64::Engine;
 use kittybox::{database::Storage, indieauth::backend::AuthBackend, media::storage::MediaStore, webmentions::Webmention, compose_kittybox};
 use tokio::{sync::Mutex, task::JoinSet};
 use std::{env, future::IntoFuture, sync::Arc};
@@ -82,7 +81,7 @@ async fn main() {
     // TODO: load from environment
     let cookie_key = axum_extra::extract::cookie::Key::from(&env::var("COOKIE_KEY")
         .as_deref()
-        .map(|s| base64::prelude::BASE64_STANDARD.decode(s.as_bytes())
+        .map(|s| data_encoding::BASE64_MIME_PERMISSIVE.decode(s.as_bytes())
             .expect("Invalid cookie key: must be base64 encoded")
         )
         .unwrap()
diff --git a/src/media/storage/file.rs b/src/media/storage/file.rs
index 711b298..e432945 100644
--- a/src/media/storage/file.rs
+++ b/src/media/storage/file.rs
@@ -99,15 +99,15 @@ impl MediaStore for FileStore {
         tempfile.flush().await?;
         tempfile.into_inner().sync_all().await?;
 
-        let hash = hasher.finalize();
-        debug!("Pending upload hash: {}", hex::encode(hash));
+        let hash = data_encoding::HEXLOWER.encode(&hasher.finalize());
+        debug!("Pending upload hash: {}", hash);
         let filename = format!(
             "{}/{}/{}/{}/{}",
-            hex::encode([hash[0]]),
-            hex::encode([hash[1]]),
-            hex::encode([hash[2]]),
-            hex::encode([hash[3]]),
-            hex::encode(&hash[4..32])
+            &hash[0..2],
+            &hash[2..4],
+            &hash[4..6],
+            &hash[6..8],
+            &hash[8..]
         );
         let domain_str = domain.to_string();
         let filepath = self.base.join(domain_str.as_str()).join(&filename);
@@ -115,7 +115,7 @@ impl MediaStore for FileStore {
         let metapath = self.base.join(domain_str.as_str()).join(&metafilename);
         let metatemppath = self.base.join(domain_str.as_str()).join(metafilename + ".tmp");
         metadata.length = std::num::NonZeroUsize::new(length);
-        metadata.etag = Some(hex::encode(hash));
+        metadata.etag = Some(hash);
         debug!("File path: {}, metadata: {}", filepath.display(), metapath.display());
         {
             let parent = filepath.parent().unwrap();