Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Unified Diff: content/child/webcrypto/jwk.cc

Issue 504413004: Move base64-urlsafe helpers to jwk.{cc,h} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/child/webcrypto/jwk.h ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/jwk.cc
diff --git a/content/child/webcrypto/jwk.cc b/content/child/webcrypto/jwk.cc
index 4bc15e2b788aa898ee618bbf31cb0bfba7cf3230..ac6f13d59e614928745c724e6e0747f66b043654 100644
--- a/content/child/webcrypto/jwk.cc
+++ b/content/child/webcrypto/jwk.cc
@@ -8,8 +8,10 @@
#include <functional>
#include <map>
+#include "base/base64.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
+#include "base/stl_util.h"
#include "base/strings/string_piece.h"
#include "content/child/webcrypto/crypto_data.h"
#include "content/child/webcrypto/status.h"
@@ -702,6 +704,29 @@ const char* GetJwkHmacAlgorithmName(blink::WebCryptoAlgorithmId hash) {
}
}
+bool Base64DecodeUrlSafe(const std::string& input, std::string* output) {
+ std::string base64EncodedText(input);
Ryan Sleevi 2014/08/27 17:22:15 1) variable naming / style 2) This still seems to
eroman 2014/08/27 18:00:57 Good catch, Done.
+ std::replace(base64EncodedText.begin(), base64EncodedText.end(), '-', '+');
+ std::replace(base64EncodedText.begin(), base64EncodedText.end(), '_', '/');
+ base64EncodedText.append((4 - base64EncodedText.size() % 4) % 4, '=');
+ return base::Base64Decode(base64EncodedText, output);
+}
+
+std::string Base64EncodeUrlSafe(const base::StringPiece& input) {
+ std::string output;
+ base::Base64Encode(input, &output);
+ std::replace(output.begin(), output.end(), '+', '-');
+ std::replace(output.begin(), output.end(), '/', '_');
+ output.erase(std::remove(output.begin(), output.end(), '='), output.end());
+ return output;
+}
+
+std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) {
+ const base::StringPiece string_piece(
+ reinterpret_cast<const char*>(vector_as_array(&input)), input.size());
+ return Base64EncodeUrlSafe(string_piece);
+}
+
} // namespace webcrypto
} // namespace content
« no previous file with comments | « content/child/webcrypto/jwk.h ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698