ft-encryption
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -31,2 +31,3 @@ 'use strict'; | ||
* @return {Object} object | ||
* @throws {Error} If can't decrypt or parse JSON | ||
*/ | ||
@@ -36,13 +37,8 @@ Encryption.prototype.decrypt = function (encrypted) { | ||
let result = null; | ||
try { | ||
let str = cipher.update(encrypted, 'base64', 'utf8'); | ||
str += cipher.final('utf8'); | ||
result = JSON.parse(str); | ||
} catch (error) { | ||
logger.warn('Error decrypting string', {encrypted: encrypted, error: error}); | ||
} finally { | ||
return result; | ||
} | ||
let str = cipher.update(encrypted, 'base64', 'utf8'); | ||
str += cipher.final('utf8'); | ||
result = JSON.parse(str); | ||
return result; | ||
}; | ||
module.exports = Encryption; |
{ | ||
"name": "ft-encryption", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "encryption wrapper", | ||
@@ -5,0 +5,0 @@ "main": "lib/encryption.js", |
@@ -25,7 +25,15 @@ 'use strict'; | ||
it('should return null if unable to decrypt', () => { | ||
let data = encryption.decrypt('not an encrypted string..'); | ||
assert.ok(!data); | ||
it('should throw error if unable to decrypt', () => { | ||
assert.throws(() => { | ||
let data = encryption.decrypt('not an encrypted string..'); | ||
}, Error); | ||
}); | ||
it('should throw error if unable to parse JSON', () => { | ||
let encrypted_string = '8SoHFEIOqSqtF13iVznL5A=='; | ||
assert.throws(() => { | ||
let data = encryption.decrypt(encrypted_string); | ||
}, Error); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4173
108