Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 047a83f

Browse files
committed
resolves #222
1 parent c9989a2 commit 047a83f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ coverage
1717
dist
1818
docs
1919
node_modules
20-
lib
20+
/lib
2121

2222
###################################################################################################
2323
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm

src/core/lib/decrypt.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { decrypt } from './decrypt';
2+
import { encrypt } from './encrypt';
3+
4+
describe('decrypt', () => {
5+
it('error handling', () => {
6+
try {
7+
const v = encrypt('123', '$C&F)J@NcRfUjXn2r4u7x!A%D*G-KaPd');
8+
9+
decrypt(v, '');
10+
fail('should have thrown');
11+
} catch (err) {
12+
expect(err.message).toBe('Invalid key length');
13+
}
14+
});
15+
});

src/core/lib/decrypt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export function decrypt(value: string, cipherKey: string | CipherKeyFunc): any {
5151

5252
return JSON.parse(buff.toString('utf8'));
5353
} catch (err) {
54+
if (!err.message.startsWith('Unexpected token')) {
55+
throw err;
56+
}
57+
5458
return buff.toString('utf8');
5559
}
5660
}

0 commit comments

Comments
 (0)