]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: clean-up AWSv4's Canonical QS crafting.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 10 May 2017 15:56:46 +0000 (17:56 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 7 Jun 2017 10:43:19 +0000 (12:43 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_auth_s3.cc

index 79446fe82d523009340d027d8d2275d08a176868..50169f83f09f61b3991bac5a80f5c8e55f81e41d 100644 (file)
@@ -455,17 +455,19 @@ static inline bool char_needs_aws4_escaping(const char c)
   return true;
 }
 
-static inline void aws4_uri_encode(const string& src, string& dst)
+static inline std::string aws4_uri_encode(const std::string& src)
 {
-  const char *p = src.c_str();
-  for (unsigned i = 0; i < src.size(); i++, p++) {
-    if (char_needs_aws4_escaping(*p)) {
-      rgw_uri_escape_char(*p, dst);
-      continue;
-    }
+  std::string result;
 
-    dst.append(p, 1);
+  for (const std::string::value_type c : src) {
+    if (char_needs_aws4_escaping(c)) {
+      rgw_uri_escape_char(c, result);
+    } else {
+      result.push_back(c);
+    }
   }
+
+  return result;
 }
 
 std::string get_v4_canonical_qs(const req_info& info, const bool using_qs)
@@ -494,14 +496,14 @@ std::string get_v4_canonical_qs(const req_info& info, const bool using_qs)
           if (key.length() != key_decoded.length()) {
             encoded_key = key;
           } else {
-            aws4_uri_encode(key, encoded_key);
+            encoded_key = aws4_uri_encode(key);
           }
           string val_decoded;
           url_decode(val, val_decoded);
           if (val.length() != val_decoded.length()) {
             encoded_val = val;
           } else {
-            aws4_uri_encode(val, encoded_val);
+            encoded_val = aws4_uri_encode(val);
           }
         } else {
           encoded_key = key;