Skip to content

Commit

Permalink
perf: add encrypt parameter type checks , to convert numbers as strings
Browse files Browse the repository at this point in the history
convert fatal error to warning in pushNewJob method
  • Loading branch information
Kos-M committed Sep 25, 2022
1 parent d7a6e80 commit 270544f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Crypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ class Crypt {
}

encrypt(text) {
let textToEncrypt = text;
try {
if (typeof textToEncrypt === 'number')
textToEncrypt = textToEncrypt.toString();
const cipher = crypto.createCipheriv(
'aes-256-cbc',
Buffer.from(this.getKey()),
this.getIv()
);
let encrypted = cipher.update(text);
let encrypted = cipher.update(textToEncrypt);
encrypted = Buffer.concat([encrypted, cipher.final()]);
return {
iv: this.getIv().toString('hex'),
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Master {
async pushNewJob(payload) {
return new Promise((resolve, reject) => {
if (typeof payload === 'undefined') {
this.log.fatal('pushNewJob:', 'payload is undefined');
this.log.warn('pushNewJob:', 'payload is undefined');
reject(Error('payload is undefined'));
}
let payloadJson = payload;
Expand Down

0 comments on commit 270544f

Please sign in to comment.