mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-06-07 11:30:49 +00:00
Add dedicated upper- and lower-case hex functions (#1734)
This makes the call sites more readable than a boolean parameter.
This commit is contained in:
parent
18e9c62087
commit
66006ba48d
|
@ -62,7 +62,7 @@ std::string s3fs_sha256_hex_fd(int fd, off_t start, off_t size)
|
|||
return std::string("");
|
||||
}
|
||||
|
||||
std::string sha256hex = s3fs_hex(sha256, digestlen);
|
||||
std::string sha256hex = s3fs_hex_lower(sha256, digestlen);
|
||||
delete[] sha256;
|
||||
|
||||
return sha256hex;
|
||||
|
|
|
@ -2628,7 +2628,7 @@ std::string S3fsCurl::CalcSignature(const std::string& method, const std::string
|
|||
StringToSign = "AWS4-HMAC-SHA256\n";
|
||||
StringToSign += date8601 + "\n";
|
||||
StringToSign += strdate + "/" + endpoint + "/s3/aws4_request\n";
|
||||
StringToSign += s3fs_hex(sRequest, sRequest_len);
|
||||
StringToSign += s3fs_hex_lower(sRequest, sRequest_len);
|
||||
delete[] sRequest;
|
||||
|
||||
const unsigned char* cscope = reinterpret_cast<const unsigned char*>(StringToSign.c_str());
|
||||
|
@ -2639,7 +2639,7 @@ std::string S3fsCurl::CalcSignature(const std::string& method, const std::string
|
|||
s3fs_HMAC256(kSigning, kSigning_len, cscope, cscope_len, &md, &md_len);
|
||||
delete[] kSigning;
|
||||
|
||||
Signature = s3fs_hex(md, md_len);
|
||||
Signature = s3fs_hex_lower(md, md_len);
|
||||
delete[] md;
|
||||
|
||||
return Signature;
|
||||
|
@ -2660,7 +2660,7 @@ void S3fsCurl::insertV4Headers()
|
|||
unsigned char* sRequest = NULL;
|
||||
unsigned int sRequest_len = 0;
|
||||
s3fs_sha256(b_postdata, cRequest_len, &sRequest, &sRequest_len);
|
||||
payload_hash = s3fs_hex(sRequest, sRequest_len);
|
||||
payload_hash = s3fs_hex_lower(sRequest, sRequest_len);
|
||||
delete[] sRequest;
|
||||
break;
|
||||
}
|
||||
|
@ -3751,7 +3751,7 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const st
|
|||
S3FS_PRN_ERR("Could not make md5 for file(part %d)", part_num);
|
||||
return -EIO;
|
||||
}
|
||||
partdata.etag = s3fs_hex(md5raw, get_md5_digest_length());
|
||||
partdata.etag = s3fs_hex_lower(md5raw, get_md5_digest_length());
|
||||
char* md5base64p = s3fs_base64(md5raw, get_md5_digest_length());
|
||||
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-MD5", md5base64p);
|
||||
delete[] md5base64p;
|
||||
|
|
|
@ -152,7 +152,7 @@ std::string urlEncode(const std::string &s)
|
|||
result += c;
|
||||
}else{
|
||||
result += "%";
|
||||
result += s3fs_hex(&c, 1, false);
|
||||
result += s3fs_hex_upper(&c, 1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -182,7 +182,7 @@ std::string urlEncode2(const std::string &s)
|
|||
result += c;
|
||||
}else{
|
||||
result += "%";
|
||||
result += s3fs_hex(&c, 1, false);
|
||||
result += s3fs_hex_upper(&c, 1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -362,12 +362,8 @@ bool convert_unixtime_from_option_arg(const char* argv, time_t& unixtime)
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string s3fs_hex(const unsigned char* input, size_t length, bool lower)
|
||||
static std::string s3fs_hex(const unsigned char* input, size_t length, const char *hexAlphabet)
|
||||
{
|
||||
static const char hexLower[] = "0123456789abcdef";
|
||||
static const char hexUpper[] = "0123456789ABCDEF";
|
||||
|
||||
const char* hexAlphabet = (lower ? hexLower : hexUpper);
|
||||
std::string hex;
|
||||
for(size_t pos = 0; pos < length; ++pos){
|
||||
hex += hexAlphabet[input[pos] / 16];
|
||||
|
@ -376,6 +372,16 @@ std::string s3fs_hex(const unsigned char* input, size_t length, bool lower)
|
|||
return hex;
|
||||
}
|
||||
|
||||
std::string s3fs_hex_lower(const unsigned char* input, size_t length)
|
||||
{
|
||||
return s3fs_hex(input, length, "0123456789abcdef");
|
||||
}
|
||||
|
||||
std::string s3fs_hex_upper(const unsigned char* input, size_t length)
|
||||
{
|
||||
return s3fs_hex(input, length, "0123456789ABCDEF");
|
||||
}
|
||||
|
||||
char* s3fs_base64(const unsigned char* input, size_t length)
|
||||
{
|
||||
static const char base[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
|
|
@ -96,7 +96,8 @@ bool get_keyword_value(const std::string& target, const char* keyword, std::stri
|
|||
//
|
||||
// For binary string
|
||||
//
|
||||
std::string s3fs_hex(const unsigned char* input, size_t length, bool lower = true);
|
||||
std::string s3fs_hex_lower(const unsigned char* input, size_t length);
|
||||
std::string s3fs_hex_upper(const unsigned char* input, size_t length);
|
||||
char* s3fs_base64(const unsigned char* input, size_t length);
|
||||
unsigned char* s3fs_decode64(const char* input, size_t* plength);
|
||||
|
||||
|
|
|
@ -40,8 +40,8 @@ template <> void assert_equals(const std::string &x, const std::string &y, const
|
|||
{
|
||||
if (x != y) {
|
||||
std::cerr << x << " != " << y << " at " << file << ":" << line << std::endl;
|
||||
std::cerr << s3fs_hex(reinterpret_cast<const unsigned char *>(x.c_str()), x.size()) << std::endl;
|
||||
std::cerr << s3fs_hex(reinterpret_cast<const unsigned char *>(y.c_str()), y.size()) << std::endl;
|
||||
std::cerr << s3fs_hex_lower(reinterpret_cast<const unsigned char *>(x.c_str()), x.size()) << std::endl;
|
||||
std::cerr << s3fs_hex_lower(reinterpret_cast<const unsigned char *>(y.c_str()), y.size()) << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +59,8 @@ template <> void assert_nequals(const std::string &x, const std::string &y, cons
|
|||
{
|
||||
if (x == y) {
|
||||
std::cerr << x << " == " << y << " at " << file << ":" << line << std::endl;
|
||||
std::cerr << s3fs_hex(reinterpret_cast<const unsigned char *>(x.c_str()), x.size()) << std::endl;
|
||||
std::cerr << s3fs_hex(reinterpret_cast<const unsigned char *>(y.c_str()), y.size()) << std::endl;
|
||||
std::cerr << s3fs_hex_lower(reinterpret_cast<const unsigned char *>(x.c_str()), x.size()) << std::endl;
|
||||
std::cerr << s3fs_hex_lower(reinterpret_cast<const unsigned char *>(y.c_str()), y.size()) << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user