diff --git a/src/openpgp.js b/src/openpgp.js index d78ad39c..6304b138 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -253,12 +253,14 @@ export async function encryptKey({ privateKey, passphrase, config }) { * @async * @static */ -export function encrypt({ message, encryptionKeys, signingKeys, passwords, sessionKey, armor = true, detached = false, signature = null, wildcard = false, signingKeyIDs = [], encryptionKeyIDs = [], date = new Date(), signingUserIDs = [], encryptionUserIDs = [], config }) { +export function encrypt({ message, encryptionKeys, signingKeys, passwords, sessionKey, armor = true, signature = null, wildcard = false, signingKeyIDs = [], encryptionKeyIDs = [], date = new Date(), signingUserIDs = [], encryptionUserIDs = [], config, ...rest }) { config = { ...defaultConfig, ...config }; checkMessage(message); encryptionKeys = toArray(encryptionKeys); signingKeys = toArray(signingKeys); passwords = toArray(passwords); signingUserIDs = toArray(signingUserIDs); encryptionUserIDs = toArray(encryptionUserIDs); - if (detached) { - throw new Error("detached option has been removed from openpgp.encrypt. Separately call openpgp.sign instead. Don't forget to remove privateKeys option as well."); + if (rest.detached) { + throw new Error("The `detached` option has been removed from openpgp.encrypt, separately call openpgp.sign instead. Don't forget to remove the `privateKeys` option as well."); } + if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.encrypt, pass `encryptionKeys` instead"); + if (rest.privateKeys) throw new Error("The `privateKeys` option has been removed from openpgp.encrypt, pass `signingKeys` instead"); return Promise.resolve().then(async function() { const streaming = message.fromStream; @@ -309,9 +311,11 @@ export function encrypt({ message, encryptionKeys, signingKeys, passwords, sessi * @async * @static */ -export function decrypt({ message, decryptionKeys, passwords, sessionKeys, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config }) { +export function decrypt({ message, decryptionKeys, passwords, sessionKeys, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config, ...rest }) { config = { ...defaultConfig, ...config }; checkMessage(message); verificationKeys = toArray(verificationKeys); decryptionKeys = toArray(decryptionKeys); passwords = toArray(passwords); sessionKeys = toArray(sessionKeys); + if (rest.privateKeys) throw new Error("The `privateKeys` option has been removed from openpgp.decrypt, pass `decryptionKeys` instead"); + if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.decrypt, pass `verificationKeys` instead"); return message.decrypt(decryptionKeys, passwords, sessionKeys, date, config).then(async function(decrypted) { if (!verificationKeys) { @@ -366,11 +370,13 @@ export function decrypt({ message, decryptionKeys, passwords, sessionKeys, verif * @async * @static */ -export function sign({ message, signingKeys, armor = true, detached = false, signingKeyIDs = [], date = new Date(), signingUserIDs = [], config }) { +export function sign({ message, signingKeys, armor = true, detached = false, signingKeyIDs = [], date = new Date(), signingUserIDs = [], config, ...rest }) { config = { ...defaultConfig, ...config }; checkCleartextOrMessage(message); + if (rest.privateKeys) throw new Error("The `privateKeys` option has been removed from openpgp.sign, pass `signingKeys` instead"); if (message instanceof CleartextMessage && !armor) throw new Error("Can't sign non-armored cleartext message"); if (message instanceof CleartextMessage && detached) throw new Error("Can't detach-sign a cleartext message"); + signingKeys = toArray(signingKeys); signingUserIDs = toArray(signingUserIDs); return Promise.resolve().then(async function() { @@ -419,11 +425,13 @@ export function sign({ message, signingKeys, armor = true, detached = false, sig * @async * @static */ -export function verify({ message, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config }) { +export function verify({ message, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config, ...rest }) { config = { ...defaultConfig, ...config }; checkCleartextOrMessage(message); + if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.verify, pass `verificationKeys` instead"); if (message instanceof CleartextMessage && format === 'binary') throw new Error("Can't return cleartext message data as binary"); if (message instanceof CleartextMessage && signature) throw new Error("Can't verify detached cleartext signature"); + verificationKeys = toArray(verificationKeys); return Promise.resolve().then(async function() { @@ -470,9 +478,10 @@ export function verify({ message, verificationKeys, expectSigned = false, format * @async * @static */ -export function generateSessionKey({ encryptionKeys, date = new Date(), encryptionUserIDs = [], config }) { +export function generateSessionKey({ encryptionKeys, date = new Date(), encryptionUserIDs = [], config, ...rest }) { config = { ...defaultConfig, ...config }; encryptionKeys = toArray(encryptionKeys); encryptionUserIDs = toArray(encryptionUserIDs); + if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.generateSessionKey, pass `encryptionKeys` instead"); return Promise.resolve().then(async function() { @@ -500,9 +509,10 @@ export function generateSessionKey({ encryptionKeys, date = new Date(), encrypti * @async * @static */ -export function encryptSessionKey({ data, algorithm, aeadAlgorithm, encryptionKeys, passwords, armor = true, wildcard = false, encryptionKeyIDs = [], date = new Date(), encryptionUserIDs = [], config }) { +export function encryptSessionKey({ data, algorithm, aeadAlgorithm, encryptionKeys, passwords, armor = true, wildcard = false, encryptionKeyIDs = [], date = new Date(), encryptionUserIDs = [], config, ...rest }) { config = { ...defaultConfig, ...config }; checkBinary(data); checkString(algorithm, 'algorithm'); encryptionKeys = toArray(encryptionKeys); passwords = toArray(passwords); encryptionUserIDs = toArray(encryptionUserIDs); + if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.encryptSessionKey, pass `encryptionKeys` instead"); return Promise.resolve().then(async function() { @@ -527,9 +537,10 @@ export function encryptSessionKey({ data, algorithm, aeadAlgorithm, encryptionKe * @async * @static */ -export function decryptSessionKeys({ message, decryptionKeys, passwords, date = new Date(), config }) { +export function decryptSessionKeys({ message, decryptionKeys, passwords, date = new Date(), config, ...rest }) { config = { ...defaultConfig, ...config }; checkMessage(message); decryptionKeys = toArray(decryptionKeys); passwords = toArray(passwords); + if (rest.privateKeys) throw new Error("The `privateKeys` option has been removed from openpgp.decryptSessionKeys, pass `decryptionKeys` instead"); return Promise.resolve().then(async function() { diff --git a/test/general/openpgp.js b/test/general/openpgp.js index 48a45e2e..070feb5e 100644 --- a/test/general/openpgp.js +++ b/test/general/openpgp.js @@ -1509,7 +1509,12 @@ aOU= describe('sign - unit tests', function() { it('Supports signing with GnuPG dummy key', async function() { const dummyKey = await openpgp.readKey({ armoredKey: gnuDummyKeySigningSubkey }); - const sig = await openpgp.sign({ message: await openpgp.createMessage({ text: 'test' }), privateKeys: dummyKey, date: new Date('2018-12-17T03:24:00') }); + const sig = await openpgp.sign({ + message: await openpgp.createMessage({ text: 'test' }), + signingKeys: dummyKey, + date: new Date('2018-12-17T03:24:00'), + config: { minRSABits: 1024 } + }); expect(sig).to.match(/-----END PGP MESSAGE-----\n$/); }); });