How to use fs-json-store-encryption-adapter - 3 common examples

To help you get started, we’ve selected a few fs-json-store-encryption-adapter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vladimiry / ElectronMail / src / electron-main / database / serialization.ts View on Github external
constructor(input: { key: Buffer, preset: EncryptionAdapterBundle.KeyBasedPreset }) {
        this.logger.info("constructor()");

        const encryptionAdapter = new EncryptionAdapterBundle.EncryptionAdapter(input);

        this.read = async (data: Buffer) => {
            this.logger.info(`read() buffer.length: ${data.length}`);

            const {header: {serialization}} = persistencePartsUtil.split(data);
            const decryptedData = await encryptionAdapter.read(data);

            if (serialization && serialization.type === "msgpack") {
                this.logger.verbose(`"msgpack.decode" start`);
                const decoded = msgpack.decode(decryptedData) as FsDb;
                this.logger.verbose(`"msgpack.decode" end`);
                return decoded;
            }

            const readableStream = bufferToStream(decryptedData);
github vladimiry / ElectronMail / src / electron-main / util.ts View on Github external
export async function buildSettingsAdapter(
    {configStore}: Context,
    password: string,
): Promise {
    return new EncryptionAdapter(
        {password, preset: (await configStore.readExisting()).encryptionPreset},
        {keyDerivationCache: true, keyDerivationCacheLimit: 3},
    );
}
github vladimiry / ElectronMail / src / electron-main / api / index.spec.ts View on Github external
readSettings: async (t) => {
        const {
            endpoints,
            mocks: {
                "src/electron-main/keytar": {setPassword: setPasswordSpy, deletePassword: deletePasswordSpy},
                "src/electron-main/storage-upgrade": {upgradeSettings: upgradeSettingsSpy},
                "src/electron-main/session": {initSessionByAccount: initSessionByAccountMock},
            },
        } = t.context;

        t.false(await t.context.ctx.settingsStore.readable(), "settings file does not exist");
        t.falsy(t.context.ctx.settingsStore.adapter, "adapter is not set");
        const initial = await readConfigAndSettings(endpoints, {password: OPTIONS.masterPassword, savePassword: false});
        t.is(0, upgradeSettingsSpy.callCount);
        t.is(t.context.ctx.settingsStore.adapter && t.context.ctx.settingsStore.adapter.constructor.name,
            EncryptionAdapter.name,
            "adapter is an EncryptionAdapter",
        );
        const initialExpected = {...t.context.ctx.initialStores.settings, ...{_rev: 0}};
        t.deepEqual(initial, initialExpected, "checking initial settings file");
        t.true(await t.context.ctx.settingsStore.readable(), "settings file exists");
        t.is(setPasswordSpy.callCount, 0);
        t.is(deletePasswordSpy.callCount, 1);
        t.true(deletePasswordSpy.alwaysCalledWithExactly());
        t.is(initial.accounts.length, initSessionByAccountMock.callCount);
        for (const {login} of initial.accounts) {
            t.true(initSessionByAccountMock.calledWithExactly(t.context.ctx, login));
        }

        const initialUpdated = await t.context.ctx.settingsStore.write(initial);
        const initialUpdatedExpected = {...initial, ...initialExpected, ...{_rev: initialExpected._rev + 1}};
        t.deepEqual(initialUpdated, initialUpdatedExpected, "saved initial settings file");

fs-json-store-encryption-adapter

Encryption adapter for the "fs-json-store" module

MIT
Latest version published 4 months ago

Package Health Score

56 / 100
Full package analysis