1 /* $Id: test-tal.c,v 1.14 2024/04/22 05:54:01 claudio Exp $ */
2 /*
3 * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <assert.h>
19 #include <err.h>
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include <openssl/err.h>
27 #include <openssl/evp.h>
28 #include <openssl/x509v3.h>
29
30 #include "extern.h"
31
32 int outformats;
33 int verbose;
34 int filemode;
35 int experimental;
36
37 int
main(int argc,char * argv[])38 main(int argc, char *argv[])
39 {
40 int c, i, verb = 0;
41 char *buf;
42 size_t len;
43 struct tal *tal;
44
45 ERR_load_crypto_strings();
46 OpenSSL_add_all_ciphers();
47 OpenSSL_add_all_digests();
48
49 while ((c = getopt(argc, argv, "v")) != -1)
50 switch (c) {
51 case 'v':
52 verb++;
53 break;
54 default:
55 errx(1, "bad argument %c", c);
56 }
57
58 argv += optind;
59 argc -= optind;
60
61 if (argc == 0)
62 errx(1, "argument missing");
63
64 for (i = 0; i < argc; i++) {
65 buf = load_file(argv[i], &len);
66 tal = tal_parse(argv[i], buf, len);
67 free(buf);
68 if (tal == NULL)
69 break;
70 if (verb)
71 tal_print(tal);
72 tal_free(tal);
73 }
74
75 EVP_cleanup();
76 CRYPTO_cleanup_all_ex_data();
77 ERR_free_strings();
78
79 if (i < argc)
80 errx(1, "test failed for %s", argv[i]);
81
82 printf("OK\n");
83 return 0;
84 }
85
86 time_t
get_current_time(void)87 get_current_time(void)
88 {
89 return time(NULL);
90 }
91