Skip to content

Commit 1eb24a5

Browse files
committed
fix in promise rejection
1 parent 8419ea7 commit 1eb24a5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

basic256.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let crypto = require('crypto');
55
try {
66
var savedKeys = require("./config.js").k;
77
} catch (e) {
8-
Promise.reject('No Configuration Exists!');
8+
return Promise.reject('No Configuration Exists!');
99
}
1010

1111
var ALGORITHM, KEY, HMAC_ALGORITHM, HMAC_KEY;
@@ -39,7 +39,7 @@ var constant_time_compare = function (val1, val2) {
3939
module.exports = {
4040

4141
"encrypt": function (plain_text) {
42-
if (!plain_text || typeof(plain_text) !== "string") Promise.reject("Plain text not found.");
42+
if (!plain_text || typeof(plain_text) !== "string") return Promise.reject("Plain text not found.");
4343

4444
var IV = Buffer.from(randomValueHex(16)); // ensure that the IV (initialization vector) is random
4545
var encryptor, cipher_text, hmac;
@@ -60,7 +60,7 @@ module.exports = {
6060
},
6161

6262
"decrypt": function (cipher_text) {
63-
if (!cipher_text || typeof(cipher_text) !== "string" || !cipher_text.match("$")) Promise.reject("A valid cipher text not found.");
63+
if (!cipher_text || typeof(cipher_text) !== "string" || !cipher_text.match("$")) return Promise.reject("A valid cipher text not found.");
6464

6565
var cipher_blob = cipher_text.split("$");
6666
var ct = cipher_blob[0];
@@ -73,7 +73,7 @@ module.exports = {
7373
chmac.update(IV.toString('hex'));
7474

7575
if (!constant_time_compare(chmac.digest('hex'), hmac)) {
76-
Promise.reject("Encrypted Blob has been tampered with.");
76+
return Promise.reject("Encrypted Blob has been tampered with.");
7777
}
7878

7979
decryptor = crypto.createDecipheriv(ALGORITHM, KEY, IV);

0 commit comments

Comments
 (0)