diff --git a/lib/index.js b/lib/index.js index 2d56db2..6a3713c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -212,7 +212,11 @@ class SSP extends EventEmitter { async command(command, args) { command = command.toUpperCase() if (commandList[command] === undefined) { - throw new Error('Command not found') + throw new Error('Unknown command') + } + + if (commandList[command].encrypted && this.keys.encryptKey === null) { + throw new Error('Command requires ecnryption') } if (this.state.processing) { diff --git a/lib/utils.js b/lib/utils.js index a431456..2a85c0c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -983,11 +983,7 @@ function generateKeys() { */ function getPacket(command, argBytes, sequence, encryptKey = null, eCount) { if (commandList[command].args && argBytes.length === 0) { - throw new Error('Args missings') - } - - if (commandList[command].encrypted && encryptKey === null) { - throw new Error('Command requires ecnryption') + throw new Error('Command requires arguments') } const SEQ_SLAVE_ID = sequence diff --git a/lib/utils.test.js b/lib/utils.test.js index 725fb8d..56bfdf7 100644 --- a/lib/utils.test.js +++ b/lib/utils.test.js @@ -797,14 +797,7 @@ describe('getPacket', () => { const args = Buffer.from([]) const sequence = 1 - expect(() => getPacket('SET_CHANNEL_INHIBITS', args, sequence)).toThrow('Args missings') - }) - - test('throws error when encryption key is missing for a command that requires encryption', () => { - const args = Buffer.from([1, 2, 3]) - const sequence = 1 - - expect(() => getPacket('PAYOUT_AMOUNT', args, sequence)).toThrow('Command requires ecnryption') + expect(() => getPacket('SET_CHANNEL_INHIBITS', args, sequence)).toThrow('Command requires arguments') }) test('generates packet with encrypted data when encryption key is provided', () => { @@ -830,14 +823,6 @@ describe('getPacket', () => { const result = getPacket('PAYOUT_AMOUNT', args, sequence, key, count) expect(result).toBeDefined() // Assert whatever you expect from the result }) - - test('throws error when encryption key is missing for PAYOUT_AMOUNT command that requires encryption', () => { - const args = argsToByte('PAYOUT_AMOUNT', { amount: 5, country_code: 'EUR' }, 6) - const sequence = 1 - const count = 1 - - expect(() => getPacket('PAYOUT_AMOUNT', args, sequence, null, count)).toThrow('Command requires ecnryption') - }) }) describe('createSSPHostEncryptionKey', () => {