orgnote-api 0.7.14 → 0.7.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
decryptViaKeys,
|
|
4
4
|
encryptViaPassword,
|
|
5
5
|
decryptViaPassword,
|
|
6
|
+
NoKeysProvidedError,
|
|
7
|
+
NoPasswordProvidedError,
|
|
6
8
|
IncorrectOrMissingPrivateKeyPasswordError,
|
|
7
9
|
} from '../encryption';
|
|
8
10
|
import { test, expect } from 'vitest';
|
|
@@ -122,7 +124,42 @@ YQ==
|
|
|
122
124
|
|
|
123
125
|
try {
|
|
124
126
|
await decryptViaPassword(encryptedMsg, 'password');
|
|
127
|
+
} catch (e) {
|
|
128
|
+
expect(e).toBeInstanceOf(NoKeysProvidedError);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('Should raise IncorrectOrMissingPrivateKeyPasswordError error when incorrect armored key provided', async () => {
|
|
133
|
+
const password = 'test';
|
|
134
|
+
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
135
|
+
|
|
136
|
+
wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
|
|
137
|
+
aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
138
|
+
5iO5mEqoXWXg6nAvNxciA56dKuI=
|
|
139
|
+
=B4Tc
|
|
140
|
+
-----END PGP MESSAGE-----
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
await decryptViaKeys(encryptedMsg, armoredPublicKey, privateKeyPassphrase);
|
|
125
145
|
} catch (e) {
|
|
126
146
|
expect(e).toBeInstanceOf(IncorrectOrMissingPrivateKeyPasswordError);
|
|
127
147
|
}
|
|
128
148
|
});
|
|
149
|
+
|
|
150
|
+
test('Should raise NoPasswordProvidedError error when try to use keys instead of password', async () => {
|
|
151
|
+
const encryptedMsg = `-----BEGIN PGP MESSAGE-----
|
|
152
|
+
|
|
153
|
+
wy4ECQMI6KFWGqyVV+DgYl0qUEeTe1kAdjkoR4FxFJxx+6QiOP+sZ6h7bn//
|
|
154
|
+
aGW80jwBXEQ7uTjT8akpOKiH7BIuhEUZIXh+vDveG0Uwf63s2dIklznAEo+E
|
|
155
|
+
5iO5mEqoXWXg6nAvNxciA56dKuI=
|
|
156
|
+
=B4Tc
|
|
157
|
+
-----END PGP MESSAGE-----
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
await decryptViaKeys(encryptedMsg, armoredPrivateKey, privateKeyPassphrase);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
expect(e).toBeInstanceOf(NoPasswordProvidedError);
|
|
164
|
+
}
|
|
165
|
+
});
|
package/encryption/encryption.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
export class IncorrectOrMissingPrivateKeyPasswordError extends Error {}
|
|
12
12
|
export class ImpossibleToDecryptWithProvidedKeysError extends Error {}
|
|
13
13
|
export class IncorrectEncryptionPasswordError extends Error {}
|
|
14
|
+
export class NoKeysProvidedError extends Error {}
|
|
15
|
+
export class NoPasswordProvidedError extends Error {}
|
|
14
16
|
|
|
15
17
|
const noPrivateKeyPassphraseProvidedErrorMsg =
|
|
16
18
|
'Error: Signing key is not decrypted.';
|
|
@@ -25,9 +27,15 @@ const decriptionFailedErrorMsg =
|
|
|
25
27
|
const incorrectEncryptionPasswordErrorMsg =
|
|
26
28
|
'Error decrypting message: Modification detected.';
|
|
27
29
|
|
|
28
|
-
const
|
|
30
|
+
const noSymmetricallyEncryptedSessionKeyErrorMsg =
|
|
29
31
|
'Error decrypting message: No symmetrically encrypted session key packet found.';
|
|
30
32
|
|
|
33
|
+
const armoredTextNotTypePrivateKeyErrorMsg =
|
|
34
|
+
'Armored text not of type private key';
|
|
35
|
+
|
|
36
|
+
const notPrivateKeyErrprMsg =
|
|
37
|
+
'Error decrypting message: No public key encrypted session key packet found.';
|
|
38
|
+
|
|
31
39
|
export const encryptViaKeys = withCustomErrors(_encryptViaKeys);
|
|
32
40
|
export const encryptViaPassword = withCustomErrors(_encryptViaPassword);
|
|
33
41
|
export const decryptViaPassword = withCustomErrors(_decryptViaPassword);
|
|
@@ -139,7 +147,7 @@ function withCustomErrors<P extends unknown[], T>(
|
|
|
139
147
|
incorrectPrivateKeyPassphraseErrorMsg,
|
|
140
148
|
corruptedPrivateKeyErrorMsg,
|
|
141
149
|
decryptionKeyIsNotDecryptedErrorMsg,
|
|
142
|
-
|
|
150
|
+
armoredTextNotTypePrivateKeyErrorMsg,
|
|
143
151
|
].includes(e.message)
|
|
144
152
|
) {
|
|
145
153
|
throw new IncorrectOrMissingPrivateKeyPasswordError(e.message);
|
|
@@ -150,6 +158,14 @@ function withCustomErrors<P extends unknown[], T>(
|
|
|
150
158
|
if (e.message === incorrectEncryptionPasswordErrorMsg) {
|
|
151
159
|
throw new IncorrectEncryptionPasswordError();
|
|
152
160
|
}
|
|
161
|
+
if (e.message === noSymmetricallyEncryptedSessionKeyErrorMsg) {
|
|
162
|
+
throw new NoKeysProvidedError();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (e.message === notPrivateKeyErrprMsg) {
|
|
166
|
+
throw new NoPasswordProvidedError();
|
|
167
|
+
}
|
|
168
|
+
|
|
153
169
|
throw e;
|
|
154
170
|
}
|
|
155
171
|
};
|