summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2017-11-08 18:34:05 +0300
committerKonstantin Tokarev <annulen@yandex.ru>2017-11-08 16:15:17 +0000
commit3f941dc062674630daa39770ac027658f8fb0302 (patch)
treedb64c8420b3d63e90dab6b1cedfde6f8555984d3
parentbd65a16f788b00f7a7c326c846158d75d4aa2614 (diff)
Support Base64URLPolicy in base64Encode
Partial cherry-pick of r159377 by Alexey Proskuryakov. https://bugs.webkit.org/show_bug.cgi?id=124442 Change-Id: I2ce9aaa5d05304132fa21e3c6d36c06e1f89e5f0 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--Source/WTF/wtf/text/Base64.cpp10
-rw-r--r--Source/WTF/wtf/text/Base64.h3
2 files changed, 9 insertions, 4 deletions
diff --git a/Source/WTF/wtf/text/Base64.cpp b/Source/WTF/wtf/text/Base64.cpp
index 7a0467a36..5df356165 100644
--- a/Source/WTF/wtf/text/Base64.cpp
+++ b/Source/WTF/wtf/text/Base64.cpp
@@ -122,9 +122,13 @@ void base64Encode(const char* data, unsigned len, Vector<char>& out, Base64Encod
}
// Add padding
- while (didx < out.size()) {
- out[didx] = '=';
- ++didx;
+ if (policy == Base64URLPolicy)
+ out.resize(didx);
+ else {
+ while (didx < out.size()) {
+ out[didx] = '=';
+ ++didx;
+ }
}
}
diff --git a/Source/WTF/wtf/text/Base64.h b/Source/WTF/wtf/text/Base64.h
index 5b0d4d80e..1454c72f2 100644
--- a/Source/WTF/wtf/text/Base64.h
+++ b/Source/WTF/wtf/text/Base64.h
@@ -35,7 +35,8 @@ namespace WTF {
enum Base64EncodePolicy {
Base64DoNotInsertLFs,
- Base64InsertLFs
+ Base64InsertLFs,
+ Base64URLPolicy // No padding, no LFs.
};
enum Base64DecodePolicy {