addon-sdk/source/lib/sdk/base64.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 "use strict";
     7 module.metadata = {
     8   "stability": "unstable"
     9 };
    11 const { Cu } = require("chrome");
    13 // Passing an empty object as second argument to avoid scope's pollution
    14 const { atob, btoa } = Cu.import("resource://gre/modules/Services.jsm", {});
    16 function isUTF8(charset) {
    17   let type = typeof charset;
    19   if (type === "undefined")
    20     return false;
    22   if (type === "string" && charset.toLowerCase() === "utf-8")
    23     return true;
    25   throw new Error("The charset argument can be only 'utf-8'");
    26 }
    28 exports.decode = function (data, charset) {
    29   if (isUTF8(charset))
    30 		return decodeURIComponent(escape(atob(data)))
    32 	return atob(data);
    33 }
    35 exports.encode = function (data, charset) {
    36   if (isUTF8(charset))
    37     return btoa(unescape(encodeURIComponent(data)))
    39 	return btoa(data);
    40 }

mercurial