1e71b7053SJung-uk Kim /*
2e71b7053SJung-uk Kim * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
374664626SKris Kennaway *
4b077aed3SPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use
5e71b7053SJung-uk Kim * this file except in compliance with the License. You can obtain a copy
6e71b7053SJung-uk Kim * in the file LICENSE in the source distribution or at
7e71b7053SJung-uk Kim * https://www.openssl.org/source/license.html
874664626SKris Kennaway */
974664626SKris Kennaway
1074664626SKris Kennaway #include <stdio.h>
1174664626SKris Kennaway #include <stdlib.h>
1274664626SKris Kennaway #include <string.h>
1374664626SKris Kennaway #include "apps.h"
14e71b7053SJung-uk Kim #include "progs.h"
1574664626SKris Kennaway #include <openssl/bio.h>
1674664626SKris Kennaway #include <openssl/err.h>
1774664626SKris Kennaway #include <openssl/ssl.h>
1874664626SKris Kennaway
19e71b7053SJung-uk Kim typedef enum OPTION_choice {
20e71b7053SJung-uk Kim OPT_ERR = -1, OPT_EOF = 0, OPT_HELP
21e71b7053SJung-uk Kim } OPTION_CHOICE;
2274664626SKris Kennaway
23e71b7053SJung-uk Kim const OPTIONS errstr_options[] = {
24e71b7053SJung-uk Kim {OPT_HELP_STR, 1, '-', "Usage: %s [options] errnum...\n"},
25b077aed3SPierre Pronchery
26b077aed3SPierre Pronchery OPT_SECTION("General"),
27e71b7053SJung-uk Kim {"help", OPT_HELP, '-', "Display this summary"},
28b077aed3SPierre Pronchery
29b077aed3SPierre Pronchery OPT_PARAMETERS(),
30b077aed3SPierre Pronchery {"errnum", 0, 0, "Error number(s) to decode"},
31e71b7053SJung-uk Kim {NULL}
32e71b7053SJung-uk Kim };
33f579bf8eSKris Kennaway
errstr_main(int argc,char ** argv)34e71b7053SJung-uk Kim int errstr_main(int argc, char **argv)
3574664626SKris Kennaway {
36e71b7053SJung-uk Kim OPTION_CHOICE o;
37e71b7053SJung-uk Kim char buf[256], *prog;
38e71b7053SJung-uk Kim int ret = 1;
3974664626SKris Kennaway unsigned long l;
4074664626SKris Kennaway
41e71b7053SJung-uk Kim prog = opt_init(argc, argv, errstr_options);
42e71b7053SJung-uk Kim while ((o = opt_next()) != OPT_EOF) {
43e71b7053SJung-uk Kim switch (o) {
44e71b7053SJung-uk Kim case OPT_EOF:
45e71b7053SJung-uk Kim case OPT_ERR:
46e71b7053SJung-uk Kim BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
47e71b7053SJung-uk Kim goto end;
48e71b7053SJung-uk Kim case OPT_HELP:
49e71b7053SJung-uk Kim opt_help(errstr_options);
50e71b7053SJung-uk Kim ret = 0;
51e71b7053SJung-uk Kim goto end;
52ddd58736SKris Kennaway }
5374664626SKris Kennaway }
5474664626SKris Kennaway
55b077aed3SPierre Pronchery /*
56b077aed3SPierre Pronchery * We're not really an SSL application so this won't auto-init, but
57e71b7053SJung-uk Kim * we're still interested in SSL error strings
58e71b7053SJung-uk Kim */
59e71b7053SJung-uk Kim OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS
60e71b7053SJung-uk Kim | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
61b077aed3SPierre Pronchery
62b077aed3SPierre Pronchery /* All remaining arg are error code. */
63b077aed3SPierre Pronchery ret = 0;
64b077aed3SPierre Pronchery for (argv = opt_rest(); *argv != NULL; argv++) {
65*e0c4386eSCy Schubert if (sscanf(*argv, "%lx", &l) <= 0) {
66b077aed3SPierre Pronchery ret++;
67b077aed3SPierre Pronchery } else {
68e71b7053SJung-uk Kim ERR_error_string_n(l, buf, sizeof(buf));
69e71b7053SJung-uk Kim BIO_printf(bio_out, "%s\n", buf);
7074664626SKris Kennaway }
7174664626SKris Kennaway }
72e71b7053SJung-uk Kim end:
73e71b7053SJung-uk Kim return ret;
7474664626SKris Kennaway }
75