mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-03-30 15:08:32 +00:00
Lint: error on unnecessary switch-case braces
Also fix some indent issues with armoring code detected after required ESLint update. s
This commit is contained in:
parent
917faa56f5
commit
30635c72e8
@ -13,7 +13,8 @@ module.exports = {
|
||||
|
||||
'plugins': [
|
||||
'chai-friendly',
|
||||
'import'
|
||||
'import',
|
||||
'unicorn'
|
||||
],
|
||||
|
||||
'globals': { // TODO are all these necessary?
|
||||
@ -118,6 +119,7 @@ module.exports = {
|
||||
'max-lines': [2, { 'max': 620, 'skipBlankLines': true, 'skipComments': true }],
|
||||
'no-unused-expressions': 0,
|
||||
'chai-friendly/no-unused-expressions': [2, { 'allowShortCircuit': true }],
|
||||
'unicorn/switch-case-braces': ['error', 'avoid'],
|
||||
|
||||
// Custom warnings:
|
||||
'no-console': 1
|
||||
|
1089
package-lock.json
generated
1089
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -86,6 +86,7 @@
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-chai-friendly": "^0.7.2",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-unicorn": "^48.0.1",
|
||||
"fflate": "^0.7.4",
|
||||
"http-server": "^14.1.1",
|
||||
"karma": "^6.4.0",
|
||||
|
@ -331,12 +331,11 @@ export function generateParams(algo, bits, oid) {
|
||||
switch (algo) {
|
||||
case enums.publicKey.rsaEncrypt:
|
||||
case enums.publicKey.rsaEncryptSign:
|
||||
case enums.publicKey.rsaSign: {
|
||||
case enums.publicKey.rsaSign:
|
||||
return publicKey.rsa.generate(bits, 65537).then(({ n, e, d, p, q, u }) => ({
|
||||
privateParams: { d, p, q, u },
|
||||
publicParams: { n, e }
|
||||
}));
|
||||
}
|
||||
case enums.publicKey.ecdsa:
|
||||
return publicKey.elliptic.generate(oid).then(({ oid, Q, secret }) => ({
|
||||
privateParams: { d: secret },
|
||||
|
@ -110,9 +110,9 @@ async function genPublicEphemeralKey(curve, Q) {
|
||||
break;
|
||||
case 'node':
|
||||
return nodePublicEphemeralKey(curve, Q);
|
||||
default: {
|
||||
default:
|
||||
return jsPublicEphemeralKey(curve, Q);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,9 +173,8 @@ async function genPrivateEphemeralKey(curve, V, Q, d) {
|
||||
break;
|
||||
case 'node':
|
||||
return nodePrivateEphemeralKey(curve, V, d);
|
||||
default: {
|
||||
default:
|
||||
return jsPrivateEphemeralKey(curve, V, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed
|
||||
if (message && !util.isStream(message)) {
|
||||
const keyPair = { publicKey, privateKey };
|
||||
switch (curve.type) {
|
||||
case 'web': {
|
||||
case 'web':
|
||||
// If browser doesn't support a curve, we'll catch it
|
||||
try {
|
||||
// Need to await to make sure browser succeeds
|
||||
@ -63,7 +63,6 @@ export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed
|
||||
util.printDebugError('Browser did not support signing: ' + err.message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'node': {
|
||||
const signature = await nodeSign(curve, hashAlgo, message, keyPair);
|
||||
return {
|
||||
|
@ -100,9 +100,8 @@ export async function verify(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
||||
throw new Error('Hash algorithm too weak for EdDSA.');
|
||||
}
|
||||
switch (algo) {
|
||||
case enums.publicKey.ed25519: {
|
||||
case enums.publicKey.ed25519:
|
||||
return ed25519.sign.detached.verify(hashed, RS, publicKey);
|
||||
}
|
||||
case enums.publicKey.ed448: {
|
||||
const ed448 = await util.getNobleCurve(enums.publicKey.ed448);
|
||||
return ed448.verify(RS, hashed, publicKey);
|
||||
|
@ -192,9 +192,8 @@ class CurveWithOID {
|
||||
const publicKey = util.concatUint8Array([new Uint8Array([0x40]), keyPair.publicKey]);
|
||||
return { publicKey, privateKey };
|
||||
}
|
||||
default: {
|
||||
default:
|
||||
return jsGenKeyPair(this.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -153,9 +153,8 @@ export async function sign(algo, hashAlgo, publicKeyParams, privateKeyParams, da
|
||||
const { x } = privateKeyParams;
|
||||
return publicKey.dsa.sign(hashAlgo, hashed, g, p, q, x);
|
||||
}
|
||||
case enums.publicKey.elgamal: {
|
||||
case enums.publicKey.elgamal:
|
||||
throw new Error('Signing with Elgamal is not defined in the OpenPGP standard.');
|
||||
}
|
||||
case enums.publicKey.ecdsa: {
|
||||
const { oid, Q } = publicKeyParams;
|
||||
const { d } = privateKeyParams;
|
||||
|
@ -47,33 +47,33 @@ function getType(text) {
|
||||
// parts, and this is the Xth part out of Y.
|
||||
if (/MESSAGE, PART \d+\/\d+/.test(header[1])) {
|
||||
return enums.armor.multipartSection;
|
||||
} else
|
||||
}
|
||||
// BEGIN PGP MESSAGE, PART X
|
||||
// Used for multi-part messages, where this is the Xth part of an
|
||||
// unspecified number of parts. Requires the MESSAGE-ID Armor
|
||||
// Header to be used.
|
||||
if (/MESSAGE, PART \d+/.test(header[1])) {
|
||||
return enums.armor.multipartLast;
|
||||
} else
|
||||
}
|
||||
// BEGIN PGP SIGNED MESSAGE
|
||||
if (/SIGNED MESSAGE/.test(header[1])) {
|
||||
return enums.armor.signed;
|
||||
} else
|
||||
}
|
||||
// BEGIN PGP MESSAGE
|
||||
// Used for signed, encrypted, or compressed files.
|
||||
if (/MESSAGE/.test(header[1])) {
|
||||
return enums.armor.message;
|
||||
} else
|
||||
}
|
||||
// BEGIN PGP PUBLIC KEY BLOCK
|
||||
// Used for armoring public keys.
|
||||
if (/PUBLIC KEY BLOCK/.test(header[1])) {
|
||||
return enums.armor.publicKey;
|
||||
} else
|
||||
}
|
||||
// BEGIN PGP PRIVATE KEY BLOCK
|
||||
// Used for armoring private keys.
|
||||
if (/PRIVATE KEY BLOCK/.test(header[1])) {
|
||||
return enums.armor.privateKey;
|
||||
} else
|
||||
}
|
||||
// BEGIN PGP SIGNATURE
|
||||
// Used for detached signatures, OpenPGP/MIME signatures, and
|
||||
// cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE
|
||||
|
@ -218,14 +218,13 @@ function encodeSessionKey(version, keyAlgo, cipherAlgo, sessionKeyData) {
|
||||
case enums.publicKey.rsaEncrypt:
|
||||
case enums.publicKey.rsaEncryptSign:
|
||||
case enums.publicKey.elgamal:
|
||||
case enums.publicKey.ecdh: {
|
||||
case enums.publicKey.ecdh:
|
||||
// add checksum
|
||||
return util.concatUint8Array([
|
||||
new Uint8Array(version === 6 ? [] : [cipherAlgo]),
|
||||
sessionKeyData,
|
||||
util.writeChecksum(sessionKeyData.subarray(sessionKeyData.length % 8))
|
||||
]);
|
||||
}
|
||||
case enums.publicKey.x25519:
|
||||
case enums.publicKey.x448:
|
||||
return sessionKeyData;
|
||||
|
Loading…
x
Reference in New Issue
Block a user