diff options
author | Vika <vika@fireburn.ru> | 2025-01-01 05:42:45 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2025-01-01 07:08:33 +0300 |
commit | 5ad8443c8d6d9ed3f9d28ac52af529ceb41d741f (patch) | |
tree | 5d6dd326abd9cd135652e68fc893c2a95486a798 /src | |
parent | df509eadc9aecef605194b7c97c5fb02bf928b79 (diff) | |
download | kittybox-5ad8443c8d6d9ed3f9d28ac52af529ceb41d741f.tar.zst |
Get rid of base64 and hex in favor of data_encoding crate
Less dependency duplication = more fun Change-Id: Icbd0497a68fdd5bea3757e3c62c80008b87bce96
Diffstat (limited to 'src')
-rw-r--r-- | src/login.rs | 8 | ||||
-rw-r--r-- | src/main.rs | 3 | ||||
-rw-r--r-- | src/media/storage/file.rs | 16 |
3 files changed, 16 insertions, 11 deletions
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(); |