Skip to content

Commit

Permalink
Lint: enforce single quotes and do not error on class methods without…
Browse files Browse the repository at this point in the history
… `this` (#1341)
  • Loading branch information
larabr committed Jun 24, 2021
1 parent d238a02 commit ab22fe8
Show file tree
Hide file tree
Showing 43 changed files with 333 additions and 344 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Expand Up @@ -72,7 +72,7 @@ module.exports = {
}
],
"capitalized-comments": "off",
"class-methods-use-this": "error",
"class-methods-use-this": "off",
"comma-dangle": [ "error", "never" ],
"comma-spacing": "off",
"comma-style": [
Expand Down Expand Up @@ -278,7 +278,7 @@ module.exports = {
"prefer-spread": "off",
"prefer-template": "off",
"quote-props": "off",
"quotes": "off",
"quotes": ["error", "single", { "avoidEscape": true }],
"require-await": "error",
"require-jsdoc": "off",
"semi-spacing": [
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Expand Up @@ -5,7 +5,7 @@ import { builtinModules } from 'module';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import { terser } from "rollup-plugin-terser";
import { terser } from 'rollup-plugin-terser';

import pkg from './package.json';

Expand All @@ -16,7 +16,7 @@ const banner =
`${new Date().toISOString().split('T')[0]} - ` +
`this is LGPL licensed code, see LICENSE/our website ${pkg.homepage} for more information. */`;

const intro = `const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};`;
const intro = "const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};";

const terserOptions = {
ecma: 2017,
Expand Down
4 changes: 2 additions & 2 deletions src/biginteger/native.interface.js
Expand Up @@ -155,9 +155,9 @@ export default class BigInteger {
* @returns {BigInteger} this ** e mod n.
*/
modExp(e, n) {
if (n.isZero()) throw Error("Modulo cannot be zero");
if (n.isZero()) throw Error('Modulo cannot be zero');
if (n.isOne()) return new BigInteger(0);
if (e.isNegative()) throw Error("Unsopported negative exponent");
if (e.isNegative()) throw Error('Unsopported negative exponent');

let exp = e.value;
let x = this.value;
Expand Down
6 changes: 3 additions & 3 deletions src/config/config.js
Expand Up @@ -154,12 +154,12 @@ export default {
* @memberof module:config
* @property {String} versionString A version string to be included in armored messages
*/
versionString: "OpenPGP.js VERSION",
versionString: 'OpenPGP.js VERSION',
/**
* @memberof module:config
* @property {String} commentString A comment string to be included in armored messages
*/
commentString: "https://openpgpjs.org",
commentString: 'https://openpgpjs.org',

/**
* Max userID string length (used for parsing)
Expand All @@ -173,7 +173,7 @@ export default {
* @memberof module:config
* @property {Array} knownNotations
*/
knownNotations: ["preferred-email-encoding@pgp.com", "pka-address@gnupg.org"],
knownNotations: ['preferred-email-encoding@pgp.com', 'pka-address@gnupg.org'],
/**
* @memberof module:config
* @property {Boolean} useIndutnyElliptic Whether to use the indutny/elliptic library. When false, certain curves will not be supported.
Expand Down
6 changes: 3 additions & 3 deletions src/crypto/aes_kw.js
Expand Up @@ -33,7 +33,7 @@ import util from '../util';
* @returns {Uint8Array}
*/
export function wrap(key, data) {
const aes = new cipher["aes" + (key.length * 8)](key);
const aes = new cipher['aes' + (key.length * 8)](key);
const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]);
const P = unpack(data);
let A = IV;
Expand Down Expand Up @@ -73,7 +73,7 @@ export function wrap(key, data) {
* @throws {Error}
*/
export function unwrap(key, data) {
const aes = new cipher["aes" + (key.length * 8)](key);
const aes = new cipher['aes' + (key.length * 8)](key);
const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]);
const C = unpack(data);
let A = C.subarray(0, 2);
Expand Down Expand Up @@ -102,7 +102,7 @@ export function unwrap(key, data) {
if (A[0] === IV[0] && A[1] === IV[1]) {
return pack(R);
}
throw new Error("Key Data Integrity failed");
throw new Error('Key Data Integrity failed');
}

function createArrayBuffer(data) {
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/cipher/des.js
Expand Up @@ -384,7 +384,7 @@ function desAddPadding(message, padding) {

let pad;
if (padding === 2 && (padLength < 8)) { //pad the message with spaces
pad = " ".charCodeAt(0);
pad = ' '.charCodeAt(0);
} else if (padding === 1) { //PKCS7 padding
pad = padLength;
} else if (!padding && (padLength < 8)) { //pad the message out with null bytes
Expand All @@ -410,7 +410,7 @@ function desRemovePadding(message, padding) {
let padLength = null;
let pad;
if (padding === 2) { // space padded
pad = " ".charCodeAt(0);
pad = ' '.charCodeAt(0);
} else if (padding === 1) { // PKCS7
padLength = message[message.length - 1];
} else if (!padding) { // null padding
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/cipher/twofish.js
Expand Up @@ -318,7 +318,7 @@ function createTwofish() {
}

return {
name: "twofish",
name: 'twofish',
blocksize: 128 / 8,
open: tfsInit,
close: tfsClose,
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/public_key/dsa.js
Expand Up @@ -113,13 +113,13 @@ export async function verify(hashAlgo, r, s, hashed, g, p, q, y) {

if (r.lte(zero) || r.gte(q) ||
s.lte(zero) || s.gte(q)) {
util.printDebug("invalid DSA Signature");
util.printDebug('invalid DSA Signature');
return false;
}
const h = new BigInteger(hashed.subarray(0, q.byteLength())).imod(q);
const w = s.modInv(q); // s**-1 mod q
if (w.isZero()) {
util.printDebug("invalid DSA Signature");
util.printDebug('invalid DSA Signature');
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions src/crypto/public_key/elliptic/curves.js
Expand Up @@ -175,7 +175,7 @@ class Curve {
try {
return await webGenKeyPair(this.name);
} catch (err) {
util.printDebugError("Browser did not support generating ec key " + err.message);
util.printDebugError('Browser did not support generating ec key ' + err.message);
break;
}
case 'node':
Expand Down Expand Up @@ -299,10 +299,10 @@ export {

async function webGenKeyPair(name) {
// Note: keys generated with ECDSA and ECDH are structurally equivalent
const webCryptoKey = await webCrypto.generateKey({ name: "ECDSA", namedCurve: webCurves[name] }, true, ["sign", "verify"]);
const webCryptoKey = await webCrypto.generateKey({ name: 'ECDSA', namedCurve: webCurves[name] }, true, ['sign', 'verify']);

const privateKey = await webCrypto.exportKey("jwk", webCryptoKey.privateKey);
const publicKey = await webCrypto.exportKey("jwk", webCryptoKey.publicKey);
const privateKey = await webCrypto.exportKey('jwk', webCryptoKey.privateKey);
const publicKey = await webCrypto.exportKey('jwk', webCryptoKey.publicKey);

return {
publicKey: jwkToRawPublic(publicKey),
Expand Down Expand Up @@ -354,7 +354,7 @@ function rawPublicToJWK(payloadSize, name, publicKey) {
const bufY = publicKey.slice(len + 1, len * 2 + 1);
// https://www.rfc-editor.org/rfc/rfc7518.txt
const jwk = {
kty: "EC",
kty: 'EC',
crv: name,
x: uint8ArrayToB64(bufX, true),
y: uint8ArrayToB64(bufY, true),
Expand Down
28 changes: 14 additions & 14 deletions src/crypto/public_key/elliptic/ecdh.js
Expand Up @@ -54,7 +54,7 @@ function buildEcdhParam(public_algo, oid, kdfParams, fingerprint) {
oid.write(),
new Uint8Array([public_algo]),
kdfParams.write(),
util.stringToUint8Array("Anonymous Sender "),
util.stringToUint8Array('Anonymous Sender '),
fingerprint.subarray(0, 20)
]);
}
Expand Down Expand Up @@ -219,21 +219,21 @@ export async function decrypt(oid, kdfParams, V, C, Q, d, fingerprint) {
async function webPrivateEphemeralKey(curve, V, Q, d) {
const recipient = privateToJWK(curve.payloadSize, curve.web.web, Q, d);
let privateKey = webCrypto.importKey(
"jwk",
'jwk',
recipient,
{
name: "ECDH",
name: 'ECDH',
namedCurve: curve.web.web
},
true,
["deriveKey", "deriveBits"]
['deriveKey', 'deriveBits']
);
const jwk = rawPublicToJWK(curve.payloadSize, curve.web.web, V);
let sender = webCrypto.importKey(
"jwk",
'jwk',
jwk,
{
name: "ECDH",
name: 'ECDH',
namedCurve: curve.web.web
},
true,
Expand All @@ -242,15 +242,15 @@ async function webPrivateEphemeralKey(curve, V, Q, d) {
[privateKey, sender] = await Promise.all([privateKey, sender]);
let S = webCrypto.deriveBits(
{
name: "ECDH",
name: 'ECDH',
namedCurve: curve.web.web,
public: sender
},
privateKey,
curve.web.sharedSize
);
let secret = webCrypto.exportKey(
"jwk",
'jwk',
privateKey
);
[S, secret] = await Promise.all([S, secret]);
Expand All @@ -271,17 +271,17 @@ async function webPublicEphemeralKey(curve, Q) {
const jwk = rawPublicToJWK(curve.payloadSize, curve.web.web, Q);
let keyPair = webCrypto.generateKey(
{
name: "ECDH",
name: 'ECDH',
namedCurve: curve.web.web
},
true,
["deriveKey", "deriveBits"]
['deriveKey', 'deriveBits']
);
let recipient = webCrypto.importKey(
"jwk",
'jwk',
jwk,
{
name: "ECDH",
name: 'ECDH',
namedCurve: curve.web.web
},
false,
Expand All @@ -290,15 +290,15 @@ async function webPublicEphemeralKey(curve, Q) {
[keyPair, recipient] = await Promise.all([keyPair, recipient]);
let s = webCrypto.deriveBits(
{
name: "ECDH",
name: 'ECDH',
namedCurve: curve.web.web,
public: recipient
},
keyPair.privateKey,
curve.web.sharedSize
);
let p = webCrypto.exportKey(
"jwk",
'jwk',
keyPair.publicKey
);
[s, p] = await Promise.all([s, p]);
Expand Down
36 changes: 18 additions & 18 deletions src/crypto/public_key/elliptic/ecdsa.js
Expand Up @@ -62,7 +62,7 @@ export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed
if (curve.name !== 'p521' && (err.name === 'DataError' || err.name === 'OperationError')) {
throw err;
}
util.printDebugError("Browser did not support signing: " + err.message);
util.printDebugError('Browser did not support signing: ' + err.message);
}
break;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ export async function verify(oid, hashAlgo, signature, message, publicKey, hashe
if (curve.name !== 'p521' && (err.name === 'DataError' || err.name === 'OperationError')) {
throw err;
}
util.printDebugError("Browser did not support verifying: " + err.message);
util.printDebugError('Browser did not support verifying: ' + err.message);
}
break;
case 'node':
Expand Down Expand Up @@ -178,22 +178,22 @@ async function webSign(curve, hashAlgo, message, keyPair) {
const len = curve.payloadSize;
const jwk = privateToJWK(curve.payloadSize, webCurves[curve.name], keyPair.publicKey, keyPair.privateKey);
const key = await webCrypto.importKey(
"jwk",
'jwk',
jwk,
{
"name": "ECDSA",
"namedCurve": webCurves[curve.name],
"hash": { name: enums.read(enums.webHash, curve.hash) }
'name': 'ECDSA',
'namedCurve': webCurves[curve.name],
'hash': { name: enums.read(enums.webHash, curve.hash) }
},
false,
["sign"]
['sign']
);

const signature = new Uint8Array(await webCrypto.sign(
{
"name": 'ECDSA',
"namedCurve": webCurves[curve.name],
"hash": { name: enums.read(enums.webHash, hashAlgo) }
'name': 'ECDSA',
'namedCurve': webCurves[curve.name],
'hash': { name: enums.read(enums.webHash, hashAlgo) }
},
key,
message
Expand All @@ -208,24 +208,24 @@ async function webSign(curve, hashAlgo, message, keyPair) {
async function webVerify(curve, hashAlgo, { r, s }, message, publicKey) {
const jwk = rawPublicToJWK(curve.payloadSize, webCurves[curve.name], publicKey);
const key = await webCrypto.importKey(
"jwk",
'jwk',
jwk,
{
"name": "ECDSA",
"namedCurve": webCurves[curve.name],
"hash": { name: enums.read(enums.webHash, curve.hash) }
'name': 'ECDSA',
'namedCurve': webCurves[curve.name],
'hash': { name: enums.read(enums.webHash, curve.hash) }
},
false,
["verify"]
['verify']
);

const signature = util.concatUint8Array([r, s]).buffer;

return webCrypto.verify(
{
"name": 'ECDSA',
"namedCurve": webCurves[curve.name],
"hash": { name: enums.read(enums.webHash, hashAlgo) }
'name': 'ECDSA',
'namedCurve': webCurves[curve.name],
'hash': { name: enums.read(enums.webHash, hashAlgo) }
},
key,
signature,
Expand Down
14 changes: 7 additions & 7 deletions src/crypto/public_key/rsa.js
Expand Up @@ -318,12 +318,12 @@ async function webSign(hashName, data, n, e, d, p, q, u) {
*/
const jwk = await privateToJWK(n, e, d, p, q, u);
const algo = {
name: "RSASSA-PKCS1-v1_5",
name: 'RSASSA-PKCS1-v1_5',
hash: { name: hashName }
};
const key = await webCrypto.importKey("jwk", jwk, algo, false, ["sign"]);
const key = await webCrypto.importKey('jwk', jwk, algo, false, ['sign']);
// add hash field for ms edge support
return new Uint8Array(await webCrypto.sign({ "name": "RSASSA-PKCS1-v1_5", "hash": hashName }, key, data));
return new Uint8Array(await webCrypto.sign({ 'name': 'RSASSA-PKCS1-v1_5', 'hash': hashName }, key, data));
}

async function nodeSign(hashAlgo, data, n, e, d, p, q, u) {
Expand Down Expand Up @@ -374,12 +374,12 @@ async function bnVerify(hashAlgo, s, n, e, hashed) {

async function webVerify(hashName, data, s, n, e) {
const jwk = publicToJWK(n, e);
const key = await webCrypto.importKey("jwk", jwk, {
name: "RSASSA-PKCS1-v1_5",
const key = await webCrypto.importKey('jwk', jwk, {
name: 'RSASSA-PKCS1-v1_5',
hash: { name: hashName }
}, false, ["verify"]);
}, false, ['verify']);
// add hash field for ms edge support
return webCrypto.verify({ "name": "RSASSA-PKCS1-v1_5", "hash": hashName }, key, s, data);
return webCrypto.verify({ 'name': 'RSASSA-PKCS1-v1_5', 'hash': hashName }, key, s, data);
}

async function nodeVerify(hashAlgo, data, s, n, e) {
Expand Down

0 comments on commit ab22fe8

Please sign in to comment.