summaryrefslogtreecommitdiff
path: root/src/lib/Base64.js
diff options
context:
space:
mode:
authorhackademix2018-07-01 01:01:23 +0200
committerhackademix2018-07-01 01:01:23 +0200
commiteceae7187a6f0e9510bc1165f6977256b87f490f (patch)
treed943f1ec73c09efa70954dcedb55eac82a726148 /src/lib/Base64.js
downloadnoscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.gz
noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.xz
noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.zip
Initial commit starting at version 10.1.8.3rc4.
Diffstat (limited to 'src/lib/Base64.js')
-rw-r--r--src/lib/Base64.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lib/Base64.js b/src/lib/Base64.js
new file mode 100644
index 0000000..e83d2a5
--- /dev/null
+++ b/src/lib/Base64.js
@@ -0,0 +1,49 @@
+
+'use strict';
+// we need this because of https://bugzilla.mozilla.org/show_bug.cgi?id=439276
+
+var Base64 = {
+
+ purify: function(input) {
+ return input.replace(/[^A-Za-z0-9\+\/=]+/g, '');
+ },
+
+ alt: function(s) {
+ // URL base64 variant, see http://en.wikipedia.org/wiki/Base64#URL_applications
+ return s.replace(/-/g, '+').replace(/_/g, '/')
+ },
+
+ decode: function (input, strict) {
+ var output = '';
+ var chr1, chr2, chr3;
+ var enc1, enc2, enc3, enc4;
+ var i = 0;
+
+ // if (/[^A-Za-z0-9\+\/\=]/.test(input)) return ""; // we don't need this, caller checks for us
+
+ const k = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+ while (i < input.length) {
+
+ enc1 = k.indexOf(input.charAt(i++));
+ enc2 = k.indexOf(input.charAt(i++));
+ enc3 = k.indexOf(input.charAt(i++));
+ enc4 = k.indexOf(input.charAt(i++));
+
+ chr1 = (enc1 << 2) | (enc2 >> 4);
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
+ chr3 = ((enc3 & 3) << 6) | enc4;
+
+ output += String.fromCharCode(chr1);
+
+ if (enc3 != 64) {
+ output += String.fromCharCode(chr2);
+ }
+ if (enc4 != 64) {
+ output += String.fromCharCode(chr3);
+ }
+
+ }
+ return output;
+
+ }
+};