Add version and usage
This commit is contained in:
		
							parent
							
								
									9f6d1ecdeb
								
							
						
					
					
						commit
						a590d1842d
					
				
							
								
								
									
										39
									
								
								salty.c
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								salty.c
									
									
									
									
									
								
							| @ -10,6 +10,7 @@ | ||||
| #define KEY_SIZE crypto_secretbox_KEYBYTES | ||||
| #define SALT_SIZE crypto_pwhash_SALTBYTES | ||||
| #define BUF_SIZE 1024 | ||||
| #define VER "1.00" | ||||
| 
 | ||||
| bool stdinput = false; | ||||
| 
 | ||||
| @ -367,22 +368,36 @@ bool getPassword(char *pw, int size) { | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void printUsage() { | ||||
| 	fprintf(stderr,"\nUsage: salty [-d] -in [INPUT] -out [OUTPUT] [OPTIONS]\n"); | ||||
| 	fprintf(stderr,"Encrypts or decrypts a file with a password. When INPUT or OUTPUT are not set,\n"); | ||||
| 	fprintf(stderr,"or set to -, standard input or output is used respectively.\n\n"); | ||||
| 	fprintf(stderr,"Options:\n"); | ||||
| 	fprintf(stderr,"    -in\t\tTakes an input file\n"); | ||||
| 	fprintf(stderr,"    -out\tTakes an output file\n"); | ||||
| 	fprintf(stderr,"    -d\t\tEnable decryption mode\n"); | ||||
| 	fprintf(stderr,"    -key\tTakes a password, needed if reading from stdin\n"); | ||||
| 	fprintf(stderr,"    \t\tOtherwise this password is read from stdin itself\n"); | ||||
| 	fprintf(stderr,"    -v\t\tDisplays version information and exits\n"); | ||||
| 	fprintf(stderr,"    -h\t\tDisplays this help and exits\n"); | ||||
| } | ||||
| 
 | ||||
| int main(int argc, char *argv[]) { | ||||
|     setvbuf(stdout, NULL, _IONBF, 0); | ||||
| 	fprintf(stderr,"- NetPaws Salty - File Encryption Program\n"); | ||||
| 	fprintf(stderr,"- 2024 Ignacio Rivero\n\n"); | ||||
| 	fprintf(stderr,NOR"NetPaws Salty - File Encryption Program\n"); | ||||
| 	fprintf(stderr,NOR"2024 Ignacio Rivero\n"); | ||||
| 	// Initialize libsodium
 | ||||
| 	if (sodium_init() < 0) { | ||||
| 		fprintf(stderr,ERR"libsodium initialization failed! It is not safe to proceed.\n"); | ||||
| 		return 1; | ||||
| 	} | ||||
| 
 | ||||
| 	// Handle input, output and password arguments
 | ||||
| 	// Handle input, output, password, and other arguments
 | ||||
| 	int in = -1, out = -1, pass = -1; | ||||
| 	bool decrypt = false; | ||||
| 	 | ||||
| 	int i = 1, exit = 0; | ||||
| 	while (i < argc && exit == 0) { | ||||
| 	int i = 1, exit = -1; | ||||
| 	while (i < argc && exit == -1) { | ||||
| 		if (strcmp (argv[i],"-in") == 0) { | ||||
| 			if (i+1 >= argc) { | ||||
| 				fprintf(stderr,ERR"Argument -in requires a file.\n"); | ||||
| @ -429,6 +444,13 @@ int main(int argc, char *argv[]) { | ||||
| 			} | ||||
| 		} else if (strcmp (argv[i],"-d") == 0) { | ||||
| 			decrypt = true; | ||||
| 		} else if (strcmp (argv[i],"-v") == 0) { | ||||
| 			fprintf(stderr,NOR"Version %s\n",VER); | ||||
| 			exit = 0; | ||||
| 		} else if (strcmp (argv[i],"-h") == 0) { | ||||
| 			fprintf(stderr,NOR"Version %s\n",VER); | ||||
| 			printUsage(); | ||||
| 			exit = 0; | ||||
| 		} else { | ||||
| 			fprintf(stderr,ERR"Invalid argument: %s\n",argv[i]); | ||||
| 			exit = 1; | ||||
| @ -436,8 +458,13 @@ int main(int argc, char *argv[]) { | ||||
| 		i++; | ||||
| 	} | ||||
| 
 | ||||
| 	if (exit != 0) | ||||
| 	if (exit == 1) { | ||||
| 		printUsage(); | ||||
| 		return exit; | ||||
| 	} else if (exit != -1) | ||||
| 		return exit; | ||||
| 
 | ||||
| 	fprintf(stderr,"\n"); | ||||
| 
 | ||||
| 	// Set input and output filenames, or go to standard I/O if none
 | ||||
| 	char input[FILENAME_MAX]; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Ignacio Rivero
						Ignacio Rivero