@typinghare/trick 1.0.6 → 2.0.0

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.
Files changed (41) hide show
  1. package/README.md +86 -0
  2. package/dist/app.d.ts +1 -1
  3. package/dist/app.js +79 -89
  4. package/dist/config.d.ts +71 -14
  5. package/dist/config.js +62 -25
  6. package/dist/encrypt.d.ts +68 -14
  7. package/dist/encrypt.js +77 -28
  8. package/dist/error.d.ts +30 -0
  9. package/dist/error.js +69 -0
  10. package/dist/index.d.ts +1 -2
  11. package/dist/index.js +1 -2
  12. package/dist/passphrase.d.ts +13 -0
  13. package/dist/passphrase.js +26 -0
  14. package/eslint.config.js +41 -0
  15. package/package.json +23 -12
  16. package/src/app.ts +110 -125
  17. package/src/config.ts +96 -31
  18. package/src/encrypt.ts +89 -44
  19. package/src/error.ts +82 -0
  20. package/src/index.ts +1 -2
  21. package/src/passphrase.ts +39 -0
  22. package/test/resources/really.json +2 -2
  23. package/test/resources/task.yml +3 -4
  24. package/test/trick.config.json +13 -0
  25. package/.prettierrc.yaml +0 -6
  26. package/.wander/jameschan312.cn@gmail.com/.idea/codeStyles/Project.xml +0 -52
  27. package/.wander/jameschan312.cn@gmail.com/.idea/codeStyles/codeStyleConfig.xml +0 -5
  28. package/.wander/jameschan312.cn@gmail.com/.idea/jsLibraryMappings.xml +0 -6
  29. package/.wander/jameschan312.cn@gmail.com/.idea/misc.xml +0 -6
  30. package/.wander/jameschan312.cn@gmail.com/.idea/modules.xml +0 -8
  31. package/.wander/jameschan312.cn@gmail.com/.idea/prettier.xml +0 -6
  32. package/.wander/jameschan312.cn@gmail.com/.idea/trick.iml +0 -14
  33. package/.wander/jameschan312.cn@gmail.com/.idea/vcs.xml +0 -6
  34. package/.wander/jameschan312.cn@gmail.com/.idea/webResources.xml +0 -14
  35. package/dist/constant.d.ts +0 -2
  36. package/dist/constant.js +0 -3
  37. package/dist/secret.d.ts +0 -5
  38. package/dist/secret.js +0 -14
  39. package/src/constant.ts +0 -4
  40. package/src/secret.ts +0 -14
  41. package/trick.config.json +0 -20
package/README.md CHANGED
@@ -3,5 +3,91 @@
3
3
  # Install
4
4
 
