Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
export async function buildSettingsAdapter(
{configStore}: Context,
password: string,
): Promise {
return new EncryptionAdapter(
{password, preset: (await configStore.readExisting()).encryptionPreset},
{keyDerivationCache: true, keyDerivationCacheLimit: 3},
);
}