ripplehang commented on code in PR #43601:
URL: https://github.com/apache/arrow/pull/43601#discussion_r1741405659


##########
cpp/src/arrow/filesystem/util_internal.cc:
##########
@@ -260,6 +263,42 @@ Result<FileInfoVector> GlobFiles(const 
std::shared_ptr<FileSystem>& filesystem,
   return out;
 }
 
+Result<std::string> CalculateSSECKeyMD5(const std::string& base64_encoded_key,
+    int expect_input_key_size) {
+  if (base64_encoded_key.size() < 2) {
+    return Status::Invalid("At least 2 bytes needed for the base64 encoded 
string");
+  }
+  // Check if the string contains only valid Base64 characters
+  for (char c : base64_encoded_key) {
+    if (!std::isalnum(c) && c != '+' && c != '/' && c != '=') {
+      return Status::Invalid("Invalid character found in the base64 encoded 
string");
+    }
+  }
+
+  // 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

Review Comment:
   ok, I would refine. 



##########
cpp/src/arrow/filesystem/util_internal.cc:
##########
@@ -260,6 +263,42 @@ Result<FileInfoVector> GlobFiles(const 
std::shared_ptr<FileSystem>& filesystem,
   return out;
 }
 
+Result<std::string> CalculateSSECKeyMD5(const std::string& base64_encoded_key,
+    int expect_input_key_size) {
+  if (base64_encoded_key.size() < 2) {
+    return Status::Invalid("At least 2 bytes needed for the base64 encoded 
string");
+  }
+  // Check if the string contains only valid Base64 characters
+  for (char c : base64_encoded_key) {
+    if (!std::isalnum(c) && c != '+' && c != '/' && c != '=') {
+      return Status::Invalid("Invalid character found in the base64 encoded 
string");
+    }
+  }
+
+  // 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) {
+    return Status::Invalid("Invalid Length for the key");
+  }
+
+  // Convert the raw binary key to an Aws::String
+  Aws::String rawKeyStr(reinterpret_cast<const 
char*>(rawKey.GetUnderlyingData()),
+                        rawKey.GetLength());
+
+  // Compute the MD5 hash of the raw binary key
+  Aws::Utils::ByteBuffer md5Hash = 
Aws::Utils::HashingUtils::CalculateMD5(rawKeyStr);
+
+  // Base64-encode the MD5 hash
+  Aws::String awsEncodedHash = Aws::Utils::HashingUtils::Base64Encode(md5Hash);

Review Comment:
   ok, I would refine. 



##########
cpp/src/arrow/filesystem/util_internal.cc:
##########
@@ -260,6 +263,42 @@ Result<FileInfoVector> GlobFiles(const 
std::shared_ptr<FileSystem>& filesystem,
   return out;
 }
 
+Result<std::string> CalculateSSECKeyMD5(const std::string& base64_encoded_key,
+    int expect_input_key_size) {
+  if (base64_encoded_key.size() < 2) {
+    return Status::Invalid("At least 2 bytes needed for the base64 encoded 
string");
+  }
+  // Check if the string contains only valid Base64 characters
+  for (char c : base64_encoded_key) {
+    if (!std::isalnum(c) && c != '+' && c != '/' && c != '=') {
+      return Status::Invalid("Invalid character found in the base64 encoded 
string");
+    }
+  }
+
+  // Decode the Base64-encoded key to get the raw binary key
+  Aws::Utils::ByteBuffer rawKey =
+      Aws::Utils::HashingUtils::Base64Decode(base64_encoded_key);

Review Comment:
   ok, I would refine. 



-- 
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]

Reply via email to