5
5
  ```shell
6
+ # npm
7
+ npm install -g @typinghare/trick
8
+
9
+ # pnpm
6
10
  pnpm add -g @typinghare/trick
11
+
12
+ # yarn
13
+ yarn add -g @typinghare/trick
14
+ ```
15
+
16
+ ## Philosophy
17
+
18
+ We often add sensitive and credential files, such as `.env` and `api_key.conf`, to `.gitignore`, preventing them from being committed or even pushed to remote depots for safety reasons. Then, we have to manually copy the file to the server. It would be effortless if we only had one file, but imagine we have a lot in a bigger project. Even worse, some careless people (me) have even lost these sensitive files after changing computers!
19
+
20
+ **Trick** helps you to encrypt sensitive files with a passphrase so that you can upload the credential file to Git platforms. Later on the server, just use the same passphrase to decrypt the files with ease.
21
+
22
+ ## Quick Example
23
+
24
+ Set up the **target** with the files needed to be encrypted:
25
+
26
+ ```bash
27
+ # This will create a trick.config.json in the current working directory
28
+ # trick add <target> [files...]
29
+ $ trick add MyTargetName .env api_key.conf
30
+
31
+ # Display the list of target names and the files bound
32
+ $ trick list
33
+ ```
34
+
35
+ Create a `passphrase.json` file under `~/.config` with the following content:
36
+
37
+ ```json
38
+ {
39
+ "MyTargetName": "Reg5eGPXWdmeW0i08uaygBlfbXP+tJlnu7z551Qt568="
40
+ }
41
+ ```
42
+
43
+ Here, the key is the target name, and the value is the `passphrase` that is used to encrypt/decrypt the files associated with this target name.
44
+
45
+ Encrypt the files:
46
+
47
+ ```bash
48
+ $ trick encrypt MyTargetName
49
+ ```
50
+
51
+ You will see the following output:
52
+
53
+ ```text
54
+ [ENCRYPTED] .env -> .trick/encrypted/.env.enc
55
+ [ENCRYPTED] api_key.conf -> .trick/encrypted/api_key.conf.enc
56
+ ```
57
+
58
+ Encrypted files are all saved to `.trick`. On the server, set the the `passphrase.json` in the same way, and execute:
59
+
60
+ ```bash
61
+ $ trick decrypt MyTargetName
62
+ ```
63
+
64
+ And you will see that the files are restored:
65
+
66
+ ```text
67
+ [DECRYPTED] .trick/encrypted/.env.enc -> .env
68
+ [DECRYPTED] .trick/encrypted/api_key.conf.enc -> api_key.conf
69
+ ```
70
+
71
+ > [!IMPORTANT]
72
+ > The `passphrase.json` collects all the passphrases you have. Please back it up in multiple devices every time you edit it!
73
+
74
+ ## More Features
75
+
76
+ ### Default Target Name
77
+
78
+ You can set the default target name so that you don't need to input it every time:
79
+
80
+ ```bash
81
+ # Set the default target name
82
+ $ trick set-default MyTargetName
83
+
84
+ # Display the default target name
85
+ $ trick get-default
86
+ ```
87
+
88
+ Now you can encrypt and decrypt more easily:
89
+
90
+ ```bash
91
+ $ trick encrypt
92
+ $ trick decrypt
7
93
  ```
package/dist/app.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function resolve_error(err: any): void;
1
+ export {};
package/dist/app.js CHANGED
@@ -1,92 +1,120 @@
1
1
  import { Command } from 'commander';
2
- import { getTargetFromConfig, ReadConfigError, TargetNotFoundError, updateConfig, WriteConfigError, } from './config.js';
3
- import { decryptFiles, encryptFiles, FailToDecryptFileError, FailToEncryptFileError, } from './encrypt.js';
4
- import { getSecret, SecretNotFoundError } from './secret.js';
5
- import { TRICK_ENCRYPTED_DIR } from './constant.js';
2
+ import { getTargetFromConfig, updateConfig } from './config.js';
3
+ import { decryptFiles, encryptFiles } from './encrypt.js';
6
4
  import fsExtra from 'fs-extra';
7
5
  import chalk from 'chalk';
6
+ import { getPassphrase } from './passphrase.js';
7
+ import { resolve_error } from './error.js';
8
8
  const program = new Command();
9
- program.version('Trick v1.0.6');
10
- program.description('Save credential files to remote safely.');
9
+ program.version('2.0.0');
10
+ program.description('Save credential files to remote safely and easily.');
11
11
  program
12
12
  .command('add')
