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