Finish refactoring src/**/*.js to use import & export
This commit is contained in:
parent
70ac662073
commit
8728db2b08
|
@ -39,7 +39,7 @@ import armor from './encoding/armor.js';
|
|||
* if message not yet signed
|
||||
*/
|
||||
|
||||
function CleartextMessage(text, packetlist) {
|
||||
export function CleartextMessage(text, packetlist) {
|
||||
if (!(this instanceof CleartextMessage)) {
|
||||
return new CleartextMessage(text, packetlist);
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ CleartextMessage.prototype.armor = function() {
|
|||
* @return {module:cleartext~CleartextMessage} new cleartext message object
|
||||
* @static
|
||||
*/
|
||||
function readArmored(armoredText) {
|
||||
export function readArmored(armoredText) {
|
||||
var input = armor.decode(armoredText);
|
||||
if (input.type !== enums.armor.signed) {
|
||||
throw new Error('No cleartext signed message.');
|
||||
|
@ -205,6 +205,3 @@ function verifyHeaders(headers, packetlist) {
|
|||
throw new Error('Hash algorithm mismatch in armor header and signature');
|
||||
}
|
||||
}
|
||||
|
||||
exports.CleartextMessage = CleartextMessage;
|
||||
exports.readArmored = readArmored;
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
import enums from '../enums.js';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
prefer_hash_algorithm: enums.hash.sha256,
|
||||
encryption_cipher: enums.symmetric.aes256,
|
||||
compression: enums.compression.zip,
|
||||
|
|
|
@ -2,5 +2,7 @@
|
|||
* @see module:config/config
|
||||
* @module config
|
||||
*/
|
||||
import config from './config.js';
|
||||
module.exports = config;
|
||||
|
||||
'use strict';
|
||||
|
||||
export { default } from './config.js';
|
|
@ -5,12 +5,10 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
module.exports = LocalStorage;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function LocalStorage() {}
|
||||
export default function LocalStorage() {}
|
||||
|
||||
/**
|
||||
* Reads the config out of the HTML5 local storage
|
||||
|
|
|
@ -14,7 +14,7 @@ import random from './random';
|
|||
import pkcs1 from './pkcs1';
|
||||
import crypto from './crypto.js';
|
||||
|
||||
module.exports = {
|
||||
const mod = {
|
||||
/** @see module:crypto/cipher */
|
||||
cipher: cipher,
|
||||
/** @see module:crypto/hash */
|
||||
|
@ -32,5 +32,7 @@ module.exports = {
|
|||
};
|
||||
|
||||
for (var i in crypto) {
|
||||
module.exports[i] = crypto[i];
|
||||
mod[i] = crypto[i];
|
||||
}
|
||||
|
||||
export default mod;
|
||||
|
|
|
@ -402,7 +402,7 @@ function armor(messagetype, body, partindex, parttotal) {
|
|||
return result.join('');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
encode: armor,
|
||||
decode: dearmor
|
||||
};
|
||||
|
|
|
@ -108,7 +108,7 @@ function r2s(t) {
|
|||
return new Uint8Array(r);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
encode: s2r,
|
||||
decode: r2s
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* @module enums
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
|
||||
/** A string to key specifier type
|
||||
* @enum {Integer}
|
||||
|
|
13
src/key.js
13
src/key.js
|
@ -38,7 +38,7 @@ import util from './util';
|
|||
* @param {module:packet/packetlist} packetlist The packets that form this key
|
||||
*/
|
||||
|
||||
function Key(packetlist) {
|
||||
export function Key(packetlist) {
|
||||
if (!(this instanceof Key)) {
|
||||
return new Key(packetlist);
|
||||
}
|
||||
|
@ -887,7 +887,7 @@ SubKey.prototype.update = function(subKey, primaryKey) {
|
|||
* @return {{keys: Array<module:key~Key>, err: (Array<Error>|null)}} result object with key and error arrays
|
||||
* @static
|
||||
*/
|
||||
function readArmored(armoredText) {
|
||||
export function readArmored(armoredText) {
|
||||
var result = {};
|
||||
result.keys = [];
|
||||
try {
|
||||
|
@ -931,7 +931,7 @@ function readArmored(armoredText) {
|
|||
* @return {module:key~Key}
|
||||
* @static
|
||||
*/
|
||||
function generate(options) {
|
||||
export function generate(options) {
|
||||
var packetlist, secretKeyPacket, userIdPacket, dataToSign, signaturePacket, secretSubkeyPacket, subkeySignaturePacket;
|
||||
|
||||
options.keyType = options.keyType || enums.publicKey.rsa_encrypt_sign;
|
||||
|
@ -1042,7 +1042,7 @@ function generate(options) {
|
|||
* @param {Array<module:key~Key>} keys Set of keys
|
||||
* @return {enums.symmetric} Preferred symmetric algorithm
|
||||
*/
|
||||
function getPreferredSymAlgo(keys) {
|
||||
export function getPreferredSymAlgo(keys) {
|
||||
var prioMap = {};
|
||||
keys.forEach(function(key) {
|
||||
var primaryUser = key.getPrimaryUser();
|
||||
|
@ -1069,8 +1069,3 @@ function getPreferredSymAlgo(keys) {
|
|||
}
|
||||
return prefAlgo.algo;
|
||||
}
|
||||
|
||||
exports.Key = Key;
|
||||
exports.readArmored = readArmored;
|
||||
exports.generate = generate;
|
||||
exports.getPreferredSymAlgo = getPreferredSymAlgo;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
import keyModule from '../key.js';
|
||||
import * as keyModule from '../key.js';
|
||||
import LocalStore from './localstore.js';
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
'use strict';
|
||||
|
||||
import config from '../config';
|
||||
import keyModule from '../key.js';
|
||||
import * as keyModule from '../key.js';
|
||||
import util from '../util.js';
|
||||
|
||||
export default function LocalStore(prefix) {
|
||||
|
|
|
@ -32,7 +32,7 @@ import enums from './enums.js';
|
|||
import armor from './encoding/armor.js';
|
||||
import config from './config';
|
||||
import crypto from './crypto';
|
||||
import keyModule from './key.js';
|
||||
import * as keyModule from './key.js';
|
||||
|
||||
/**
|
||||
* @class
|
||||
|
@ -42,7 +42,7 @@ import keyModule from './key.js';
|
|||
* See {@link http://tools.ietf.org/html/rfc4880#section-11.3}
|
||||
*/
|
||||
|
||||
function Message(packetlist) {
|
||||
export function Message(packetlist) {
|
||||
if (!(this instanceof Message)) {
|
||||
return new Message(packetlist);
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ Message.prototype.encrypt = function(keys, passwords) {
|
|||
* @param {(Array<String>|String)} password(s) for message encryption
|
||||
* @return {Array<module:message~Message>} new message with encrypted content
|
||||
*/
|
||||
function encryptSessionKey(sessionKey, symAlgo, keys, passwords) {
|
||||
export function encryptSessionKey(sessionKey, symAlgo, keys, passwords) {
|
||||
|
||||
/** Convert to arrays if necessary */
|
||||
if(keys && !Array.prototype.isPrototypeOf(keys)) {
|
||||
|
@ -396,7 +396,7 @@ Message.prototype.armor = function() {
|
|||
* @return {module:message~Message} new message object
|
||||
* @static
|
||||
*/
|
||||
function readArmored(armoredText) {
|
||||
export function readArmored(armoredText) {
|
||||
//TODO how do we want to handle bad text? Exception throwing
|
||||
//TODO don't accept non-message armored texts
|
||||
var input = armor.decode(armoredText).data;
|
||||
|
@ -409,7 +409,7 @@ function readArmored(armoredText) {
|
|||
* @return {module:message~Message} new message object
|
||||
* @static
|
||||
*/
|
||||
function read(input) {
|
||||
export function read(input) {
|
||||
var packetlist = new packet.List();
|
||||
packetlist.read(input);
|
||||
return new Message(packetlist);
|
||||
|
@ -420,7 +420,7 @@ function read(input) {
|
|||
* @param {String} content An 8 bit ascii string containing e.g. a MIME subtree with text nodes or attachments
|
||||
* @param {String} detachedSignature The detached ascii armored PGP signature
|
||||
*/
|
||||
function readSignedContent(content, detachedSignature) {
|
||||
export function readSignedContent(content, detachedSignature) {
|
||||
var literalDataPacket = new packet.Literal();
|
||||
literalDataPacket.setBytes(util.str2Uint8Array(content), enums.read(enums.literal, enums.literal.binary));
|
||||
var packetlist = new packet.List();
|
||||
|
@ -437,7 +437,7 @@ function readSignedContent(content, detachedSignature) {
|
|||
* @return {module:message~Message} new message object
|
||||
* @static
|
||||
*/
|
||||
function fromText(text, filename) {
|
||||
export function fromText(text, filename) {
|
||||
var literalDataPacket = new packet.Literal();
|
||||
// text will be converted to UTF8
|
||||
literalDataPacket.setText(text);
|
||||
|
@ -456,7 +456,7 @@ function fromText(text, filename) {
|
|||
* @return {module:message~Message} new message object
|
||||
* @static
|
||||
*/
|
||||
function fromBinary(bytes, filename) {
|
||||
export function fromBinary(bytes, filename) {
|
||||
if(!Uint8Array.prototype.isPrototypeOf(bytes)) {
|
||||
throw new Error('Data must be in the form of a Uint8Array');
|
||||
}
|
||||
|
@ -473,11 +473,3 @@ function fromBinary(bytes, filename) {
|
|||
literalDataPacketlist.push(literalDataPacket);
|
||||
return new Message(literalDataPacketlist);
|
||||
}
|
||||
|
||||
exports.Message = Message;
|
||||
exports.read = read;
|
||||
exports.readArmored = readArmored;
|
||||
exports.readSignedContent = readSignedContent;
|
||||
exports.fromText = fromText;
|
||||
exports.fromBinary = fromBinary;
|
||||
exports.encryptSessionKey = encryptSessionKey;
|
||||
|
|
|
@ -33,19 +33,19 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
import * as message from './message.js';
|
||||
import * as cleartext from './cleartext.js';
|
||||
import * as key from './key.js';
|
||||
import armor from './encoding/armor.js';
|
||||
import enums from './enums.js';
|
||||
import message from './message.js';
|
||||
import cleartext from './cleartext.js';
|
||||
import config from './config/config.js';
|
||||
import key from './key.js';
|
||||
import util from './util';
|
||||
import AsyncProxy from './worker/async_proxy.js';
|
||||
import es6Promise from 'es6-promise';
|
||||
|
||||
es6Promise.polyfill(); // load ES6 Promises polyfill
|
||||
|
||||
var asyncProxy = null; // instance of the asyncproxy
|
||||
let asyncProxy = null; // instance of the asyncproxy
|
||||
|
||||
/**
|
||||
* Set the path for the web worker script and create an instance of the async proxy
|
||||
|
@ -54,7 +54,7 @@ var asyncProxy = null; // instance of the asyncproxy
|
|||
* web worker initialized with 'openpgp.worker.js'
|
||||
* @return {Boolean} true if worker created successfully
|
||||
*/
|
||||
function initWorker(path, options) {
|
||||
export function initWorker(path, options) {
|
||||
if (options && options.worker || typeof window !== 'undefined' && window.Worker) {
|
||||
options = options || {};
|
||||
options.config = config;
|
||||
|
@ -69,7 +69,7 @@ function initWorker(path, options) {
|
|||
* Returns a reference to the async proxy if the worker was initialized with openpgp.initWorker()
|
||||
* @return {module:worker/async_proxy~AsyncProxy|null} the async proxy or null if not initialized
|
||||
*/
|
||||
function getWorker() {
|
||||
export function getWorker() {
|
||||
return asyncProxy;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ function getWorker() {
|
|||
* @return {Promise<String> or Promise<Packetlist>} encrypted ASCII armored message, or Packetlist if params.packets is true
|
||||
* @static
|
||||
*/
|
||||
function encryptMessage(keys, data, passwords, params) {
|
||||
export function encryptMessage(keys, data, passwords, params) {
|
||||
|
||||
if (asyncProxy) {
|
||||
return asyncProxy.encryptMessage(keys, data, passwords, params);
|
||||
|
@ -129,7 +129,7 @@ function encryptMessage(keys, data, passwords, params) {
|
|||
* @return {Promise<Packetlist>} Binary string of key packets
|
||||
* @static
|
||||
*/
|
||||
function encryptSessionKey(sessionKey, algo, keys, passwords) {
|
||||
export function encryptSessionKey(sessionKey, algo, keys, passwords) {
|
||||
|
||||
if (asyncProxy) {
|
||||
return asyncProxy.encryptSessionKey(sessionKey, algo, keys, passwords);
|
||||
|
@ -151,7 +151,7 @@ function encryptSessionKey(sessionKey, algo, keys, passwords) {
|
|||
* @return {Promise<String>} encrypted ASCII armored message
|
||||
* @static
|
||||
*/
|
||||
function signAndEncryptMessage(publicKeys, privateKey, text) {
|
||||
export function signAndEncryptMessage(publicKeys, privateKey, text) {
|
||||
if (!publicKeys.length) {
|
||||
publicKeys = [publicKeys];
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ function signAndEncryptMessage(publicKeys, privateKey, text) {
|
|||
* or null if no literal data found
|
||||
* @static
|
||||
*/
|
||||
function decryptMessage(privateKey, msg, params) {
|
||||
export function decryptMessage(privateKey, msg, params) {
|
||||
if (asyncProxy) {
|
||||
return asyncProxy.decryptMessage(privateKey, msg, params);
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ function decryptMessage(privateKey, msg, params) {
|
|||
* or null if no key packets found
|
||||
* @static
|
||||
*/
|
||||
function decryptSessionKey(privateKey, msg) {
|
||||
export function decryptSessionKey(privateKey, msg) {
|
||||
if (asyncProxy) {
|
||||
return asyncProxy.decryptSessionKey(privateKey, msg);
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ function decryptSessionKey(privateKey, msg) {
|
|||
* with verified signatures or null if no literal data found
|
||||
* @static
|
||||
*/
|
||||
function decryptAndVerifyMessage(privateKey, publicKeys, msg) {
|
||||
export function decryptAndVerifyMessage(privateKey, publicKeys, msg) {
|
||||
if (!publicKeys.length) {
|
||||
publicKeys = [publicKeys];
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ function decryptAndVerifyMessage(privateKey, publicKeys, msg) {
|
|||
* @return {Promise<String>} ASCII armored message
|
||||
* @static
|
||||
*/
|
||||
function signClearMessage(privateKeys, text) {
|
||||
export function signClearMessage(privateKeys, text) {
|
||||
if (!privateKeys.length) {
|
||||
privateKeys = [privateKeys];
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ function signClearMessage(privateKeys, text) {
|
|||
* cleartext with status of verified signatures
|
||||
* @static
|
||||
*/
|
||||
function verifyClearSignedMessage(publicKeys, msg) {
|
||||
export function verifyClearSignedMessage(publicKeys, msg) {
|
||||
if (!publicKeys.length) {
|
||||
publicKeys = [publicKeys];
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ function verifyClearSignedMessage(publicKeys, msg) {
|
|||
* @return {Promise<Object>} {key: module:key~Key, privateKeyArmored: String, publicKeyArmored: String}
|
||||
* @static
|
||||
*/
|
||||
function generateKeyPair(options) {
|
||||
export function generateKeyPair(options) {
|
||||
// use web worker if web crypto apis are not supported
|
||||
if (!util.getWebCrypto() && asyncProxy) {
|
||||
return asyncProxy.generateKeyPair(options);
|
||||
|
@ -389,15 +389,3 @@ function onError(message, error) {
|
|||
// rethrow new high level error for api users
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
exports.initWorker = initWorker;
|
||||
exports.getWorker = getWorker;
|
||||
exports.encryptMessage = encryptMessage;
|
||||
exports.encryptSessionKey = encryptSessionKey;
|
||||
exports.signAndEncryptMessage = signAndEncryptMessage;
|
||||
exports.decryptMessage = decryptMessage;
|
||||
exports.decryptSessionKey = decryptSessionKey;
|
||||
exports.decryptAndVerifyMessage = decryptAndVerifyMessage;
|
||||
exports.signClearMessage = signClearMessage;
|
||||
exports.verifyClearSignedMessage = verifyClearSignedMessage;
|
||||
exports.generateKeyPair = generateKeyPair;
|
|
@ -30,12 +30,10 @@
|
|||
|
||||
import util from '../util.js';
|
||||
|
||||
module.exports = Keyid;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function Keyid() {
|
||||
export default function Keyid() {
|
||||
this.bytes = '';
|
||||
}
|
||||
|
||||
|
@ -63,17 +61,17 @@ Keyid.prototype.isNull = function() {
|
|||
return this.bytes === '';
|
||||
};
|
||||
|
||||
module.exports.mapToHex = function (keyId) {
|
||||
Keyid.mapToHex = function (keyId) {
|
||||
return keyId.toHex();
|
||||
};
|
||||
|
||||
module.exports.fromClone = function (clone) {
|
||||
Keyid.fromClone = function (clone) {
|
||||
var keyid = new Keyid();
|
||||
keyid.bytes = clone.bytes;
|
||||
return keyid;
|
||||
};
|
||||
|
||||
module.exports.fromId = function (hex) {
|
||||
Keyid.fromId = function (hex) {
|
||||
var keyid = new Keyid();
|
||||
keyid.read(util.hex2bin(hex));
|
||||
return keyid;
|
||||
|
|
|
@ -39,12 +39,10 @@
|
|||
import BigInteger from '../crypto/public_key/jsbn.js';
|
||||
import util from '../util.js';
|
||||
|
||||
module.exports = MPI;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function MPI() {
|
||||
export default function MPI() {
|
||||
/** An implementation dependent integer */
|
||||
this.data = null;
|
||||
}
|
||||
|
@ -109,7 +107,7 @@ MPI.prototype.fromBigInteger = function (bn) {
|
|||
this.data = bn.clone();
|
||||
};
|
||||
|
||||
module.exports.fromClone = function (clone) {
|
||||
MPI.fromClone = function (clone) {
|
||||
clone.data.copyTo = BigInteger.prototype.copyTo;
|
||||
var bn = new BigInteger();
|
||||
clone.data.copyTo(bn);
|
||||
|
|
|
@ -35,12 +35,10 @@ import enums from '../enums.js';
|
|||
import util from '../util.js';
|
||||
import crypto from '../crypto';
|
||||
|
||||
module.exports = S2K;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function S2K() {
|
||||
export default function S2K() {
|
||||
/** @type {module:enums.hash} */
|
||||
this.algorithm = 'sha256';
|
||||
/** @type {module:enums.s2k} */
|
||||
|
@ -201,7 +199,7 @@ S2K.prototype.produce_key = function (passphrase, numBytes) {
|
|||
return util.concatUint8Array(arr).subarray(0, numBytes);
|
||||
};
|
||||
|
||||
module.exports.fromClone = function (clone) {
|
||||
S2K.fromClone = function (clone) {
|
||||
var s2k = new S2K();
|
||||
s2k.algorithm = clone.algorithm;
|
||||
s2k.type = clone.type;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
import config from './config';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
readNumber: function (bytes) {
|
||||
var n = 0;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
import crypto from '../crypto';
|
||||
import packet from '../packet';
|
||||
import key from '../key.js';
|
||||
import * as key from '../key.js';
|
||||
import type_keyid from '../type/keyid.js';
|
||||
|
||||
var INITIAL_RANDOM_SEED = 50000, // random bytes seeded to worker
|
||||
|
|
Loading…
Reference in New Issue
Block a user