Skip to content

Commit

Permalink
fix: allow to generate unencrypted packets
Browse files Browse the repository at this point in the history
  • Loading branch information
kybarg committed May 9, 2024
1 parent 28b1465 commit 6dc6d70
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 1 addition & 16 deletions lib/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit 6dc6d70

Please sign in to comment.