sdc-cli 1.0.2 → 1.1.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 (2) hide show
  1. package/cli.js +91 -11
  2. package/package.json +3 -2
package/cli.js CHANGED
@@ -6,6 +6,7 @@ import fs from 'fs/promises';
6
6
  import path from 'path';
7
7
  import { spawn } from 'child_process';
8
8
  import { fileURLToPath } from 'url';
9
+ import cliProgress from 'cli-progress';
9
10
 
10
11
  const __filename = fileURLToPath(import.meta.url);
11
12
  const __dirname = path.dirname(__filename);
@@ -19,7 +20,7 @@ class CryptCLI {
19
20
  program
20
21
  .name('sdc-cli')
21
22
  .description('A useful CLI in Node.js to use simple-data-crypto library')
22
- .version('1.0.0');
23
+ .version('1.1.0');
23
24
 
24
25
  // Encrypt command
25
26
  program
@@ -69,11 +70,11 @@ class CryptCLI {
69
70
 
70
71
  async getPassword(options, purpose = 'password') {
71
72
  // If password is provided via command line
72
- if (options.password) {
73
+ if (typeof options.password !== 'undefined') {
73
74
  //process.stderr.write(`Warning: Using password from command line is not secure\n`);
74
75
  return options.password;
75
76
  }
76
-
77
+
77
78
  // If password file is specified
78
79
  if (options.passwordFile) {
79
80
  try {
@@ -213,7 +214,10 @@ class CryptCLI {
213
214
  }
214
215
  ]);
215
216
 
216
- const password = await this.getPassword(options, 'password');
217
+ const password = await this.getPassword(options, 'password') || '';
218
+ if ('' === password) {
219
+ process.stderr.write('Warning: Using empty passwords is dangerous\n')
220
+ }
217
221
  const encrypted = await encrypt_data(answers.inputData, password);
218
222
 
219
223
  if (outputFile) {
@@ -228,9 +232,46 @@ class CryptCLI {
228
232
  const fileReader = await this.createFileReader(inputFile);
229
233
  const fileWriter = await this.createFileWriter(outputFile || '-');
230
234
  if (inputFile === '-' && (!options.passwordScript)) options.passwordScript = 'sdc-askpass';
231
- const password = await this.getPassword(options, 'password');
235
+ const password = await this.getPassword(options, 'password') || '';
236
+ if ('' === password) {
237
+ process.stderr.write('Warning: Using empty passwords is dangerous\n')
238
+ }
239
+
240
+ // Get file size for progress calculation
241
+ let totalBytes = 0;
242
+ if (inputFile !== '-') {
243
+ try {
244
+ const stats = await fs.stat(inputFile);
245
+ totalBytes = stats.size;
246
+ } catch (error) {
247
+ // If can't get file size, use unknown total
248
+ totalBytes = 0;
249
+ }
250
+ }
232
251
 
233
- const success = await encrypt_file(fileReader, fileWriter, password);
252
+ // Create progress bar for file encryption
253
+ const progressBar = new cliProgress.SingleBar({
254
+ format: 'Encrypting |{bar}| {percentage}% | {value}/{total} bytes',
255
+ barCompleteChar: '\u2588',
256
+ barIncompleteChar: '\u2591',
257
+ hideCursor: true
258
+ });
259
+
260
+ progressBar.start(totalBytes, 0);
261
+
262
+ const success = await encrypt_file(
263
+ fileReader,
264
+ fileWriter,
265
+ password,
266
+ (processedBytes) => {
267
+ progressBar.update(processedBytes);
268
+ }
269
+ );
270
+
271
+ if (totalBytes > 0) {
272
+ progressBar.update(totalBytes);
273
+ }
274
+ progressBar.stop();
234
275
 
235
276
  if (success) {
236
277
  if (outputFile) {
@@ -260,7 +301,7 @@ class CryptCLI {
260
301
  waitUserInput: false
261
302
  }
262
303
  ]);
263
- const password = await this.getPassword(options, 'password');
304
+ const password = await this.getPassword(options, 'password') || '';
264
305
 
265
306
  const decrypted = await decrypt_data(answers.inputData, password);
266
307
 
@@ -275,9 +316,44 @@ class CryptCLI {
275
316
  const fileReader = await this.createFileReader(inputFile);
276
317
  const fileWriter = await this.createFileWriter(outputFile || '-');
277
318
  if (inputFile === '-' && (!options.passwordScript)) options.passwordScript = 'sdc-askpass';
278
- const password = await this.getPassword(options, 'password');
319
+ const password = await this.getPassword(options, 'password') || '';
320
+
321
+ // Get file size for progress calculation
322
+ let totalBytes = 0;
323
+ if (inputFile !== '-') {
324
+ try {
325
+ const stats = await fs.stat(inputFile);
326
+ totalBytes = stats.size;
327
+ } catch (error) {
328
+ // If can't get file size, use unknown total
329
+ totalBytes = 0;
330
+ }
331
+ }
332
+
333
+ // Create progress bar for file decryption
334
+ const progressBar = new cliProgress.SingleBar({
335
+ format: 'Decrypting |{bar}| {percentage}% | {value}/{total} bytes',
336
+ barCompleteChar: '\u2588',
337
+ barIncompleteChar: '\u2591',
338
+ hideCursor: true
339
+ });
279
340
 
280
- const success = await decrypt_file(fileReader, fileWriter, password);
341
+ progressBar.start(totalBytes, 0);
342
+
343
+ const success = await decrypt_file(
344
+ fileReader,
345
+ fileWriter,
346
+ password,
347
+ (decryptedBytes, processedBytes) => {
348
+ // Use processedBytes (the bytes actually read from encrypted file)
349
+ progressBar.update(processedBytes || decryptedBytes);
350
+ }
351
+ );
352
+
353
+ if (totalBytes > 0) {
354
+ progressBar.update(totalBytes);
355
+ }
356
+ progressBar.stop();
281
357
 
282
358
  if (success) {
283
359
  if (outputFile) {
@@ -304,7 +380,7 @@ class CryptCLI {
304
380
  password: options.password,
305
381
  passwordFile: options.passwordFile,
306
382
  passwordScript: options.passwordScript
307
- }, 'current password');
383
+ }, 'current password') || '';
308
384
 
309
385
  // Get new password
310
386
  const newPassword = await this.getPassword({
@@ -312,7 +388,11 @@ class CryptCLI {
312
388
  passwordFile: options.newPasswordFile,
313
389
  passwordScript: options.newPasswordScript,
314
390
  skipConfirm: true
315
- }, 'new password');
391
+ }, 'new password') || '';
392
+
393
+ if ('' === newPassword) {
394
+ process.stderr.write('Warning: Using empty passwords is dangerous\n')
395
+ }
316
396
 
317
397
  // Read file header (first 5KB as recommended)
318
398
  let fileBuffer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-cli",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "A useful CLI in Node.js to use simple-data-crypto library",
5
5
  "keywords": [
6
6
  "encryption",
@@ -22,8 +22,9 @@
22
22
  "cli": "node cli.js"
23
23
  },
24
24
  "dependencies": {
25
+ "cli-progress": "^3.12.0",
25
26
  "commander": "^14.0.2",
26
27
  "inquirer": "^13.0.1",
27
- "simple-data-crypto": "^1.56.11"
28
+ "simple-data-crypto": "^1.100.0"
28
29
  }
29
30
  }