Remove the -v option.
[shallot/rransom.git] / src / error.c
blobf7c488e381e463e6b0d02eca940d4af7a490d8cf
1 // error handling for shallot
3 #include "error.h"
4 #include "globals.h"
5 #include "defines.h"
7 #include <stdio.h>
8 #include <stdlib.h>
10 // help - how to use this stuff
11 void usage(void) {
12 printf("Usage: shallot [-dmopv] [-f <file>] [-t count] [-e limit] pattern\n"
13 " -d : Daemonize (requires -f)\n"
14 " -m : Monitor mode (incompatible with -f)\n"
15 " -o : Optimize RSA key size to improve SHA-1 hashing speed\n"
16 " -p : Print 'pattern' help and exit (requires pattern)\n"
17 " -f <file> : Write output to <file>\n"
18 " -t count : Forces exactly count threads to be spawned\n"
19 " -e limit : Manually define the limit for e\n"
20 "Version: %s\n", VERSION);
21 exit(X_WRONG_NUMARGS);
24 void pattern(void) {
25 printf("base32 alphabet allows letters [a-z] and digits [2-7]\n"
26 "pattern can be a POSIX-style regular expression, e.g.\n"
27 " xxx must contain 'xxx'\n"
28 " bar$ must end with 'bar'\n"
29 " ^foo must begin with 'foo'\n"
30 " b[a4]r may contain leetspeech ;)\n"
31 " ^ab|^cd must begin with 'ab' or 'cd'\n"
32 " [a-z]{16} must contain letters only, no digits\n"
33 " ^dusk.*dawn$ must begin with 'dusk' and end with 'dawn'\n");
34 exit(X_WRONG_NUMARGS);
37 // our big error handling/reporting function
38 void error(int32_t code) {
39 switch(code) {
40 case X_REGEX_COMPILE: {
41 fprintf(stderr, "ERROR: Bad pattern. Try again with something else!\n");
42 break;
45 case X_REGEX_INVALID: {
46 fprintf(stderr, "ERROR: Pattern cannot contain '-'.\n");
47 break;
50 case X_SGNL_INT_TERM: {
51 fprintf(stderr, "\nCaught SIGINT/SIGTERM after %llu tries - exiting.\n",
52 loop);
53 break;
56 case X_YOURE_UNLUCKY: {
57 fprintf(stderr, "\nERROR: You happened to find a bad key - congrats.\n");
58 break;
61 case X_KEY_GEN_FAILS: {
62 fprintf(stderr, "ERROR: RSA Key Generation failed. This is bad.\n");
63 break;
66 case X_THREAD_CREATE: {
67 fprintf(stderr, "ERROR: Failed to create thread. Terminating...\n");
68 break;
71 case X_BIGNUM_FAILED: {
72 fprintf(stderr, "ERROR: Failed to covert uint64_t to BIGNUM.\n");
73 break;
76 case X_INVALID_THRDS: {
77 fprintf(stderr, "ERROR: Invalid number of threads\n");
78 break;
81 case X_EXCLUSIVE_OPT: {
82 fprintf(stderr, "ERROR: -m is incompatible with -f/-v\n");
83 break;
86 case X_INVALID_E_LIM: {
87 fprintf(stderr, "ERROR: e limit must be odd, >= %llu, and <= %llu\n",
88 RSA_PK_EXPONENT, MAXIMUM_E_LIMIT);
89 break;
92 case X_NEED_FILE_OUT: {
93 fprintf(stderr, "ERROR: -d requires -f <file>\n");
94 break;
97 case X_FILE_OPEN_ERR: {
98 fprintf(stderr, "ERROR: Couldn't open file for output\n");
99 break;
102 case X_DAEMON_FAILED: {
103 fprintf(stderr, "ERROR: Daemonization failed\n");
104 break;
107 case X_OUT_OF_MEMORY: {
108 fprintf(stderr, "ERROR: Out of memory error.\n");
109 break;
112 #ifdef BSD
113 case X_SYSCTL_FAILED: {
114 fprintf(stderr, "ERROR: sysctlbyname failed.\n");
115 break;
118 #elif defined(LINUX_PORT)
119 case X_BAD_FILE_DESC: {
120 fprintf(stderr, "ERROR: Couldn't open processor information.\n");
121 break;
124 case X_ABNORMAL_READ: {
125 fprintf(stderr, "ERROR: Failed reading processor information.\n");
126 break;
128 #endif
130 default: {
131 fprintf(stderr, "Generic error. You should never see this...\n");
132 break;
134 } // end switch
136 exit(code);