JSdoc types & ESLint fixes (#1132)

This commit is contained in:
Dan Ristea 2020-08-05 17:34:32 +01:00 committed by Daniel Huigens
parent f6ee6e959e
commit 10aa1aa5cb
15 changed files with 655 additions and 655 deletions

View File

@ -156,7 +156,7 @@ export default {
/** Returns the types comprising the private key of an algorithm /** Returns the types comprising the private key of an algorithm
* @param {module:enums.publicKey} algo The public key algorithm * @param {module:enums.publicKey} algo The public key algorithm
* @returns {Array<String>} The array of types * @returns {Array<Object>} The array of types
*/ */
getPrivKeyParamTypes: function(algo) { getPrivKeyParamTypes: function(algo) {
switch (algo) { switch (algo) {
@ -190,7 +190,7 @@ export default {
/** Returns the types comprising the public key of an algorithm /** Returns the types comprising the public key of an algorithm
* @param {module:enums.publicKey} algo The public key algorithm * @param {module:enums.publicKey} algo The public key algorithm
* @returns {Array<String>} The array of types * @returns {Array<Object>} The array of types
*/ */
getPubKeyParamTypes: function(algo) { getPubKeyParamTypes: function(algo) {
switch (algo) { switch (algo) {
@ -233,7 +233,7 @@ export default {
/** Returns the types comprising the encrypted session key of an algorithm /** Returns the types comprising the encrypted session key of an algorithm
* @param {module:enums.publicKey} algo The public key algorithm * @param {module:enums.publicKey} algo The public key algorithm
* @returns {Array<String>} The array of types * @returns {Array<Object>} The array of types
*/ */
getEncSessionKeyParamTypes: function(algo) { getEncSessionKeyParamTypes: function(algo) {
switch (algo) { switch (algo) {
@ -303,7 +303,7 @@ export default {
* Validate algorithm-specific key parameters * Validate algorithm-specific key parameters
* @param {module:enums.publicKey} algo The public key algorithm * @param {module:enums.publicKey} algo The public key algorithm
* @param {Array} params The array of parameters * @param {Array} params The array of parameters
* @returns {Promise<Boolean> whether the parameters are valid * @returns {Promise<Boolean>} whether the parameters are valid
* @async * @async
*/ */
validateParams: async function(algo, params) { validateParams: async function(algo, params) {

View File

@ -103,7 +103,7 @@ async function verify(oid, hash_algo, signature, message, publicKey, hashed) {
return await webVerify(curve, hash_algo, signature, message, publicKey); return await webVerify(curve, hash_algo, signature, message, publicKey);
} catch (err) { } catch (err) {
// We do not fallback if the error is related to key integrity // We do not fallback if the error is related to key integrity
// Unfortunaley Safari does not support p521 and throws a DataError when using it // Unfortunately Safari does not support p521 and throws a DataError when using it
// So we need to always fallback for that curve // So we need to always fallback for that curve
if (curve.name !== 'p521' && (err.name === 'DataError' || err.name === 'OperationError')) { if (curve.name !== 'p521' && (err.name === 'DataError' || err.name === 'OperationError')) {
throw err; throw err;

View File

@ -48,9 +48,9 @@ import armor from '../encoding/armor';
* @param {String} options.passphrase The passphrase used to encrypt the resulting private key * @param {String} options.passphrase The passphrase used to encrypt the resulting private key
* @param {Number} [options.keyExpirationTime=0] * @param {Number} [options.keyExpirationTime=0]
* The number of seconds after the key creation time that the key expires * The number of seconds after the key creation time that the key expires
* @param {String} curve (optional) elliptic curve for ECC keys * @param {String} options.curve (optional) elliptic curve for ECC keys
* @param {Date} date Override the creation date of the key and the key signatures * @param {Date} options.date Override the creation date of the key and the key signatures
* @param {Array<Object>} subkeys (optional) options for each subkey, default to main key options. e.g. [{sign: true, passphrase: '123'}] * @param {Array<Object>} options.subkeys (optional) options for each subkey, default to main key options. e.g. [{sign: true, passphrase: '123'}]
* sign parameter defaults to false, and indicates whether the subkey should sign rather than encrypt * sign parameter defaults to false, and indicates whether the subkey should sign rather than encrypt
* @returns {Promise<module:key.Key>} * @returns {Promise<module:key.Key>}
* @async * @async
@ -76,8 +76,8 @@ export async function generate(options) {
* @param {String} options.passphrase The passphrase used to encrypt the resulting private key * @param {String} options.passphrase The passphrase used to encrypt the resulting private key
* @param {Number} [options.keyExpirationTime=0] * @param {Number} [options.keyExpirationTime=0]
* The number of seconds after the key creation time that the key expires * The number of seconds after the key creation time that the key expires
* @param {Date} date Override the creation date of the key and the key signatures * @param {Date} options.date Override the creation date of the key and the key signatures
* @param {Array<Object>} subkeys (optional) options for each subkey, default to main key options. e.g. [{sign: true, passphrase: '123'}] * @param {Array<Object>} options.subkeys (optional) options for each subkey, default to main key options. e.g. [{sign: true, passphrase: '123'}]
* *
* @returns {Promise<module:key.Key>} * @returns {Promise<module:key.Key>}
* @async * @async

View File

@ -794,7 +794,7 @@ class Key {
/** /**
* Signs primary user of key * Signs primary user of key
* @param {Array<module:key.Key>} privateKey decrypted private keys for signing * @param {Array<module:key.Key>} privateKeys decrypted private keys for signing
* @param {Date} date (optional) use the given date for verification instead of the current time * @param {Date} date (optional) use the given date for verification instead of the current time
* @param {Object} userId (optional) user ID to get instead of the primary user, if it exists * @param {Object} userId (optional) user ID to get instead of the primary user, if it exists
* @returns {Promise<module:key.Key>} new public key with new certificate signature * @returns {Promise<module:key.Key>} new public key with new certificate signature
@ -875,9 +875,9 @@ class Key {
* @param {Integer} options.rsaBits number of bits for the key creation. * @param {Integer} options.rsaBits number of bits for the key creation.
* @param {Number} [options.keyExpirationTime=0] * @param {Number} [options.keyExpirationTime=0]
* The number of seconds after the key creation time that the key expires * The number of seconds after the key creation time that the key expires
* @param {String} curve (optional) Elliptic curve for ECC keys * @param {String} options.curve (optional) Elliptic curve for ECC keys
* @param {Date} date (optional) Override the creation date of the key and the key signatures * @param {Date} options.date (optional) Override the creation date of the key and the key signatures
* @param {Boolean} sign (optional) Indicates whether the subkey should sign rather than encrypt. Defaults to false * @param {Boolean} options.sign (optional) Indicates whether the subkey should sign rather than encrypt. Defaults to false
* @returns {Promise<module:key.Key>} * @returns {Promise<module:key.Key>}
* @async * @async
*/ */

View File

@ -30,7 +30,7 @@ class SubKey {
/** /**
* Transforms structured subkey data to packetlist * Transforms structured subkey data to packetlist
* @returns {PacketListPacket} * @returns {PacketList}
*/ */
toPacketlist() { toPacketlist() {
const packetlist = new PacketList(); const packetlist = new PacketList();

View File

@ -24,8 +24,8 @@ import util from '../util';
*/ */
class PacketList extends Array { class PacketList extends Array {
/** /**
* Reads a stream of binary data and interprents it as a list of packets. * Reads a stream of binary data and interprets it as a list of packets.
* @param {Uint8Array | ReadableStream<Uint8Array>} A Uint8Array of bytes. * @param {Uint8Array | ReadableStream<Uint8Array>} bytes A Uint8Array of bytes.
*/ */
async read(bytes, allowedPackets, streaming) { async read(bytes, allowedPackets, streaming) {
this.stream = stream.transformPair(bytes, async (readable, writable) => { this.stream = stream.transformPair(bytes, async (readable, writable) => {

View File

@ -161,7 +161,7 @@ class SecretKeyPacket extends PublicKeyPacket {
/** /**
* Creates an OpenPGP key packet for the given key. * Creates an OpenPGP key packet for the given key.
* @returns {String} A string of bytes containing the secret key OpenPGP packet * @returns {Uint8Array} A string of bytes containing the secret key OpenPGP packet
*/ */
write() { write() {
const arr = [this.writePublicKey()]; const arr = [this.writePublicKey()];

View File

@ -36,7 +36,7 @@ class Keyid {
/** /**
* Parsing method for a key id * Parsing method for a key id
* @param {Uint8Array} input Input to read the key id from * @param {Uint8Array} bytes Input to read the key id from
*/ */
read(bytes) { read(bytes) {
this.bytes = util.uint8ArrayToStr(bytes.subarray(0, 8)); this.bytes = util.uint8ArrayToStr(bytes.subarray(0, 8));

View File

@ -54,8 +54,8 @@ class MPI {
/** /**
* Parsing function for a MPI ({@link https://tools.ietf.org/html/rfc4880#section-3.2|RFC 4880 3.2}). * Parsing function for a MPI ({@link https://tools.ietf.org/html/rfc4880#section-3.2|RFC 4880 3.2}).
* @param {Uint8Array} input Payload of MPI data * @param {Uint8Array|string} bytes Payload of MPI data
* @param {String} endian Endianness of the data; 'be' for big-endian or 'le' for little-endian * @param {'be'|'le'} endian Endianness of the data; 'be' for big-endian or 'le' for little-endian
* @returns {Integer} Length of data read * @returns {Integer} Length of data read
*/ */
read(bytes, endian = 'be') { read(bytes, endian = 'be') {

View File

@ -59,7 +59,7 @@ class S2K {
/** /**
* Parsing function for a string-to-key specifier ({@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}). * Parsing function for a string-to-key specifier ({@link https://tools.ietf.org/html/rfc4880#section-3.7|RFC 4880 3.7}).
* @param {String} input Payload of string-to-key specifier * @param {String} bytes Payload of string-to-key specifier
* @returns {Integer} Actual length of the object * @returns {Integer} Actual length of the object
*/ */
read(bytes) { read(bytes) {

View File

@ -307,8 +307,8 @@ export default {
/** /**
* Check Uint8Array equality * Check Uint8Array equality
* @param {Uint8Array} first array * @param {Uint8Array} array1 first array
* @param {Uint8Array} second array * @param {Uint8Array} array2 second array
* @returns {Boolean} equality * @returns {Boolean} equality
*/ */
equalsUint8Array: function (array1, array2) { equalsUint8Array: function (array1, array2) {

View File

@ -2533,7 +2533,7 @@ module.exports = () => describe('Key', function() {
let rsaGenStub; let rsaGenStub;
let v5KeysVal; let v5KeysVal;
let aeadProtectVal; let aeadProtectVal;
let rsaGenValue = { const rsaGenValue = {
512: openpgp.crypto.publicKey.rsa.generate(512, "10001"), 512: openpgp.crypto.publicKey.rsa.generate(512, "10001"),
1024: openpgp.crypto.publicKey.rsa.generate(1024, "10001"), 1024: openpgp.crypto.publicKey.rsa.generate(1024, "10001"),
2048: openpgp.crypto.publicKey.rsa.generate(2048, "10001") 2048: openpgp.crypto.publicKey.rsa.generate(2048, "10001")
@ -2602,16 +2602,16 @@ module.exports = () => describe('Key', function() {
it('Parsing V5 public key packet', async function() { it('Parsing V5 public key packet', async function() {
// Manually modified from https://gitlab.com/openpgp-wg/rfc4880bis/blob/00b2092/back.mkd#sample-eddsa-key // Manually modified from https://gitlab.com/openpgp-wg/rfc4880bis/blob/00b2092/back.mkd#sample-eddsa-key
let packetBytes = openpgp.util.hexToUint8Array(` const packetBytes = openpgp.util.hexToUint8Array(`
98 37 05 53 f3 5f 0b 16 00 00 00 2d 09 2b 06 01 04 01 da 47 98 37 05 53 f3 5f 0b 16 00 00 00 2d 09 2b 06 01 04 01 da 47
0f 01 01 07 40 3f 09 89 94 bd d9 16 ed 40 53 19 0f 01 01 07 40 3f 09 89 94 bd d9 16 ed 40 53 19
79 34 e4 a8 7c 80 73 3a 12 80 d6 2f 80 10 99 2e 79 34 e4 a8 7c 80 73 3a 12 80 d6 2f 80 10 99 2e
43 ee 3b 24 06 43 ee 3b 24 06
`.replace(/\s+/g, '')); `.replace(/\s+/g, ''));
let packetlist = new openpgp.PacketList(); const packetlist = new openpgp.PacketList();
await packetlist.read(packetBytes, { PublicKeyPacket: openpgp.PublicKeyPacket }); await packetlist.read(packetBytes, { PublicKeyPacket: openpgp.PublicKeyPacket });
let key = packetlist[0]; const key = packetlist[0];
expect(key).to.exist; expect(key).to.exist;
}); });
@ -2774,7 +2774,7 @@ module.exports = () => describe('Key', function() {
it("decrypt(keyId) - throw if key parameters don't correspond", async function() { it("decrypt(keyId) - throw if key parameters don't correspond", async function() {
const key = await openpgp.key.readArmored(mismatchingKeyParams); const key = await openpgp.key.readArmored(mismatchingKeyParams);
const subKeyId = key.subKeys[0].getKeyId() const subKeyId = key.subKeys[0].getKeyId();
await expect(key.decrypt('userpass', subKeyId)).to.be.rejectedWith('Key is invalid'); await expect(key.decrypt('userpass', subKeyId)).to.be.rejectedWith('Key is invalid');
}); });
@ -3179,7 +3179,7 @@ VYGdb3eNlV8CfoEC
}); });
it('Generate session key - latest created user', async function() { it('Generate session key - latest created user', async function() {
let publicKey = await openpgp.key.readArmored(multi_uid_key); const publicKey = await openpgp.key.readArmored(multi_uid_key);
const privateKey = await openpgp.key.readArmored(priv_key_rsa); const privateKey = await openpgp.key.readArmored(priv_key_rsa);
await privateKey.decrypt('hello world'); await privateKey.decrypt('hello world');
// Set second user to prefer aes128. We should select this user by default, since it was created later. // Set second user to prefer aes128. We should select this user by default, since it was created later.
@ -3189,7 +3189,7 @@ VYGdb3eNlV8CfoEC
}); });
it('Generate session key - primary user', async function() { it('Generate session key - primary user', async function() {
let publicKey = await openpgp.key.readArmored(multi_uid_key); const publicKey = await openpgp.key.readArmored(multi_uid_key);
const privateKey = await openpgp.key.readArmored(priv_key_rsa); const privateKey = await openpgp.key.readArmored(priv_key_rsa);
await privateKey.decrypt('hello world'); await privateKey.decrypt('hello world');
// Set first user to primary. We should select this user by default. // Set first user to primary. We should select this user by default.
@ -3201,7 +3201,7 @@ VYGdb3eNlV8CfoEC
}); });
it('Generate session key - specific user', async function() { it('Generate session key - specific user', async function() {
let publicKey = await openpgp.key.readArmored(multi_uid_key); const publicKey = await openpgp.key.readArmored(multi_uid_key);
const privateKey = await openpgp.key.readArmored(priv_key_rsa); const privateKey = await openpgp.key.readArmored(priv_key_rsa);
await privateKey.decrypt('hello world'); await privateKey.decrypt('hello world');
// Set first user to primary. We won't select this user, this is to test that. // Set first user to primary. We won't select this user, this is to test that.
@ -3215,7 +3215,7 @@ VYGdb3eNlV8CfoEC
}); });
it('Sign - specific user', async function() { it('Sign - specific user', async function() {
let publicKey = await openpgp.key.readArmored(multi_uid_key); const publicKey = await openpgp.key.readArmored(multi_uid_key);
const privateKey = await openpgp.key.readArmored(priv_key_rsa); const privateKey = await openpgp.key.readArmored(priv_key_rsa);
await privateKey.decrypt('hello world'); await privateKey.decrypt('hello world');
const privateKeyClone = await openpgp.key.readArmored(priv_key_rsa); const privateKeyClone = await openpgp.key.readArmored(priv_key_rsa);
@ -3311,8 +3311,8 @@ VYGdb3eNlV8CfoEC
it("Should throw when trying to encrypt a key that's already encrypted", async function() { it("Should throw when trying to encrypt a key that's already encrypted", async function() {
await expect((async function() { await expect((async function() {
let { privateKeyArmored } = await openpgp.generateKey({ userIds: [{ email: 'hello@user.com' }], passphrase: 'pass' }); const { privateKeyArmored } = await openpgp.generateKey({ userIds: [{ email: 'hello@user.com' }], passphrase: 'pass' });
let k = await openpgp.key.readArmored(privateKeyArmored); const k = await openpgp.key.readArmored(privateKeyArmored);
await k.decrypt('pass'); await k.decrypt('pass');
await k.encrypt('pass'); await k.encrypt('pass');
await k.encrypt('pass'); await k.encrypt('pass');
@ -3359,7 +3359,7 @@ VYGdb3eNlV8CfoEC
newPrivateKey = await openpgp.key.readArmored(newPrivateKey.armor()); newPrivateKey = await openpgp.key.readArmored(newPrivateKey.armor());
await newPrivateKey.encrypt('12345678'); await newPrivateKey.encrypt('12345678');
const armoredKey = newPrivateKey.armor(); const armoredKey = newPrivateKey.armor();
let importedPrivateKey = await openpgp.key.readArmored(armoredKey); const importedPrivateKey = await openpgp.key.readArmored(armoredKey);
await importedPrivateKey.decrypt('12345678'); await importedPrivateKey.decrypt('12345678');
const subKey = importedPrivateKey.subKeys[total]; const subKey = importedPrivateKey.subKeys[total];
expect(subKey).to.exist; expect(subKey).to.exist;
@ -3452,7 +3452,7 @@ VYGdb3eNlV8CfoEC
expect(pkSessionKeys).to.exist; expect(pkSessionKeys).to.exist;
expect(pkSessionKeys.length).to.be.equal(1); expect(pkSessionKeys.length).to.be.equal(1);
expect(pkSessionKeys[0].publicKeyId.toHex()).to.be.equals(subKey.keyPacket.getKeyId().toHex()); expect(pkSessionKeys[0].publicKeyId.toHex()).to.be.equals(subKey.keyPacket.getKeyId().toHex());
const decrypted = await openpgp.decrypt({message, privateKeys: newPrivateKey}) const decrypted = await openpgp.decrypt({ message, privateKeys: newPrivateKey });
expect(decrypted).to.exist; expect(decrypted).to.exist;
expect(decrypted.data).to.be.equal(vData); expect(decrypted.data).to.be.equal(vData);
}); });
@ -3496,7 +3496,7 @@ VYGdb3eNlV8CfoEC
expect(pkSessionKeys).to.exist; expect(pkSessionKeys).to.exist;
expect(pkSessionKeys.length).to.be.equal(1); expect(pkSessionKeys.length).to.be.equal(1);
expect(pkSessionKeys[0].publicKeyId.toHex()).to.be.equals(subKey.keyPacket.getKeyId().toHex()); expect(pkSessionKeys[0].publicKeyId.toHex()).to.be.equals(subKey.keyPacket.getKeyId().toHex());
const decrypted = await openpgp.decrypt({message, privateKeys: newPrivateKey}) const decrypted = await openpgp.decrypt({ message, privateKeys: newPrivateKey });
expect(decrypted).to.exist; expect(decrypted).to.exist;
expect(decrypted.data).to.be.equal(vData); expect(decrypted.data).to.be.equal(vData);
}); });