Skip to content

Commit

Permalink
Throw in encryptSessionKey if no keys or passwords are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
larabr committed Jul 26, 2022
1 parent b677ab5 commit 1ab556c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/message.js
Expand Up @@ -466,6 +466,7 @@ export class Message {
packetlist.push(...results);
}

if (!packetlist.length) throw new Error('No keys or passwords provided.');
return new Message(packetlist);
}

Expand Down
7 changes: 7 additions & 0 deletions test/general/openpgp.js
Expand Up @@ -2015,6 +2015,13 @@ aOU=
const [decryptedSessionKey] = await openpgp.decryptSessionKeys({ message: objectMessage, passwords });
expect(decryptedSessionKey).to.deep.equal(sessionKey);
});

it('passing no encryption keys or passwords leads to exception', async function() {
await expect(openpgp.encryptSessionKey({
algorithm: 'aes256',
data: util.hexToUint8Array('3e99c1bb485e70a1fcef09a7ad8d38d171015243bbdd853e1a2b0e334d122ff3')
})).to.be.rejectedWith(/No keys or passwords provided/);
});
});

describe('encrypt, decrypt, sign, verify - integration tests', function() {
Expand Down

0 comments on commit 1ab556c

Please sign in to comment.