Begin refactoring backfilling and preparation operations into setup and start adding encryption metadata to models

This commit is contained in:
Tuan Dang
2023-05-03 14:21:42 +03:00
parent b462ca3e89
commit 099cee7f39
37 changed files with 797 additions and 619 deletions
+21
View File
@@ -0,0 +1,21 @@
import { InternalServerError } from "../utils/errors";
/**
* Validate that the encryption key [encryptionKey] is in base64 format and 256-bit
* @param {String} encryptionKey - the encryption key to validate
*/
export const validateEncryptionKey = (encryptionKey: string): Buffer => {
const keyBuffer = Buffer.from(encryptionKey, 'base64')
const decoded = keyBuffer.toString('base64');
if (decoded !== encryptionKey) throw InternalServerError({
message: 'Failed to validate the format of the encryption key. Please check that it is in base64 format.'
});
if (keyBuffer.length !== 32) throw InternalServerError({
message: 'Failed to validate that the encryption key is 256-bit. Please check that it is 256-bit.'
});
return keyBuffer;
};
+1
View File
@@ -0,0 +1 @@
export * from './config';