1 // error handling for shallot
10 // help - how to use this stuff
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
);
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
) {
40 case X_REGEX_COMPILE
: {
41 fprintf(stderr
, "ERROR: Bad pattern. Try again with something else!\n");
45 case X_REGEX_INVALID
: {
46 fprintf(stderr
, "ERROR: Pattern cannot contain '-'.\n");
50 case X_SGNL_INT_TERM
: {
51 fprintf(stderr
, "\nCaught SIGINT/SIGTERM after %llu tries - exiting.\n",
56 case X_YOURE_UNLUCKY
: {
57 fprintf(stderr
, "\nERROR: You happened to find a bad key - congrats.\n");
61 case X_KEY_GEN_FAILS
: {
62 fprintf(stderr
, "ERROR: RSA Key Generation failed. This is bad.\n");
66 case X_THREAD_CREATE
: {
67 fprintf(stderr
, "ERROR: Failed to create thread. Terminating...\n");
71 case X_BIGNUM_FAILED
: {
72 fprintf(stderr
, "ERROR: Failed to covert uint64_t to BIGNUM.\n");
76 case X_INVALID_THRDS
: {
77 fprintf(stderr
, "ERROR: Invalid number of threads\n");
81 case X_EXCLUSIVE_OPT
: {
82 fprintf(stderr
, "ERROR: -m is incompatible with -f/-v\n");
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
);
92 case X_NEED_FILE_OUT
: {
93 fprintf(stderr
, "ERROR: -d requires -f <file>\n");
97 case X_FILE_OPEN_ERR
: {
98 fprintf(stderr
, "ERROR: Couldn't open file for output\n");
102 case X_DAEMON_FAILED
: {
103 fprintf(stderr
, "ERROR: Daemonization failed\n");
107 case X_OUT_OF_MEMORY
: {
108 fprintf(stderr
, "ERROR: Out of memory error.\n");
113 case X_SYSCTL_FAILED
: {
114 fprintf(stderr
, "ERROR: sysctlbyname failed.\n");
118 #elif defined(LINUX_PORT)
119 case X_BAD_FILE_DESC
: {
120 fprintf(stderr
, "ERROR: Couldn't open processor information.\n");
124 case X_ABNORMAL_READ
: {
125 fprintf(stderr
, "ERROR: Failed reading processor information.\n");
131 fprintf(stderr
, "Generic error. You should never see this...\n");