Skip to content

Commit b224271

Browse files
committed
refactor(encryptor): align Encryptor to match browser-passworder interface
1 parent aff6a7f commit b224271

File tree

4 files changed

+211
-126
lines changed

4 files changed

+211
-126
lines changed

app/core/Encryptor/Encryptor.test.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
ENCRYPTION_LIBRARY,
55
KEY_DERIVATION_OPTIONS,
66
KeyDerivationIteration,
7+
KEY_DERIVATION_LEGACY_OPTIONS,
8+
KDF_ALGORITHM,
79
} from './constants';
810

911
const Aes = NativeModules.Aes;
@@ -23,8 +25,8 @@ describe('Encryptor', () => {
2325
expect(
2426
() =>
2527
new Encryptor({
26-
derivationParams: {
27-
algorithm: 'PBKDF2',
28+
keyDerivationOptions: {
29+
algorithm: KDF_ALGORITHM,
2830
params: {
2931
iterations: 100,
3032
},
@@ -89,37 +91,47 @@ describe('Encryptor', () => {
8991
it.each([
9092
{
9193
lib: ENCRYPTION_LIBRARY.original,
92-
expectedKey: 'mockedAesKey',
93-
expectedPBKDF2Args: ['testPassword', 'mockedSalt', 600000, 256],
94+
expectedKeyValue: 'mockedAesKey',
95+
expectedPBKDF2Args: [
96+
'testPassword',
97+
'mockedSalt',
98+
KEY_DERIVATION_OPTIONS.params.iterations,
99+
256,
100+
],
94101
description:
95102
'with original library and default iterations number for key generation',
96103
keyMetadata: KEY_DERIVATION_OPTIONS,
97104
},
98105
{
99106
lib: ENCRYPTION_LIBRARY.original,
100-
expectedKey: 'mockedAesKey',
101-
expectedPBKDF2Args: ['testPassword', 'mockedSalt', 5000, 256],
107+
expectedKeyValue: 'mockedAesKey',
108+
expectedPBKDF2Args: [
109+
'testPassword',
110+
'mockedSalt',
111+
KEY_DERIVATION_LEGACY_OPTIONS.params.iterations,
112+
256,
113+
],
102114
description:
103115
'with original library and old iterations number for key generation',
104116
},
105117
{
106118
lib: 'random-lib', // Assuming not using "original" should lead to AesForked
107-
expectedKey: 'mockedAesForkedKey',
119+
expectedKeyValue: 'mockedAesForkedKey',
108120
expectedPBKDF2Args: ['testPassword', 'mockedSalt'],
109121
description:
110122
'with library different to "original" and default iterations number for key generation',
111123
keyMetadata: KEY_DERIVATION_OPTIONS,
112124
},
113125
{
114126
lib: 'random-lib', // Assuming not using "original" should lead to AesForked
115-
expectedKey: 'mockedAesForkedKey',
127+
expectedKeyValue: 'mockedAesForkedKey',
116128
expectedPBKDF2Args: ['testPassword', 'mockedSalt'],
117129
description:
118130
'with library different to "original" and old iterations number for key generation',
119131
},
120132
])(
121133
'decrypts a string correctly $description',
122-
async ({ lib, expectedKey, expectedPBKDF2Args, keyMetadata }) => {
134+
async ({ lib, expectedKeyValue, expectedPBKDF2Args, keyMetadata }) => {
123135
const password = 'testPassword';
124136
const mockVault = {
125137
cipher: 'mockedCipher',
@@ -128,6 +140,12 @@ describe('Encryptor', () => {
128140
lib,
129141
};
130142

143+
const expectedKey: EncryptionKey = {
144+
key: expectedKeyValue,
145+
keyMetadata: keyMetadata ?? KEY_DERIVATION_LEGACY_OPTIONS,
146+
lib,
147+
};
148+
131149
const decryptedObject = await encryptor.decrypt(
132150
password,
133151
JSON.stringify(

0 commit comments

Comments
 (0)