13
- .description('Adds a target.')
14
- .argument('<secret-name>', 'The name of secret in the environment')
15
- .argument('[files...]', 'Files this target will encrypt')
16
- .action(async (secretName, files) => {
13
+ .description('Add files to a target.')
14
+ .argument('<name>', 'The name of the target')
15
+ .argument('[files...]', 'Files that are encrypted')
16
+ .action(async (targetName, files) => {
17
17
  await updateConfig((config) => {
18
18
  try {
19
- getTargetFromConfig(config, secretName);
19
+ const target = getTargetFromConfig(config, targetName);
20
+ target.files.push(...files);
20
21
  }
21
22
  catch (err) {
22
- config.default_secret_name = secretName;
23
- config.targets.push({
24
- secret_name: secretName,
25
- files,
26
- });
27
- return true;
23
+ config.default_target_name = targetName;
24
+ config.targets[targetName] = { files };
28
25
  }
29
- console.error(`Target with the secret name already exists: ${secretName}`);
30
- console.error('Abort adding target');
31
- process.exit(1);
26
+ return true;
32
27
  });
33
28
  });
34
- function checkSecretName(secretName, defaultSecretName) {
35
- if (!secretName) {
36
- secretName = defaultSecretName;
29
+ program
30
+ .command('remove')
31
+ .description('Remove files from a target.')
32
+ .argument('<name>', 'The name of the target')
33
+ .argument('[files...]', 'Files to remove')
34
+ .option('-t, --target', 'Remove the target instead.')
35
+ .action(async (targetName, files, options) => {
36
+ if (options.target) {
37
+ // Remove the target
38
+ return await updateConfig((config) => {
39
+ getTargetFromConfig(config, targetName);
40
+ delete config.targets[targetName];
41
+ console.log(`[SUCCESS] Removed target: ${targetName}`);
42
+ return true;
43
+ });
37
44
  }
38
- if (!secretName) {
39
- throw new Error('No secret name given, and the default secret name is not set.');
45
+ // Remove files from the target
46
+ await updateConfig((config) => {
47
+ const target = getTargetFromConfig(config, targetName);
48
+ const removedFiles = [];
49
+ const remainingFiles = [];
50
+ for (const file of target.files) {
51
+ if (files.includes(file)) {
52
+ removedFiles.push(file);
53
+ console.log(`[SUCCESS] Removed file: ${file}`);
54
+ }
55
+ else {
56
+ remainingFiles.push(file);
57
+ }
58
+ }
59
+ target.files = remainingFiles;
60
+ const notFoundFiles = files.filter((it) => !removedFiles.includes(it));
61
+ for (const notFoundFile of notFoundFiles) {
62
+ console.log(`[WARNING] File not found in the target: ${notFoundFile}`);
63
+ }
64
+ return true;
65
+ });
66
+ });
67
+ function getTargetName(targetNameOrNull, defaultTargetName) {
68
+ const targetName = targetNameOrNull === null ? defaultTargetName : targetNameOrNull;
69
+ if (targetName === null) {
70
+ throw new Error('Target is not specified and the default target name is null!');
40
71
  }
41
- return secretName;
72
+ return targetName;
42
73
  }
43
74
  program
44
75
  .command('encrypt')
45
76
  .description('Encrypt the credential files.')
46
- .argument('[secret-name]', 'The name of secret in the environment', undefined)
47
- .action(async (secretName) => {
77
+ .argument('[target]', 'The name of the target', null)
78
+ .action(async (targetNameOrNull) => {
48
79
  await updateConfig((config) => {
49
- secretName = checkSecretName(secretName, config.default_secret_name);
50
- const target = getTargetFromConfig(config, secretName);
51
- const secret = getSecret(target.secret_name);
80
+ const targetName = getTargetName(targetNameOrNull, config.default_target_name);
81
+ const target = getTargetFromConfig(config, targetName);
82
+ const passphrase = getPassphrase(config, targetName);
52
83
  const srcFilePaths = target.files;
53
- fsExtra.ensureDir(TRICK_ENCRYPTED_DIR);
54
- encryptFiles(srcFilePaths, TRICK_ENCRYPTED_DIR, secret, config.iteration_count);
55
- return false;
84
+ fsExtra.ensureDir(config.root_directory);
85
+ encryptFiles(srcFilePaths, config.root_directory, passphrase, config.encryption.iteration_count);
56
86
  });
57
87
  });
58
88
  program
59
89
  .command('decrypt')
60
90
  .description('Decrypt the credential files.')
61
- .argument('[secret-name]', 'The name of secret in the environment', undefined)
62
- .action(async (secretName) => {
91
+ .argument('[target]', 'The name of the target', null)
92
+ .action(async (targetNameOrNull) => {
63
93
  await updateConfig((config) => {
64
- secretName = checkSecretName(secretName, config.default_secret_name);
65
- const target = getTargetFromConfig(config, secretName);
66
- const secret = getSecret(target.secret_name);
94
+ const targetName = getTargetName(targetNameOrNull, config.default_target_name);
95
+ const target = getTargetFromConfig(config, targetName);
96
+ const passphrase = getPassphrase(config, targetName);
67
97
  const srcFilePaths = target.files;
68
- fsExtra.ensureDir(TRICK_ENCRYPTED_DIR);
69
- decryptFiles(srcFilePaths, TRICK_ENCRYPTED_DIR, secret, config.iteration_count);
70
- return false;
98
+ fsExtra.ensureDir(config.root_directory);
99
+ decryptFiles(srcFilePaths, config.root_directory, passphrase, config.encryption.iteration_count);
71
100
  });
72
101
  });
73
102
  program
74
103
  .command('set-default')
75
- .description('Set the default secret name.')
76
- .argument('<secret-name>', 'The name of secret in the environment')
77
- .action(async (secretName) => {
104
+ .description('Set the default target name.')
105
+ .argument('<target>', 'The name of the target to set')
106
+ .action(async (targetName) => {
78
107
  await updateConfig((config) => {
79
- config.default_secret_name = secretName;
108
+ config.default_target_name = targetName;
80
109
  return true;
81
110
  });
82
111
  });
83
112
  program
84
113
  .command('get-default')
85
- .description('Get the default secret name.')
114
+ .description('Get the default target name.')
86
115
  .action(async () => {
87
116
  await updateConfig((config) => {
88
- console.log(config.default_secret_name);
89
- return false;
117
+ console.log(config.default_target_name);
90
118
  });
91
119
  });
92
120
  program
@@ -94,13 +122,12 @@ program
94
122
  .description('Display a list of targets.')
95
123
  .action(async () => {
96
124
  await updateConfig((config) => {
97
- for (const target of config.targets) {
98
- console.log(chalk.cyan(target.secret_name));
125
+ for (const [targetName, target] of Object.entries(config.targets)) {
126
+ console.log(chalk.cyan(targetName));
99
127
  for (const file of target.files) {
100
128
  console.log(' ' + chalk.yellow(file));
101
129
  }
102
130
  }
103
- return false;
104
131
  });
105
132
  });
106
133
  program.parse();
@@ -108,40 +135,3 @@ process.on('uncaughtException', (err) => {
108
135
  resolve_error(err);
109
136
  process.exit(1);
110
137
  });
111
- export function resolve_error(err) {
112
- if (!(err instanceof Error)) {
113
- console.error(`Unknown error: ${err}`);
114
- process.exit(2);
115
- }
116
- if (err instanceof WriteConfigError) {
117
- console.error(chalk.red('Fail to write Trick config file'));
118
- }
119
- else if (err instanceof ReadConfigError) {
120
- console.error(chalk.red('Fail to read Trick config file'));
121
- }
122
- else if (err instanceof SecretNotFoundError) {
123
- console.error(chalk.red(err.message));
124
- }
125
- else if (err instanceof TargetNotFoundError) {
126
- console.error(chalk.red(err.message));
127
- }
128
- else if (err instanceof FailToEncryptFileError) {
129
- console.error(chalk.red(err.message));
130
- if (err.opensslErrMessage) {
131
- console.error(chalk.red(err.opensslErrMessage));
132
- }
133
- else {
134
- console.error(chalk.yellow('Make sure the file exists and you have enough permission to access it'));
135
- }
136
- }
137
- else if (err instanceof FailToDecryptFileError) {
138
- console.error(chalk.red(err.message));
139
- if (err.opensslErrMessage) {
140
- console.error(chalk.red(err.opensslErrMessage));
141
- }
142
- else {
143
- console.error(chalk.yellow('Make sure the file exists and you have enough permission to access it'));
144
- }
145
- }
146
- process.exit(1);
147
- }
package/dist/config.d.ts CHANGED
@@ -1,23 +1,80 @@
1
+ /**
2
+ * The name of the configuration file to look for in the root directory.
3
+ */
1
4
  export declare const CONFIG_FILE_NAME: string;
5
+ /**
6
+ * Config type.
7
+ *
8
+ * @property targets Mapping from target names to target objects.
9
+ * @property default_target_name The name of the default target.
10
+ * @property root_directory The root directory.
11
+ * @property passphrase_file_path The path to the passphrase file.
12
+ * @property encryption Encryption configuration.
13
+ */
2
14
  export interface Config {
3
- iteration_count: number;
4
- default_secret_name?: string;
5
- targets: Target[];
15
+ targets: {
16
+ [name: string]: Target;
17
+ };
18
+ default_target_name: string | null;
19
+ root_directory: string;
20
+ passphrase_file_path: string;
21
+ encryption: Encryption;
6
22
  }
23
+ /**
24
+ * Target type.
25
+ *
26
+ * @property files A list of files to encrypt/decrypt.
27
+ */
7
28
  export interface Target {
8
- secret_name: string;
9
29
  files: string[];
10
30
  }
11
- export declare class WriteConfigError extends Error {
12
- }
13
- export declare class ReadConfigError extends Error {
31
+ /**
32
+ * Encryption configuration.
33
+ *
34
+ * @property iteration_count The number of iteration.
35
+ */
36
+ export interface Encryption {
37
+ iteration_count: number;
14
38
  }
39
+ /**
40
+ * Writes a configuration object to the configuration file.
41
+ *
42
+ * @param config The configuration to write.
43
+ * @throws {WriteConfigError} If error occurs when writing to the configuration
44
+ * file.
45
+ */
15
46
  export declare function writeConfig(config: Config): Promise<void>;
47
+ /**
48
+ * Retrieves the configuration object from the configuration file.
49
+ *
50
+ * @return The configuration object retrieved from the configuration object;
51
+ * null if the configuration file doesn't exist.
52
+ * @throws {ReadConfigError} If error occurs when reading the configuration
53
+ * file.
54
+ */
16
55
  export declare function readConfig(): Promise<Config | null>;
17
- export declare function updateConfig(callback: UpdateConfigCallback): Promise<void>;
18
- export type UpdateConfigCallback = (config: Config) => boolean;
19
- export declare class TargetNotFoundError extends Error {
20
- readonly secretName: string;
21
- constructor(secretName: string);
22
- }
23
- export declare function getTargetFromConfig(config: Config, secretName: string): Target;
56
+ /**
57
+ * Updates the configuration object.
58
+ *
59
+ * This function first retrieves the configuration object fromthe configuration
60
+ * file. If the configuration file doesn't exist, the default configuration will
61
+ * be used instead.
62
+ *
63
+ * Then it calls the callback function by passing on the configuration object.
64
+ * If the callback function returns `true`, then the object will be written to
65
+ * the configuration file.
66
+ *
67
+ * @param callback The callback function taking the configuraition object
68
+ * retrieved from the configuration file.
69
+ * @see DEFAULT_CONFIG
70
+ */
71
+ export declare function updateConfig(callback: (Config: Config) => boolean | void): Promise<void>;
72
+ /**
73
+ * Gets a target object from a specified configuration object.
74
+ *
75
+ * @param config The configuration object to get the target from.
76
+ * @param targetName The name of the target to get.
77
+ * @return The target object associated with the given name.
78
+ * @throws {TargetNotFoundError} If the target object is not found.
79
+ */
80
+ export declare function getTargetFromConfig(config: Config, targetName: string): Target;
package/dist/config.js CHANGED
@@ -1,21 +1,44 @@
1
1
  import fsExtra from 'fs-extra';
2
+ import { ReadConfigError, TargetNotFoundError, WriteConfigError, } from './error.js';
3
+ /**
4
+ * The name of the configuration file to look for in the root directory.
5
+ */
2
6
  export const CONFIG_FILE_NAME = 'trick.config.json';
3
- const defaultConfig = {
4
- iteration_count: 114514,
5
- targets: [],
7
+ /**
8
+ * Default configuration.
9
+ */
10
+ const DEFAULT_CONFIG = {
11
+ targets: {},
12
+ default_target_name: null,
13
+ root_directory: '.trick',
14
+ passphrase_file_path: '~/.config/trick_passphrase.json',
15
+ encryption: {
16
+ iteration_count: 0,
17
+ },
6
18
  };
7
- export class WriteConfigError extends Error {
8
- }
9
- export class ReadConfigError extends Error {
10
- }
19
+ /**
20
+ * Writes a configuration object to the configuration file.
21
+ *
22
+ * @param config The configuration to write.
23
+ * @throws {WriteConfigError} If error occurs when writing to the configuration
24
+ * file.
25
+ */
11
26
  export async function writeConfig(config) {
12
27
  try {
13
- await fsExtra.writeJson(CONFIG_FILE_NAME, config);
28
+ await fsExtra.writeFile(CONFIG_FILE_NAME, JSON.stringify(config, null, 2));
14
29
  }
15
30
  catch (err) {
16
- throw new WriteConfigError();
31
+ throw new WriteConfigError(err);
17
32
  }
18
33
  }
34
+ /**
35
+ * Retrieves the configuration object from the configuration file.
36
+ *
37
+ * @return The configuration object retrieved from the configuration object;
38
+ * null if the configuration file doesn't exist.
39
+ * @throws {ReadConfigError} If error occurs when reading the configuration
40
+ * file.
41
+ */
19
42
  export async function readConfig() {
20
43
  if (!fsExtra.existsSync(CONFIG_FILE_NAME)) {
21
44
  return null;
@@ -24,28 +47,42 @@ export async function readConfig() {
24
47
  return (await fsExtra.readJSON(CONFIG_FILE_NAME));
25
48
  }
26
49
  catch (err) {
27
- throw new ReadConfigError();
50
+ throw new ReadConfigError(err);
28
51
  }
29
52
  }
53
+ /**
54
+ * Updates the configuration object.
55
+ *
56
+ * This function first retrieves the configuration object fromthe configuration
57
+ * file. If the configuration file doesn't exist, the default configuration will
58
+ * be used instead.
59
+ *
60
+ * Then it calls the callback function by passing on the configuration object.
61
+ * If the callback function returns `true`, then the object will be written to
62
+ * the configuration file.
63
+ *
64
+ * @param callback The callback function taking the configuraition object
65
+ * retrieved from the configuration file.
66
+ * @see DEFAULT_CONFIG
67
+ */
30
68
  export async function updateConfig(callback) {
31
- const config = (await readConfig()) || defaultConfig;
69
+ const config = (await readConfig()) || DEFAULT_CONFIG;
32
70
  if (callback(config)) {
33
71
  await writeConfig(config);
34
72
  }
35
73
  }
36
- export class TargetNotFoundError extends Error {
37
- secretName;
38
- constructor(secretName) {
39
- super(`Target not found: ${secretName}`);
40
- this.secretName = secretName;
41
- }
42
- }
43
- export function getTargetFromConfig(config, secretName) {
44
- const targets = config.targets;
45
- for (const target of targets) {
46
- if (target.secret_name === secretName) {
47
- return target;
48
- }
74
+ /**
75
+ * Gets a target object from a specified configuration object.
76
+ *
77
+ * @param config The configuration object to get the target from.
78
+ * @param targetName The name of the target to get.
79
+ * @return The target object associated with the given name.
80
+ * @throws {TargetNotFoundError} If the target object is not found.
81
+ */
82
+ export function getTargetFromConfig(config, targetName) {
83
+ const target = config.targets[targetName];
84
+ if (!target) {
85
+ throw new TargetNotFoundError(targetName);
49
86
  }
50
- throw new TargetNotFoundError(secretName);
87
+ return target;
51
88
  }
package/dist/encrypt.d.ts CHANGED
@@ -1,14 +1,68 @@
1
- export declare class FailToEncryptFileError extends Error {
2
- readonly srcFilePath: string;
3
- readonly opensslErrMessage?: string | undefined;
4
- constructor(srcFilePath: string, opensslErrMessage?: string | undefined);
5
- }
6
- export declare class FailToDecryptFileError extends Error {
7
- readonly destFilePath: string;
8
- readonly opensslErrMessage?: string | undefined;
9
- constructor(destFilePath: string, opensslErrMessage?: string | undefined);
10
- }
11
- export declare function encryptFile(srcFilePath: string, destFilePath: string, secret: string, iteration_count: number): Promise<void>;
12
- export declare function decryptFile(srcFilePath: string, destFilePath: string, secret: string, iteration_count: number): Promise<void>;
13
- export declare function encryptFiles(srcFilePaths: string[], destDir: string, secret: string, iteration_count: number): Promise<void>;
14
- export declare function decryptFiles(srcFilePaths: string[], destDir: string, secret: string, iteration_count: number): Promise<void>;
1
+ /**
2
+ * Encrypts a file using OpenSSL with AES-256-CBC and PBKDF2 key derivation.
3
+ *
4
+ * This function checks whether the source file exists, constructs an OpenSSL
5
+ * command, ensures the destination directory exists, and then executes the
6
+ * encryption command.
7
+ *
8
+ * @param srcFilePath The path to the source file that needs to be encrypted.
9
+ * @param destFilePath The path where the encrypted file will be saved.
10
+ * @param passphrase The passphrase used for encryption.
11
+ * @param iteration_count The number of iterations to use for PBKDF2.
12
+ * @returns Resolves when the file is successfully encrypted.
13
+ * @throws {FailToEncryptFileError} If the source file does not exist or if
14
+ * OpenSSL returns an error during encryption.
15
+ * @throws {FailToDecryptFileError} If an unknown error occurs during
16
+ * encryption.
17
+ */
18
+ export declare function encryptFile(srcFilePath: string, destFilePath: string, passphrase: string, iteration_count: number): Promise<void>;
19
+ /**
20
+ * Decrypts a file using OpenSSL with AES-256-CBC and PBKDF2 key derivation.
21
+ *
22
+ * This function checks whether the encrypted file exists, constructs an OpenSSL
23
+ * decryption command, ensures the destination directory exists, and then
24
+ * executes the decryption command.
25
+ *
26
+ * @param srcFilePath The path where the decrypted file will be saved.
27
+ * @param destFilePath The path to the encrypted source file.
28
+ * @param passphrase The passphrase used for decryption.
29
+ * @param iteration_count The number of iterations used for PBKDF2.
30
+ * @returns Resolves when the file is successfully decrypted.
31
+ * @throws {FailToDecryptFileError} If the encrypted file does not exist or if
32
+ * OpenSSL returns an error during decryption.
33
+ * @throws {FailToDecryptFileError} If an unknown error occurs during
34
+ * decryption.
35
+ */
36
+ export declare function decryptFile(srcFilePath: string, destFilePath: string, passphrase: string, iteration_count: number): Promise<void>;
37
+ /**
38
+ * Encrypts multiple files using OpenSSL with AES-256-CBC and PBKDF2 key
39
+ * derivation.
40
+ *
41
+ * For each source file path provided, this function constructs the destination
42
+ * file path by appending `.enc`, then calls `encryptFile` and logs the
43
+ * operation.
44
+ *
45
+ * @param srcFilePaths An array of file paths to be encrypted.
46
+ * @param destDir The directory where the encrypted files will be saved.
47
+ * @param passphrase The passphrase used for encryption.
48
+ * @param iteration_count The number of iterations to use for PBKDF2.
49
+ * @returns Resolves when all files are successfully encrypted.
50
+ * @throws {FailToEncryptFileError} If any file fails to encrypt.
51
+ */
52
+ export declare function encryptFiles(srcFilePaths: string[], destDir: string, passphrase: string, iteration_count: number): Promise<void>;
53
+ /**
54
+ * Decrypts multiple files using OpenSSL with AES-256-CBC and PBKDF2 key
55
+ * derivation.
56
+ *
57
+ * For each source file path provided, this function assumes the corresponding
58
+ * encrypted file has the `.enc` extension and calls `decryptFile`, logging the
59
+ * operation.
60
+ *
61
+ * @param srcFilePaths An array of original file paths that were encrypted.
62
+ * @param destDir The directory containing the encrypted files.
63
+ * @param passphrase The passphrase used for decryption.
64
+ * @param iteration_count The number of iterations used for PBKDF2.
65
+ * @returns Resolves when all files are successfully decrypted.
66
+ * @throws {FailToDecryptFileError} If any file fails to decrypt.
67
+ */
68
+ export declare function decryptFiles(srcFilePaths: string[], destDir: string, passphrase: string, iteration_count: number): Promise<void>;