зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1520949 - Use TextEncoder/TextDecoder to handle multibyte characters in passwords. r=MattN
Differential Revision: https://phabricator.services.mozilla.com/D20625 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d923108c72
Коммит
f777b77069
|
@ -50,7 +50,7 @@ const TEST_LOGINS = [
|
|||
{
|
||||
id: 4,
|
||||
username: "user",
|
||||
password: "password",
|
||||
password: "اقرأPÀßwörd",
|
||||
hostname: "http://httpbin.org",
|
||||
formSubmitURL: null,
|
||||
httpRealm: "me@kennethreitz.com", // Digest auth.
|
||||
|
|
|
@ -174,9 +174,8 @@ OSCrypto.prototype = {
|
|||
let len = outData.cbData;
|
||||
let decrypted = ctypes.cast(outData.pbData,
|
||||
wintypes.BYTE.array(len).ptr).contents;
|
||||
for (let i = 0; i < decrypted.length; i++) {
|
||||
decryptedData += String.fromCharCode(decrypted[i]);
|
||||
}
|
||||
// Output that may include characters outside of the 0-255 (byte) range needs to use TextDecoder.
|
||||
decryptedData = (new TextDecoder()).decode(new Uint8Array(decrypted));
|
||||
|
||||
this._functions.get("LocalFree")(outData.pbData);
|
||||
return decryptedData;
|
||||
|
@ -191,9 +190,11 @@ OSCrypto.prototype = {
|
|||
*/
|
||||
encryptData(data, entropy = null) {
|
||||
let encryptedData = "";
|
||||
let decryptedData = wintypes.BYTE.array(data.length)(this.stringToArray(data));
|
||||
// Input that may include characters outside of the 0-255 (byte) range needs to use TextEncoder.
|
||||
let decryptedByteData = [...(new TextEncoder()).encode(data)];
|
||||
let decryptedData = wintypes.BYTE.array(decryptedByteData.length)(decryptedByteData);
|
||||
|
||||
let inData = new this._structs.DATA_BLOB(data.length, decryptedData);
|
||||
let inData = new this._structs.DATA_BLOB(decryptedData.length, decryptedData);
|
||||
let outData = new this._structs.DATA_BLOB();
|
||||
let entropyParam;
|
||||
if (!entropy) {
|
||||
|
|
|
@ -54,6 +54,9 @@ add_task(function test_decryptData_encryptData() {
|
|||
key),
|
||||
key),
|
||||
"https://bugzilla.mozilla.org/page.cgi");
|
||||
|
||||
Assert.equal(crypto.decryptData(crypto.encryptData("新年快樂新年快樂", key), key),
|
||||
"新年快樂新年快樂");
|
||||
}
|
||||
|
||||
let keys = [null, "a", "keys", "abcdedf", "pass", "https://bugzilla.mozilla.org/page.cgi",
|
||||
|
|
Загрузка…
Ссылка в новой задаче