1 /*	$Id: test-tal.c,v 1.13 2023/06/20 12:52:32 job 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 
36 int
37 main(int argc, char *argv[])
38 {
39 	int		 c, i, verb = 0;
40 	char		*buf;
41 	size_t		 len;
42 	struct tal	*tal;
43 
44 	ERR_load_crypto_strings();
45 	OpenSSL_add_all_ciphers();
46 	OpenSSL_add_all_digests();
47 
48 	while ((c = getopt(argc, argv, "v")) != -1)
49 		switch (c) {
50 		case 'v':
51 			verb++;
52 			break;
53 		default:
54 			errx(1, "bad argument %c", c);
55 		}
56 
57 	argv += optind;
58 	argc -= optind;
59 
60 	if (argc == 0)
61 		errx(1, "argument missing");
62 
63 	for (i = 0; i < argc; i++) {
64 		buf = load_file(argv[i], &len);
65 		tal = tal_parse(argv[i], buf, len);
66 		free(buf);
67 		if (tal == NULL)
68 			break;
69 		if (verb)
70 			tal_print(tal);
71 		tal_free(tal);
72 	}
73 
74 	EVP_cleanup();
75 	CRYPTO_cleanup_all_ex_data();
76 	ERR_free_strings();
77 
78 	if (i < argc)
79 		errx(1, "test failed for %s", argv[i]);
80 
81 	printf("OK\n");
82 	return 0;
83 }
84 
85 time_t
86 get_current_time(void)
87 {
88 	return time(NULL);
89 }
90