1 /* t-common.h - Common functions for the tests.
2 * Copyright (C) 2002, 2003 g10 Code GmbH
4 * This file is part of KSBA.
6 * KSBA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * KSBA is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 void sha1_hash_buffer (char *outbuf, const char *buffer, size_t length);
25 #define digitp(p) (*(p) >= '0' && *(p) <= '9')
27 #define fail_if_err(a) do { if(a) { \
28 fprintf (stderr, "%s:%d: KSBA error: %s\n", \
29 __FILE__, __LINE__, gpg_strerror(a)); \
34 #define fail_if_err2(f, a) do { if(a) {\
35 fprintf (stderr, "%s:%d: KSBA error on file `%s': %s\n", \
36 __FILE__, __LINE__, (f), gpg_strerror(a)); \
40 #define fail(s) do { fprintf (stderr, "%s:%d: %s\n", __FILE__,__LINE__, (s));\
43 #define xfree(a) ksba_free (a)
49 char *p = ksba_malloc (n);
52 fprintf (stderr, "out of core\n");
59 /* Prepend FNAME with the srcdir environment variable's value and
60 retrun an allocated filename. */
62 prepend_srcdir (const char *fname)
64 static const char *srcdir;
68 if(!(srcdir = getenv ("srcdir")))
71 result = xmalloc (strlen (srcdir) + 1 + strlen (fname) + 1);
72 strcpy (result, srcdir);
74 strcat (result, fname);
81 print_hex (const unsigned char *p, size_t n)
84 fputs ("none", stdout);
94 print_sexp (ksba_const_sexp_t p)
99 fputs ("[none]", stdout);
117 else if (!digitp (p))
119 fputs ("[invalid s-exp]", stdout);
125 const unsigned char *s;
126 unsigned long len, n;
128 len = strtoul (p, &endp, 10);
132 fputs ("[invalid s-exp]", stdout);
136 for (s=p,n=0; n < len; n++, s++)
137 if ( !((*s >= 'a' && *s <= 'z')
138 || (*s >= 'A' && *s <= 'Z')
139 || (*s >= '0' && *s <= '9')
140 || *s == '-' || *s == '.'))
145 for (n=0; n < len; n++, p++)
151 for (n=0; n < len; n++, p++)
159 /* Variant of print_sexp which forces printing the values in hex. */
161 print_sexp_hex (ksba_const_sexp_t p)
166 fputs ("[none]", stdout);
184 else if (!digitp (p))
186 fputs ("[invalid s-exp]", stdout);
192 unsigned long len, n;
194 len = strtoul (p, &endp, 10);
198 fputs ("[invalid s-exp]", stdout);
203 for (n=0; n < len; n++, p++)
216 fputs ("error", stdout);
223 print_time (ksba_isotime_t t)
226 fputs ("none", stdout);
228 printf ("%.4s-%.2s-%.2s %.2s:%.2s:%s", t, t+4, t+6, t+9, t+11, t+13);