remove openssl dep

This commit is contained in:
weisd
2024-12-23 19:58:37 +08:00
parent efed0a4884
commit e725c97536
8 changed files with 3171 additions and 959 deletions
+4 -2
View File
@@ -49,7 +49,7 @@ use crate::{
store_init::{load_format_erasure, ErasureError},
utils::{
self,
crypto::{base64_decode, base64_encode, hex, sha256},
crypto::{base64_decode, base64_encode, hex},
path::{encode_dir_object, has_suffix, SLASH_SEPARATOR},
},
xhttp,
@@ -540,7 +540,9 @@ impl SetDisks {
fn get_multipart_sha_dir(bucket: &str, object: &str) -> String {
let path = format!("{}/{}", bucket, object);
hex(sha256(path.as_bytes()).as_ref())
let mut hasher = Sha256::new();
hasher.update(path);
hex(hasher.finalize())
}
fn common_parity(parities: &[i32], default_parity_count: i32) -> i32 {
+12 -12
View File
@@ -10,16 +10,16 @@ pub fn hex(data: impl AsRef<[u8]>) -> String {
hex_simd::encode_to_string(data, hex_simd::AsciiCase::Lower)
}
#[cfg(windows)]
pub fn sha256(data: &[u8]) -> impl AsRef<[u8; 32]> {
use sha2::{Digest, Sha256};
<Sha256 as Digest>::digest(data)
}
// #[cfg(windows)]
// pub fn sha256(data: &[u8]) -> impl AsRef<[u8; 32]> {
// use sha2::{Digest, Sha256};
// <Sha256 as Digest>::digest(data)
// }
#[cfg(not(windows))]
pub fn sha256(data: &[u8]) -> impl AsRef<[u8]> {
use openssl::hash::{Hasher, MessageDigest};
let mut h = Hasher::new(MessageDigest::sha256()).unwrap();
h.update(data).unwrap();
h.finish().unwrap()
}
// #[cfg(not(windows))]
// pub fn sha256(data: &[u8]) -> impl AsRef<[u8]> {
// use openssl::hash::{Hasher, MessageDigest};
// let mut h = Hasher::new(MessageDigest::sha256()).unwrap();
// h.update(data).unwrap();
// h.finish().unwrap()
// }