Bug 1819019 - Convert services/automation and services/crypto to ES modules. r=markh

Differential Revision: https://phabricator.services.mozilla.com/D171052
This commit is contained in:
Mark Banner 2023-02-28 10:11:54 +00:00
parent 11246a7aca
commit f5f9e12074
6 changed files with 15 additions and 36 deletions

View File

@ -1,7 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/*
* This module is used in automation to connect the browser to
@ -23,11 +22,7 @@
* await triggerSync(username, password, "https://accounts.stage.mozaws.net");
*
*/
var EXPORTED_SYMBOLS = ["Sync", "Authentication", "initConfig", "triggerSync"];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
@ -96,7 +91,7 @@ function promiseObserver(aEventName) {
*
* await Authentication.signIn(username, password);
*/
var Authentication = {
export var Authentication = {
async isLoggedIn() {
return !!(await this.getSignedInUser());
},
@ -287,7 +282,7 @@ var Authentication = {
*
* await Sync.triggerSync();
*/
var Sync = {
export var Sync = {
getSyncLogsDirectory() {
return PathUtils.join(PathUtils.profileDir, "weave", "logs");
},
@ -397,11 +392,11 @@ var Sync = {
},
};
function initConfig(autoconfig) {
export function initConfig(autoconfig) {
Services.prefs.setCharPref(AUTOCONFIG_PREF, autoconfig);
}
async function triggerSync(username, password, autoconfig) {
export async function triggerSync(username, password, autoconfig) {
initConfig(autoconfig);
await Authentication.signIn(username, password);
var result = await Sync.triggerSync();

View File

@ -10,5 +10,5 @@ EXTRA_COMPONENTS += [
]
EXTRA_JS_MODULES["services-automation"] += [
"ServicesAutomation.jsm",
"ServicesAutomation.sys.mjs",
]

View File

@ -2,11 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["WeaveCrypto"];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const CRYPT_ALGO = "AES-CBC";
const CRYPT_ALGO_LENGTH = 256;
@ -15,12 +11,7 @@ const AES_CBC_IV_SIZE = 16;
const OPERATIONS = { ENCRYPT: 0, DECRYPT: 1 };
const UTF_LABEL = "utf-8";
const KEY_DERIVATION_ALGO = "PBKDF2";
const KEY_DERIVATION_HASHING_ALGO = "SHA-1";
const KEY_DERIVATION_ITERATIONS = 4096; // PKCS#5 recommends at least 1000.
const DERIVED_KEY_ALGO = CRYPT_ALGO;
function WeaveCrypto() {
export function WeaveCrypto() {
this.init();
}

View File

@ -2,10 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const EXPORTED_SYMBOLS = ["jwcrypto"];
const ECDH_PARAMS = {
name: "ECDH",
namedCurve: "P-256",
@ -215,4 +211,4 @@ async function deriveECDHSharedAESKey(privateKey, publicKey, keyUsages) {
);
}
const jwcrypto = new JWCrypto();
export const jwcrypto = new JWCrypto();

View File

@ -2,17 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["CryptoUtils"];
const { Observers } = ChromeUtils.import(
"resource://services-common/observers.js"
);
const { CommonUtils } = ChromeUtils.import(
"resource://services-common/utils.js"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
XPCOMUtils.defineLazyGetter(lazy, "textEncoder", function() {
@ -24,7 +21,7 @@ XPCOMUtils.defineLazyGetter(lazy, "textEncoder", function() {
* They work with octet strings, which were used before Javascript
* got ArrayBuffer and friends.
*/
var CryptoUtils = {
export var CryptoUtils = {
xor(a, b) {
let bytes = [];

View File

@ -10,9 +10,9 @@ with Files("**"):
XPCSHELL_TESTS_MANIFESTS += ["tests/unit/xpcshell.ini"]
EXTRA_JS_MODULES["services-crypto"] += [
"modules/jwcrypto.jsm",
"modules/utils.js",
"modules/WeaveCrypto.js",
"modules/jwcrypto.sys.mjs",
"modules/utils.sys.mjs",
"modules/WeaveCrypto.sys.mjs",
]
EXTRA_COMPONENTS += [