@@ -66,7 +66,7 @@ void gen_iv(u8 *buf, int size)
66
66
while (-- size >= 0 ) buf [size ] += rand ();
67
67
}
68
68
69
- char vers [] = "1.31 " ;
69
+ char vers [] = "1.32 " ;
70
70
char msg1 [] = "The data is invalid: %s\n" ;
71
71
char msg2 [] = "The file already exists: %s\n" ;
72
72
@@ -264,6 +264,23 @@ int gen_key(char *dst, int pass) // keyfile name, pass true to request password
264
264
return 0 ;
265
265
}
266
266
267
+ int usage (int level )
268
+ {
269
+ printf ("usage:\n"
270
+ "\tdse <keyfile> [password]\n"
271
+ "\tdse <keyfile> <e | d> <source> <destination>\n"
272
+ "\tdse <-V | --version>\n"
273
+ "\tdse <-h | --help>\n" );
274
+ if (level > 0 )
275
+ {
276
+ printf ("examples:\n"
277
+ "\tdse mykey creates a random-content 32 bytes keyfile named mykey\n"
278
+ "\tdse mykey mypsw creates a 32 bytes keyfile from the password mypsw\n"
279
+ "\tdse mykey e data data.enc encryption\n"
280
+ "\tdse mykey d data.enc data decryption\n" );
281
+ }
282
+ return 0 ;
283
+ }
267
284
268
285
/*=====================================================================*/
269
286
@@ -277,9 +294,21 @@ int main(int argc, char *argv[])
277
294
printf ("dse %s\n" , vers );
278
295
return 0 ;
279
296
}
297
+ if (strcmp (argv [1 ], "-h" ) == 0 || strcmp (argv [1 ], "--help" ) == 0 )
298
+ {
299
+ usage (1 );
300
+ return 0 ;
301
+ }
302
+ if (argv [1 ][0 ] == '-' )
303
+ {
304
+ usage (0 );
305
+ return 1 ;
306
+ }
280
307
}
281
-
308
+ // key generator
282
309
if (argc == 2 || argc == 3 ) return gen_key (argv [1 ], argc == 3 );
310
+
311
+ // file encrypt or decrypt
283
312
if (argc == 5 )
284
313
{
285
314
* argv [2 ] = tolower (* argv [2 ]);
@@ -291,14 +320,6 @@ int main(int argc, char *argv[])
291
320
}
292
321
}
293
322
294
- printf ("usage:\n"
295
- "\tdse <keyfile> [password]\n"
296
- "\tdse <keyfile> <e | d> <source> <destination>\n"
297
- "\tdse <-V | --version>\n\n"
298
- "examples:\n"
299
- "\tdse mykey creates a random-content 32 bytes keyfile named mykey\n"
300
- "\tdse mykey mypsw creates a 32 bytes keyfile from the password mypsw\n"
301
- "\tdse mykey e data data.enc encryption\n"
302
- "\tdse mykey d data.enc data decryption\n" );
323
+ usage (0 );
303
324
return 1 ;
304
325
}
0 commit comments