chore(deps): migrate direct encoding deps to simd (#6690)

This commit is contained in:
houseme
2026-08-27 03:17:24 +08:00
committed by GitHub
parent 31031f2a46
commit ba7785d61d
81 changed files with 523 additions and 505 deletions
+5 -5
View File
@@ -99,14 +99,14 @@ swift = [
"dep:md-5",
"dep:hmac",
"dep:sha1",
"dep:hex",
"dep:hex-simd",
"dep:ipnetwork",
"dep:rustfs-trusted-proxies",
"dep:astral-tokio-tar",
"dep:base64",
"dep:base64-simd",
"dep:async-compression",
]
webdav = ["dep:dav-server", "dep:hyper", "dep:hyper-util", "dep:http", "dep:http-body-util", "dep:tokio-rustls", "dep:base64", "dep:rustls", "dep:percent-encoding", "dep:rustfs-tls-runtime", "dep:subtle"]
webdav = ["dep:dav-server", "dep:hyper", "dep:hyper-util", "dep:http", "dep:http-body-util", "dep:tokio-rustls", "dep:base64-simd", "dep:rustls", "dep:percent-encoding", "dep:rustfs-tls-runtime", "dep:subtle"]
sftp = ["dep:russh", "dep:russh-sftp", "dep:uuid", "dep:subtle", "dep:tokio-util", "dep:socket2"]
[dependencies]
@@ -163,11 +163,11 @@ urlencoding = { workspace = true, optional = true }
md-5 = { workspace = true, optional = true }
hmac = { workspace = true, optional = true }
sha1 = { workspace = true, optional = true }
hex = { workspace = true, optional = true }
hex-simd = { workspace = true, optional = true }
ipnetwork = { workspace = true, optional = true }
rustfs-trusted-proxies = { workspace = true, optional = true }
astral-tokio-tar = { workspace = true, optional = true }
base64 = { workspace = true, optional = true }
base64-simd = { workspace = true, optional = true }
async-compression = { workspace = true, optional = true, features = ["tokio", "gzip", "bzip2"] }
# WebDAV specific dependencies (optional)
+1 -1
View File
@@ -97,7 +97,7 @@ fn get_account_metadata_bucket_name(account: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(account.as_bytes());
let hash_bytes = hasher.finalize();
let hash = hex::encode(hash_bytes);
let hash = hex_simd::encode_to_string(hash_bytes, hex_simd::AsciiCase::Lower);
format!("swift-account-{}", &hash[0..16])
}
+4 -4
View File
@@ -182,7 +182,7 @@ pub fn generate_signature(
mac.update(message.as_bytes());
let result = mac.finalize();
let signature = hex::encode(result.into_bytes());
let signature = hex_simd::encode_to_string(result.into_bytes(), hex_simd::AsciiCase::Lower);
Ok(signature)
}
@@ -213,10 +213,10 @@ pub fn validate_formpost(path: &str, request: &FormPostRequest, key: &str) -> Sw
// the sibling TempURL/SFTP checks. Decode the hex first so the comparison runs
// over the raw HMAC bytes and does not leak via string length; a non-hex
// provided signature can never match and is rejected the same way.
let expected_bytes =
hex::decode(&expected_sig).map_err(|e| SwiftError::InternalServerError(format!("Signature encoding error: {}", e)))?;
let expected_bytes = hex_simd::decode_to_vec(&expected_sig)
.map_err(|e| SwiftError::InternalServerError(format!("Signature encoding error: {}", e)))?;
let signatures_match = match hex::decode(request.signature.trim()) {
let signatures_match = match hex_simd::decode_to_vec(request.signature.trim()) {
Ok(provided_bytes) => super::tempurl::constant_time_compare(&provided_bytes, &expected_bytes),
Err(_) => false,
};
+5 -1
View File
@@ -84,7 +84,11 @@ impl SLOManifest {
let mut hasher = Md5::new();
hasher.update(etag_concat.as_bytes());
format!("\"{}-{}\"", hex::encode(hasher.finalize()), self.segments.len())
format!(
"\"{}-{}\"",
hex_simd::encode_to_string(hasher.finalize(), hex_simd::AsciiCase::Lower),
self.segments.len()
)
}
/// Validate manifest against actual segments
+1 -1
View File
@@ -300,7 +300,7 @@ pub fn generate_sync_signature(path: &str, key: &str) -> SwiftResult<String> {
mac.update(path.as_bytes());
let result = mac.finalize();
Ok(hex::encode(result.into_bytes()))
Ok(hex_simd::encode_to_string(result.into_bytes(), hex_simd::AsciiCase::Lower))
}
/// Verify sync signature
+1 -1
View File
@@ -125,7 +125,7 @@ impl TempURL {
// Hex-encode result
let result = mac.finalize();
let signature = hex::encode(result.into_bytes());
let signature = hex_simd::encode_to_string(result.into_bytes(), hex_simd::AsciiCase::Lower);
Ok(signature)
}
+1 -2
View File
@@ -675,8 +675,7 @@ fn fixed_body(message: impl Into<Bytes>) -> WebDavBody {
/// Decode base64 string
fn base64_decode(encoded: &str) -> Result<Vec<u8>, ()> {
use base64::Engine;
base64::engine::general_purpose::STANDARD.decode(encoded).map_err(|_| ())
base64_simd::STANDARD.decode_to_vec(encoded).map_err(|_| ())
}
#[cfg(test)]
@@ -56,7 +56,7 @@ fn keystone_credentials(project_id: &str) -> Credentials {
fn account_metadata_bucket_name(account: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(account.as_bytes());
let hash = hex::encode(hasher.finalize());
let hash = hex_simd::encode_to_string(hasher.finalize(), hex_simd::AsciiCase::Lower);
format!("swift-account-{}", &hash[0..16])
}