aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests/otp-data-dump.c
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2023-01-17 11:21:01 -0900
committerDavid M. Syzdek <david@syzdek.net>2023-01-17 11:21:01 -0900
commit4370c8aaf8d1ee9e078696c16a016557fdfe8be4 (patch)
tree97ec47d90ea42a651c63e63fc99e394542d7f69c /tests/otp-data-dump.c
parent169310b7bfce5e45c1abfaf4938e3176c70597d2 (diff)
downloadotputils-4370c8aaf8d1ee9e078696c16a016557fdfe8be4.tar.gz
otputils-4370c8aaf8d1ee9e078696c16a016557fdfe8be4.tar.bz2
otputils-4370c8aaf8d1ee9e078696c16a016557fdfe8be4.tar.xz
otputils-4370c8aaf8d1ee9e078696c16a016557fdfe8be4.zip
tests: adding test-otputil-otp.sh
Diffstat (limited to 'tests/otp-data-dump.c')
-rw-r--r--tests/otp-data-dump.c239
1 files changed, 239 insertions, 0 deletions
diff --git a/tests/otp-data-dump.c b/tests/otp-data-dump.c
new file mode 100644
index 0000000..d4da2d8
--- /dev/null
+++ b/tests/otp-data-dump.c
@@ -0,0 +1,239 @@
1/*
2 * OTP Utilities
3 * Copyright (C) 2022 David M. Syzdek <david@syzdek.net>.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of David M. Syzdek nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M SYZDEK BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30/*
31 * @file tests/otp-data-dump.c
32 */
33#define _TESTS_OTP_DATA_DUMP_C 1
34
35///////////////
36// //
37// Headers //
38// //
39///////////////
40#pragma mark - Headers
41
42#include <otputil_compat.h>
43
44#ifdef HAVE_CONFIG_H
45# include <config.h>
46#endif
47
48#include <errno.h>
49#include <assert.h>
50#include <getopt.h>
51#include <stdio.h>
52#include <string.h>
53#include <strings.h>
54#include <inttypes.h>
55
56#include <otputil.h>
57
58#include "otp-data.h"
59
60
61///////////////////
62// //
63// Definitions //
64// //
65///////////////////
66#pragma mark - Definitions
67
68#ifndef PROGRAM_NAME
69#define PROGRAM_NAME "otp-data-dump"
70#endif
71#ifndef PACKAGE_BUGREPORT
72#define PACKAGE_BUGREPORT "david@syzdek.net"
73#endif
74#ifndef PACKAGE_COPYRIGHT
75#define PACKAGE_COPYRIGHT ""
76#endif
77#ifndef PACKAGE_NAME
78#define PACKAGE_NAME ""
79#endif
80#ifndef PACKAGE_VERSION
81#define PACKAGE_VERSION ""
82#endif
83
84
85/////////////////
86// //
87// Variables //
88// //
89/////////////////
90#pragma mark - Variables
91
92static int verbose = 0;
93static int quiet = 0;
94
95
96//////////////////
97// //
98// Prototypes //
99// //
100//////////////////
101#pragma mark - Prototypes
102
103int
104main(
105 int argc,
106 char * argv[] );
107
108
109/////////////////
110// //
111// Functions //
112// //
113/////////////////
114#pragma mark - Functions
115
116int
117main(
118 int argc,
119 char * argv[] )
120{
121 int c;
122 int opt_index;
123 int pos;
124 int len_hash;
125 int len_pass;
126 int len_seed;
127 int len_hex;
128 int len_six;
129 int len_alt;
130 int len;
131 const char * str;
132 const otptest_t * rec;
133
134 // getopt options
135 static const char * short_opt = "hqVv";
136 static struct option long_opt[] =
137 {
138 {"help", no_argument, NULL, 'h' },
139 {"quiet", no_argument, NULL, 'q' },
140 {"silent", no_argument, NULL, 'q' },
141 {"version", no_argument, NULL, 'V' },
142 {"verbose", no_argument, NULL, 'v' },
143 { NULL, 0, NULL, 0 }
144 };
145
146 while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1)
147 {
148 switch(c)
149 {
150 case -1: /* no more arguments */
151 case 0: /* long options toggles */
152 break;
153
154 case 'h':
155 printf("Usage: %s [OPTIONS]\n", PROGRAM_NAME);
156 printf("OPTIONS:\n");
157 printf(" -h, --help print this help and exit\n");
158 printf(" -q, --quiet, --silent do not print messages\n");
159 printf(" -V, --version print version number and exit\n");
160 printf(" -v, --verbose print verbose messages\n");
161 printf("\n");
162 return(0);
163
164 case 'q':
165 quiet++;
166 break;
167
168 case 'V':
169 printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION);
170 printf("Written by David M. Syzdek.\n");
171 return(0);
172
173 case 'v':
174 verbose++;
175 break;
176
177 case '?':
178 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
179 return(1);
180
181 default:
182 fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c);
183 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
184 return(1);
185 };
186 };
187
188 len_hash = 0;
189 len_pass = 0;
190 len_seed = 0;
191 len_hex = 0;
192 len_six = 0;
193 len_alt = 0;
194 for(pos = 0; ((otp_test_data[pos].pass)); pos++)
195 {
196 rec = &otp_test_data[pos];
197 str = otputil_md2str(rec->method);
198 len_hash = ((len = (int)strlen(str)) > len_hash) ? len : len_hash;
199 len_pass = ((len = (int)strlen(rec->pass)) > len_pass) ? len : len_pass;
200 len_seed = ((len = (int)strlen(rec->seed)) > len_seed) ? len : len_seed;
201 len_hex = ((len = (int)strlen(rec->hex)) > len_hex) ? len : len_hex;
202 len_six = ((len = (int)strlen(rec->six)) > len_six) ? len : len_six;
203 len_alt = ((len = (int)strlen(rec->alt_md4)) > len_alt) ? len : len_alt;
204 len_alt = ((len = (int)strlen(rec->alt_md5)) > len_alt) ? len : len_alt;
205 len_alt = ((len = (int)strlen(rec->alt_sha1)) > len_alt) ? len : len_alt;
206 };
207 len_hash++;
208 len_pass++;
209 len_seed++;
210 len_hex++;
211 len_six++;
212 len_alt++;
213
214 for(pos = 0; ((otp_test_data[pos].pass)); pos++)
215 {
216 rec = &otp_test_data[pos];
217 str = otputil_md2str(rec->method);
218 printf("%-*s:", len_hash, str);
219 printf("%-*s:", len_pass, rec->pass);
220 printf("%-*s:", len_seed, rec->seed);
221 printf("%-3i:", rec->count);
222 printf("%-*s:", len_hex, rec->hex);
223 printf("%-*s:", len_six, rec->six);
224 switch(rec->method)
225 {
226 case OTPUTIL_MD_MD4: str = rec->alt_md4; break;
227 case OTPUTIL_MD_MD5: str = rec->alt_md5; break;
228 case OTPUTIL_MD_SHA1: str = rec->alt_sha1; break;
229 default: str = ""; break;
230 };
231 printf("%-*s:", len_alt, str);
232 printf("\n");
233 };
234
235 return(0);
236}
237
238
239/* end of source file */