mapleFU commented on code in PR #43601:
URL: https://github.com/apache/arrow/pull/43601#discussion_r1738292330
##########
cpp/src/arrow/filesystem/util_internal.cc:
##########
@@ -260,6 +263,44 @@ Result<FileInfoVector> GlobFiles(const
std::shared_ptr<FileSystem>& filesystem,
return out;
}
+bool CalculateSSECKeyMD5(const std::string& base64_encoded_key, std::string&
md5_result,
+ int expect_input_key_size) {
+ if (base64_encoded_key.size() < 2) {
+ return false;
+ }
+ // Check if the string contains only valid Base64 characters
+ for (char c : base64_encoded_key) {
+ if (!std::isalnum(c) && c != '+' && c != '/' && c != '=') {
+ return false;
+ }
+ }
+
+ // Decode the Base64-encoded key to get the raw binary key
+ Aws::Utils::ByteBuffer rawKey =
+ Aws::Utils::HashingUtils::Base64Decode(base64_encoded_key);
Review Comment:
how do this handles error if `base64_encoded_key` is not valid?
##########
cpp/src/arrow/filesystem/util_internal.h:
##########
@@ -99,6 +99,16 @@ ARROW_EXPORT
Result<FileInfoVector> GlobFiles(const std::shared_ptr<FileSystem>& filesystem,
const std::string& glob);
+/// \brief Decode the Input SSE key,calculate the MD5
+/// \param base64_encoded_key is the input base64 encoded sse key
+/// \param md5_result, output resut
+/// \param expect_input_key_size, default 32
+/// \return true if the decode and calculate MD5 success, otherwise return
false
+ARROW_EXPORT
+bool CalculateSSECKeyMD5(const std::string& base64_encoded_key, std::string&
md5_result,
Review Comment:
Would you mind change to `Result<std::string>`?
##########
cpp/src/arrow/filesystem/util_internal.cc:
##########
@@ -260,6 +263,44 @@ Result<FileInfoVector> GlobFiles(const
std::shared_ptr<FileSystem>& filesystem,
return out;
}
+bool CalculateSSECKeyMD5(const std::string& base64_encoded_key, std::string&
md5_result,
+ int expect_input_key_size) {
+ if (base64_encoded_key.size() < 2) {
+ return false;
+ }
+ // Check if the string contains only valid Base64 characters
+ for (char c : base64_encoded_key) {
+ if (!std::isalnum(c) && c != '+' && c != '/' && c != '=') {
+ return false;
+ }
+ }
+
+ // Decode the Base64-encoded key to get the raw binary key
+ Aws::Utils::ByteBuffer rawKey =
+ Aws::Utils::HashingUtils::Base64Decode(base64_encoded_key);
+
+ // the key needs to be // 256 bits(32 bytes)according to
+ //
https://docs.aws.amazon.com/AmazonS3/latest/userguide/ServerSideEncryptionCustomerKeys.html#specifying-s3-c-encryption
+ if (rawKey.GetLength() != expect_input_key_size) {
Review Comment:
When would this not equal to 256?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]