Appease linter
This commit is contained in:
parent
aea7aa953a
commit
17fc32ba51
|
@ -1,5 +1,6 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"extends": "airbnb-base",
|
"extends": "airbnb-base",
|
||||||
|
"parser": "babel-eslint",
|
||||||
"parserOptions": { "sourceType": "module" },
|
"parserOptions": { "sourceType": "module" },
|
||||||
|
|
||||||
"env": {
|
"env": {
|
||||||
|
|
31
package-lock.json
generated
31
package-lock.json
generated
|
@ -479,6 +479,20 @@
|
||||||
"js-tokens": "^3.0.2"
|
"js-tokens": "^3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"babel-eslint": {
|
||||||
|
"version": "10.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.1.0.tgz",
|
||||||
|
"integrity": "sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@babel/code-frame": "^7.0.0",
|
||||||
|
"@babel/parser": "^7.7.0",
|
||||||
|
"@babel/traverse": "^7.7.0",
|
||||||
|
"@babel/types": "^7.7.0",
|
||||||
|
"eslint-visitor-keys": "^1.0.0",
|
||||||
|
"resolve": "^1.12.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||||
|
@ -3063,6 +3077,23 @@
|
||||||
"lodash": "^4.17.14"
|
"lodash": "^4.17.14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"resolve": {
|
||||||
|
"version": "1.17.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz",
|
||||||
|
"integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"path-parse": "^1.0.6"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"path-parse": {
|
||||||
|
"version": "1.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
|
||||||
|
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"resolve-from": {
|
"resolve-from": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz",
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
"@rollup/plugin-node-resolve": "^7.1.3",
|
"@rollup/plugin-node-resolve": "^7.1.3",
|
||||||
"@rollup/plugin-replace": "^2.3.2",
|
"@rollup/plugin-replace": "^2.3.2",
|
||||||
"asmcrypto.js": "github:openpgpjs/asmcrypto#475cffa5ccb2cf2556427056679414acf3610d1b",
|
"asmcrypto.js": "github:openpgpjs/asmcrypto#475cffa5ccb2cf2556427056679414acf3610d1b",
|
||||||
|
"babel-eslint": "^10.1.0",
|
||||||
"bn.js": "^4.11.8",
|
"bn.js": "^4.11.8",
|
||||||
"buffer": "^5.0.8",
|
"buffer": "^5.0.8",
|
||||||
"chai": "^4.1.2",
|
"chai": "^4.1.2",
|
||||||
|
|
|
@ -30,55 +30,6 @@ import util from '../util';
|
||||||
// Do not use util.getNodeCrypto because we need this regardless of useNative setting
|
// Do not use util.getNodeCrypto because we need this regardless of useNative setting
|
||||||
const nodeCrypto = util.detectNode() && require('crypto');
|
const nodeCrypto = util.detectNode() && require('crypto');
|
||||||
|
|
||||||
export default {
|
|
||||||
/**
|
|
||||||
* Retrieve secure random byte array of the specified length
|
|
||||||
* @param {Integer} length Length in bytes to generate
|
|
||||||
* @returns {Uint8Array} Random byte array
|
|
||||||
* @async
|
|
||||||
*/
|
|
||||||
getRandomBytes: async function(length) {
|
|
||||||
const buf = new Uint8Array(length);
|
|
||||||
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
||||||
crypto.getRandomValues(buf);
|
|
||||||
} else if (typeof globalThis !== 'undefined' && typeof globalThis.msCrypto === 'object' && typeof globalThis.msCrypto.getRandomValues === 'function') {
|
|
||||||
globalThis.msCrypto.getRandomValues(buf);
|
|
||||||
} else if (nodeCrypto) {
|
|
||||||
const bytes = nodeCrypto.randomBytes(buf.length);
|
|
||||||
buf.set(bytes);
|
|
||||||
} else if (this.randomBuffer.buffer) {
|
|
||||||
await this.randomBuffer.get(buf);
|
|
||||||
} else {
|
|
||||||
throw new Error('No secure random number generator available.');
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a secure random MPI that is greater than or equal to min and less than max.
|
|
||||||
* @param {module:type/mpi} min Lower bound, included
|
|
||||||
* @param {module:type/mpi} max Upper bound, excluded
|
|
||||||
* @returns {module:BN} Random MPI
|
|
||||||
* @async
|
|
||||||
*/
|
|
||||||
getRandomBN: async function(min, max) {
|
|
||||||
if (max.cmp(min) <= 0) {
|
|
||||||
throw new Error('Illegal parameter value: max <= min');
|
|
||||||
}
|
|
||||||
|
|
||||||
const modulus = max.sub(min);
|
|
||||||
const bytes = modulus.byteLength();
|
|
||||||
|
|
||||||
// Using a while loop is necessary to avoid bias introduced by the mod operation.
|
|
||||||
// However, we request 64 extra random bits so that the bias is negligible.
|
|
||||||
// Section B.1.1 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
|
|
||||||
const r = new BN(await this.getRandomBytes(bytes + 8));
|
|
||||||
return r.mod(modulus).add(min);
|
|
||||||
},
|
|
||||||
|
|
||||||
randomBuffer: new RandomBuffer()
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffer for secure random numbers
|
* Buffer for secure random numbers
|
||||||
*/
|
*/
|
||||||
|
@ -145,3 +96,52 @@ class RandomBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
/**
|
||||||
|
* Retrieve secure random byte array of the specified length
|
||||||
|
* @param {Integer} length Length in bytes to generate
|
||||||
|
* @returns {Uint8Array} Random byte array
|
||||||
|
* @async
|
||||||
|
*/
|
||||||
|
getRandomBytes: async function(length) {
|
||||||
|
const buf = new Uint8Array(length);
|
||||||
|
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
||||||
|
crypto.getRandomValues(buf);
|
||||||
|
} else if (typeof globalThis !== 'undefined' && typeof globalThis.msCrypto === 'object' && typeof globalThis.msCrypto.getRandomValues === 'function') {
|
||||||
|
globalThis.msCrypto.getRandomValues(buf);
|
||||||
|
} else if (nodeCrypto) {
|
||||||
|
const bytes = nodeCrypto.randomBytes(buf.length);
|
||||||
|
buf.set(bytes);
|
||||||
|
} else if (this.randomBuffer.buffer) {
|
||||||
|
await this.randomBuffer.get(buf);
|
||||||
|
} else {
|
||||||
|
throw new Error('No secure random number generator available.');
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a secure random MPI that is greater than or equal to min and less than max.
|
||||||
|
* @param {module:type/mpi} min Lower bound, included
|
||||||
|
* @param {module:type/mpi} max Upper bound, excluded
|
||||||
|
* @returns {module:BN} Random MPI
|
||||||
|
* @async
|
||||||
|
*/
|
||||||
|
getRandomBN: async function(min, max) {
|
||||||
|
if (max.cmp(min) <= 0) {
|
||||||
|
throw new Error('Illegal parameter value: max <= min');
|
||||||
|
}
|
||||||
|
|
||||||
|
const modulus = max.sub(min);
|
||||||
|
const bytes = modulus.byteLength();
|
||||||
|
|
||||||
|
// Using a while loop is necessary to avoid bias introduced by the mod operation.
|
||||||
|
// However, we request 64 extra random bits so that the bias is negligible.
|
||||||
|
// Section B.1.1 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
|
||||||
|
const r = new BN(await this.getRandomBytes(bytes + 8));
|
||||||
|
return r.mod(modulus).add(min);
|
||||||
|
},
|
||||||
|
|
||||||
|
randomBuffer: new RandomBuffer()
|
||||||
|
};
|
||||||
|
|
|
@ -25,79 +25,6 @@
|
||||||
import { readAllArmored } from '../key';
|
import { readAllArmored } from '../key';
|
||||||
import LocalStore from './localstore';
|
import LocalStore from './localstore';
|
||||||
|
|
||||||
class Keyring {
|
|
||||||
/**
|
|
||||||
* Initialization routine for the keyring.
|
|
||||||
* @param {keyring/localstore} [storeHandler] class implementing loadPublic(), loadPrivate(), storePublic(), and storePrivate() methods
|
|
||||||
*/
|
|
||||||
constructor(storeHandler) {
|
|
||||||
this.storeHandler = storeHandler || new LocalStore();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls the storeHandler to load the keys
|
|
||||||
* @async
|
|
||||||
*/
|
|
||||||
async load() {
|
|
||||||
this.publicKeys = new KeyArray(await this.storeHandler.loadPublic());
|
|
||||||
this.privateKeys = new KeyArray(await this.storeHandler.loadPrivate());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls the storeHandler to save the keys
|
|
||||||
* @async
|
|
||||||
*/
|
|
||||||
async store() {
|
|
||||||
await Promise.all([
|
|
||||||
this.storeHandler.storePublic(this.publicKeys.keys),
|
|
||||||
this.storeHandler.storePrivate(this.privateKeys.keys)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the keyring - erase all the keys
|
|
||||||
*/
|
|
||||||
clear() {
|
|
||||||
this.publicKeys.keys = [];
|
|
||||||
this.privateKeys.keys = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches the keyring for keys having the specified key id
|
|
||||||
* @param {String} keyId provided as string of lowercase hex number
|
|
||||||
* withouth 0x prefix (can be 16-character key ID or fingerprint)
|
|
||||||
* @param {Boolean} deep if true search also in subkeys
|
|
||||||
* @returns {Array<module:key.Key>|null} keys found or null
|
|
||||||
*/
|
|
||||||
getKeysForId(keyId, deep) {
|
|
||||||
let result = [];
|
|
||||||
result = result.concat(this.publicKeys.getForId(keyId, deep) || []);
|
|
||||||
result = result.concat(this.privateKeys.getForId(keyId, deep) || []);
|
|
||||||
return result.length ? result : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes keys having the specified key id from the keyring
|
|
||||||
* @param {String} keyId provided as string of lowercase hex number
|
|
||||||
* withouth 0x prefix (can be 16-character key ID or fingerprint)
|
|
||||||
* @returns {Array<module:key.Key>|null} keys found or null
|
|
||||||
*/
|
|
||||||
removeKeysForId(keyId) {
|
|
||||||
let result = [];
|
|
||||||
result = result.concat(this.publicKeys.removeForId(keyId) || []);
|
|
||||||
result = result.concat(this.privateKeys.removeForId(keyId) || []);
|
|
||||||
return result.length ? result : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all public and private keys
|
|
||||||
* @returns {Array<module:key.Key>} all keys
|
|
||||||
*/
|
|
||||||
getAllKeys() {
|
|
||||||
return this.publicKeys.keys.concat(this.privateKeys.keys);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of keys
|
* Array of keys
|
||||||
*/
|
*/
|
||||||
|
@ -192,6 +119,79 @@ class KeyArray {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Keyring {
|
||||||
|
/**
|
||||||
|
* Initialization routine for the keyring.
|
||||||
|
* @param {keyring/localstore} [storeHandler] class implementing loadPublic(), loadPrivate(), storePublic(), and storePrivate() methods
|
||||||
|
*/
|
||||||
|
constructor(storeHandler) {
|
||||||
|
this.storeHandler = storeHandler || new LocalStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the storeHandler to load the keys
|
||||||
|
* @async
|
||||||
|
*/
|
||||||
|
async load() {
|
||||||
|
this.publicKeys = new KeyArray(await this.storeHandler.loadPublic());
|
||||||
|
this.privateKeys = new KeyArray(await this.storeHandler.loadPrivate());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the storeHandler to save the keys
|
||||||
|
* @async
|
||||||
|
*/
|
||||||
|
async store() {
|
||||||
|
await Promise.all([
|
||||||
|
this.storeHandler.storePublic(this.publicKeys.keys),
|
||||||
|
this.storeHandler.storePrivate(this.privateKeys.keys)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the keyring - erase all the keys
|
||||||
|
*/
|
||||||
|
clear() {
|
||||||
|
this.publicKeys.keys = [];
|
||||||
|
this.privateKeys.keys = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches the keyring for keys having the specified key id
|
||||||
|
* @param {String} keyId provided as string of lowercase hex number
|
||||||
|
* withouth 0x prefix (can be 16-character key ID or fingerprint)
|
||||||
|
* @param {Boolean} deep if true search also in subkeys
|
||||||
|
* @returns {Array<module:key.Key>|null} keys found or null
|
||||||
|
*/
|
||||||
|
getKeysForId(keyId, deep) {
|
||||||
|
let result = [];
|
||||||
|
result = result.concat(this.publicKeys.getForId(keyId, deep) || []);
|
||||||
|
result = result.concat(this.privateKeys.getForId(keyId, deep) || []);
|
||||||
|
return result.length ? result : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes keys having the specified key id from the keyring
|
||||||
|
* @param {String} keyId provided as string of lowercase hex number
|
||||||
|
* withouth 0x prefix (can be 16-character key ID or fingerprint)
|
||||||
|
* @returns {Array<module:key.Key>|null} keys found or null
|
||||||
|
*/
|
||||||
|
removeKeysForId(keyId) {
|
||||||
|
let result = [];
|
||||||
|
result = result.concat(this.publicKeys.removeForId(keyId) || []);
|
||||||
|
result = result.concat(this.privateKeys.removeForId(keyId) || []);
|
||||||
|
return result.length ? result : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all public and private keys
|
||||||
|
* @returns {Array<module:key.Key>} all keys
|
||||||
|
*/
|
||||||
|
getAllKeys() {
|
||||||
|
return this.publicKeys.keys.concat(this.privateKeys.keys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks a key to see if it matches the specified email address
|
* Checks a key to see if it matches the specified email address
|
||||||
* @private
|
* @private
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
// License along with this library; if not, write to the Free Software
|
// License along with this library; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
/* eslint class-methods-use-this: ["error", { "exceptMethods": ["read"] }] */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @requires enums
|
* @requires enums
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
// License along with this library; if not, write to the Free Software
|
// License along with this library; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
/* eslint class-methods-use-this: ["error", { "exceptMethods": ["isDecrypted"] }] */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @requires type/keyid
|
* @requires type/keyid
|
||||||
* @requires type/mpi
|
* @requires type/mpi
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* eslint class-methods-use-this: ["error", { "exceptMethods": ["read"] }] */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @requires enums
|
* @requires enums
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user