diff options
author | David Walter Seikel | 2011-06-27 15:59:06 +1000 |
---|---|---|
committer | David Walter Seikel | 2011-06-27 15:59:06 +1000 |
commit | 92bd9b2503e7dd927f416cb9b17f169ea925fa56 (patch) | |
tree | f0f3776cfc0c6e6224db66f5678387c580095f16 /linden/indra/libgcrypt/libgcrypt-1.2.2/tests/tsexp.c | |
parent | Make use of the new packaging stuff from upstream. (diff) | |
download | meta-impy-92bd9b2503e7dd927f416cb9b17f169ea925fa56.zip meta-impy-92bd9b2503e7dd927f416cb9b17f169ea925fa56.tar.gz meta-impy-92bd9b2503e7dd927f416cb9b17f169ea925fa56.tar.bz2 meta-impy-92bd9b2503e7dd927f416cb9b17f169ea925fa56.tar.xz |
Clean up line endings, execute bits, and other bits of errant nonsense from Windows.
Diffstat (limited to 'linden/indra/libgcrypt/libgcrypt-1.2.2/tests/tsexp.c')
-rw-r--r--[-rwxr-xr-x] | linden/indra/libgcrypt/libgcrypt-1.2.2/tests/tsexp.c | 792 |
1 files changed, 396 insertions, 396 deletions
diff --git a/linden/indra/libgcrypt/libgcrypt-1.2.2/tests/tsexp.c b/linden/indra/libgcrypt/libgcrypt-1.2.2/tests/tsexp.c index 551ab68..54c9e81 100755..100644 --- a/linden/indra/libgcrypt/libgcrypt-1.2.2/tests/tsexp.c +++ b/linden/indra/libgcrypt/libgcrypt-1.2.2/tests/tsexp.c | |||
@@ -1,396 +1,396 @@ | |||
1 | /* tsexp.c - S-expression regression tests | 1 | /* tsexp.c - S-expression regression tests |
2 | * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. | 2 | * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. |
3 | * | 3 | * |
4 | * This file is part of Libgcrypt. | 4 | * This file is part of Libgcrypt. |
5 | * | 5 | * |
6 | * Libgcrypt is free software; you can redistribute it and/or modify | 6 | * Libgcrypt is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU Lesser General Public License as | 7 | * it under the terms of the GNU Lesser General Public License as |
8 | * published by the Free Software Foundation; either version 2.1 of | 8 | * published by the Free Software Foundation; either version 2.1 of |
9 | * the License, or (at your option) any later version. | 9 | * the License, or (at your option) any later version. |
10 | * | 10 | * |
11 | * Libgcrypt is distributed in the hope that it will be useful, | 11 | * Libgcrypt is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU Lesser General Public License for more details. | 14 | * GNU Lesser General Public License for more details. |
15 | * | 15 | * |
16 | * You should have received a copy of the GNU Lesser General Public | 16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this program; if not, write to the Free Software | 17 | * License along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <stdarg.h> | 24 | #include <stdarg.h> |
25 | #include "../src/gcrypt.h" | 25 | #include "../src/gcrypt.h" |
26 | 26 | ||
27 | #define PGMNAME "tsexp" | 27 | #define PGMNAME "tsexp" |
28 | 28 | ||
29 | static int verbose; | 29 | static int verbose; |
30 | static int error_count; | 30 | static int error_count; |
31 | 31 | ||
32 | static void | 32 | static void |
33 | info (const char *format, ...) | 33 | info (const char *format, ...) |
34 | { | 34 | { |
35 | va_list arg_ptr; | 35 | va_list arg_ptr; |
36 | 36 | ||
37 | if (verbose) | 37 | if (verbose) |
38 | { | 38 | { |
39 | va_start( arg_ptr, format ) ; | 39 | va_start( arg_ptr, format ) ; |
40 | vfprintf (stderr, format, arg_ptr ); | 40 | vfprintf (stderr, format, arg_ptr ); |
41 | va_end(arg_ptr); | 41 | va_end(arg_ptr); |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
45 | static void | 45 | static void |
46 | fail ( const char *format, ... ) | 46 | fail ( const char *format, ... ) |
47 | { | 47 | { |
48 | va_list arg_ptr ; | 48 | va_list arg_ptr ; |
49 | 49 | ||
50 | fputs (PGMNAME ": ", stderr); | 50 | fputs (PGMNAME ": ", stderr); |
51 | va_start( arg_ptr, format ) ; | 51 | va_start( arg_ptr, format ) ; |
52 | vfprintf (stderr, format, arg_ptr ); | 52 | vfprintf (stderr, format, arg_ptr ); |
53 | va_end(arg_ptr); | 53 | va_end(arg_ptr); |
54 | error_count++; | 54 | error_count++; |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | /* fixme: we need better tests */ | 58 | /* fixme: we need better tests */ |
59 | static void | 59 | static void |
60 | basic (void) | 60 | basic (void) |
61 | { | 61 | { |
62 | int pass; | 62 | int pass; |
63 | gcry_sexp_t sexp; | 63 | gcry_sexp_t sexp; |
64 | int idx; | 64 | int idx; |
65 | char *secure_buffer; | 65 | char *secure_buffer; |
66 | size_t secure_buffer_len; | 66 | size_t secure_buffer_len; |
67 | const char *string; | 67 | const char *string; |
68 | static struct { | 68 | static struct { |
69 | const char *token; | 69 | const char *token; |
70 | const char *parm; | 70 | const char *parm; |
71 | } values[] = { | 71 | } values[] = { |
72 | { "public-key", NULL }, | 72 | { "public-key", NULL }, |
73 | { "dsa", NULL }, | 73 | { "dsa", NULL }, |
74 | { "dsa", "p" }, | 74 | { "dsa", "p" }, |
75 | { "dsa", "y" }, | 75 | { "dsa", "y" }, |
76 | { "dsa", "q" }, | 76 | { "dsa", "q" }, |
77 | { "dsa", "g" }, | 77 | { "dsa", "g" }, |
78 | { NULL } | 78 | { NULL } |
79 | }; | 79 | }; |
80 | 80 | ||
81 | info ("doing some pretty pointless tests\n"); | 81 | info ("doing some pretty pointless tests\n"); |
82 | 82 | ||
83 | secure_buffer_len = 99; | 83 | secure_buffer_len = 99; |
84 | secure_buffer = gcry_xmalloc_secure (secure_buffer_len); | 84 | secure_buffer = gcry_xmalloc_secure (secure_buffer_len); |
85 | memset (secure_buffer, 'G', secure_buffer_len); | 85 | memset (secure_buffer, 'G', secure_buffer_len); |
86 | 86 | ||
87 | for (pass=0;;pass++) | 87 | for (pass=0;;pass++) |
88 | { | 88 | { |
89 | switch (pass) | 89 | switch (pass) |
90 | { | 90 | { |
91 | case 0: | 91 | case 0: |
92 | string = ("(public-key (dsa (p #41424344#) (y this_is_y) " | 92 | string = ("(public-key (dsa (p #41424344#) (y this_is_y) " |
93 | "(q #61626364656667#) (g %m)))"); | 93 | "(q #61626364656667#) (g %m)))"); |
94 | 94 | ||
95 | if ( gcry_sexp_build (&sexp, NULL, string, | 95 | if ( gcry_sexp_build (&sexp, NULL, string, |
96 | gcry_mpi_set_ui (NULL, 42)) ) | 96 | gcry_mpi_set_ui (NULL, 42)) ) |
97 | { | 97 | { |
98 | fail (" scanning `%s' failed\n", string); | 98 | fail (" scanning `%s' failed\n", string); |
99 | return; | 99 | return; |
100 | } | 100 | } |
101 | break; | 101 | break; |
102 | 102 | ||
103 | case 1: | 103 | case 1: |
104 | string = ("(public-key (dsa (p #41424344#) (y this_is_y) " | 104 | string = ("(public-key (dsa (p #41424344#) (y this_is_y) " |
105 | "(q %b) (g %m)))"); | 105 | "(q %b) (g %m)))"); |
106 | 106 | ||
107 | if ( gcry_sexp_build (&sexp, NULL, string, | 107 | if ( gcry_sexp_build (&sexp, NULL, string, |
108 | 15, "foo\0\x01\0x02789012345", | 108 | 15, "foo\0\x01\0x02789012345", |
109 | gcry_mpi_set_ui (NULL, 42)) ) | 109 | gcry_mpi_set_ui (NULL, 42)) ) |
110 | { | 110 | { |
111 | fail (" scanning `%s' failed\n", string); | 111 | fail (" scanning `%s' failed\n", string); |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | break; | 114 | break; |
115 | 115 | ||
116 | case 2: | 116 | case 2: |
117 | string = ("(public-key (dsa (p #41424344#) (y silly_y_value) " | 117 | string = ("(public-key (dsa (p #41424344#) (y silly_y_value) " |
118 | "(q %b) (g %m)))"); | 118 | "(q %b) (g %m)))"); |
119 | 119 | ||
120 | if ( gcry_sexp_build (&sexp, NULL, string, | 120 | if ( gcry_sexp_build (&sexp, NULL, string, |
121 | secure_buffer_len, secure_buffer, | 121 | secure_buffer_len, secure_buffer, |
122 | gcry_mpi_set_ui (NULL, 17)) ) | 122 | gcry_mpi_set_ui (NULL, 17)) ) |
123 | { | 123 | { |
124 | fail (" scanning `%s' failed\n", string); | 124 | fail (" scanning `%s' failed\n", string); |
125 | return; | 125 | return; |
126 | } | 126 | } |
127 | if (!gcry_is_secure (sexp)) | 127 | if (!gcry_is_secure (sexp)) |
128 | fail ("gcry_sexp_build did not switch to secure memory\n"); | 128 | fail ("gcry_sexp_build did not switch to secure memory\n"); |
129 | break; | 129 | break; |
130 | 130 | ||
131 | default: | 131 | default: |
132 | return; /* Ready. */ | 132 | return; /* Ready. */ |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | /* now find something */ | 136 | /* now find something */ |
137 | for (idx=0; values[idx].token; idx++) | 137 | for (idx=0; values[idx].token; idx++) |
138 | { | 138 | { |
139 | const char *token = values[idx].token; | 139 | const char *token = values[idx].token; |
140 | const char *parm = values[idx].parm; | 140 | const char *parm = values[idx].parm; |
141 | gcry_sexp_t s1, s2; | 141 | gcry_sexp_t s1, s2; |
142 | gcry_mpi_t a; | 142 | gcry_mpi_t a; |
143 | const char *p; | 143 | const char *p; |
144 | size_t n; | 144 | size_t n; |
145 | 145 | ||
146 | s1 = gcry_sexp_find_token (sexp, token, strlen(token) ); | 146 | s1 = gcry_sexp_find_token (sexp, token, strlen(token) ); |
147 | if (!s1) | 147 | if (!s1) |
148 | { | 148 | { |
149 | fail ("didn't found `%s'\n", token); | 149 | fail ("didn't found `%s'\n", token); |
150 | continue; | 150 | continue; |
151 | } | 151 | } |
152 | 152 | ||
153 | p = gcry_sexp_nth_data (s1, 0, &n); | 153 | p = gcry_sexp_nth_data (s1, 0, &n); |
154 | if (!p) | 154 | if (!p) |
155 | { | 155 | { |
156 | fail ("no car for `%s'\n", token); | 156 | fail ("no car for `%s'\n", token); |
157 | continue; | 157 | continue; |
158 | } | 158 | } |
159 | info ("car=`%.*s'\n", (int)n, p); | 159 | info ("car=`%.*s'\n", (int)n, p); |
160 | 160 | ||
161 | s2 = gcry_sexp_cdr (s1); | 161 | s2 = gcry_sexp_cdr (s1); |
162 | if (!s2) | 162 | if (!s2) |
163 | { | 163 | { |
164 | fail ("no cdr for `%s'\n", token); | 164 | fail ("no cdr for `%s'\n", token); |
165 | continue; | 165 | continue; |
166 | } | 166 | } |
167 | 167 | ||
168 | p = gcry_sexp_nth_data (s2, 0, &n); | 168 | p = gcry_sexp_nth_data (s2, 0, &n); |
169 | if (p) | 169 | if (p) |
170 | { | 170 | { |
171 | fail ("data at car of `%s'\n", token); | 171 | fail ("data at car of `%s'\n", token); |
172 | continue; | 172 | continue; |
173 | } | 173 | } |
174 | 174 | ||
175 | if (parm) | 175 | if (parm) |
176 | { | 176 | { |
177 | s2 = gcry_sexp_find_token (s1, parm, strlen (parm)); | 177 | s2 = gcry_sexp_find_token (s1, parm, strlen (parm)); |
178 | if (!s2) | 178 | if (!s2) |
179 | { | 179 | { |
180 | fail ("didn't found `%s'\n", parm); | 180 | fail ("didn't found `%s'\n", parm); |
181 | continue; | 181 | continue; |
182 | } | 182 | } |
183 | p = gcry_sexp_nth_data (s2, 0, &n); | 183 | p = gcry_sexp_nth_data (s2, 0, &n); |
184 | if (!p) | 184 | if (!p) |
185 | { | 185 | { |
186 | fail("no car for `%s'\n", parm ); | 186 | fail("no car for `%s'\n", parm ); |
187 | continue; | 187 | continue; |
188 | } | 188 | } |
189 | info ("car=`%.*s'\n", (int)n, p); | 189 | info ("car=`%.*s'\n", (int)n, p); |
190 | p = gcry_sexp_nth_data (s2, 1, &n); | 190 | p = gcry_sexp_nth_data (s2, 1, &n); |
191 | if (!p) | 191 | if (!p) |
192 | { | 192 | { |
193 | fail("no cdr for `%s'\n", parm ); | 193 | fail("no cdr for `%s'\n", parm ); |
194 | continue; | 194 | continue; |
195 | } | 195 | } |
196 | info ("cdr=`%.*s'\n", (int)n, p); | 196 | info ("cdr=`%.*s'\n", (int)n, p); |
197 | 197 | ||
198 | a = gcry_sexp_nth_mpi (s2, 0, GCRYMPI_FMT_USG); | 198 | a = gcry_sexp_nth_mpi (s2, 0, GCRYMPI_FMT_USG); |
199 | if (!a) | 199 | if (!a) |
200 | { | 200 | { |
201 | fail("failed to cdr the mpi for `%s'\n", parm); | 201 | fail("failed to cdr the mpi for `%s'\n", parm); |
202 | continue; | 202 | continue; |
203 | } | 203 | } |
204 | } | 204 | } |
205 | } | 205 | } |
206 | 206 | ||
207 | gcry_sexp_release (sexp); | 207 | gcry_sexp_release (sexp); |
208 | sexp = NULL; | 208 | sexp = NULL; |
209 | } | 209 | } |
210 | gcry_free (secure_buffer); | 210 | gcry_free (secure_buffer); |
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | static void | 214 | static void |
215 | canon_len (void) | 215 | canon_len (void) |
216 | { | 216 | { |
217 | static struct { | 217 | static struct { |
218 | size_t textlen; /* length of the buffer */ | 218 | size_t textlen; /* length of the buffer */ |
219 | size_t expected;/* expected length or 0 on error and then ... */ | 219 | size_t expected;/* expected length or 0 on error and then ... */ |
220 | size_t erroff; /* ... and at this offset */ | 220 | size_t erroff; /* ... and at this offset */ |
221 | gcry_error_t errcode; /* ... with this error code */ | 221 | gcry_error_t errcode; /* ... with this error code */ |
222 | char *text; | 222 | char *text; |
223 | } values[] = { | 223 | } values[] = { |
224 | { 14, 13, 0, GPG_ERR_NO_ERROR, "(9:abcdefghi) " }, | 224 | { 14, 13, 0, GPG_ERR_NO_ERROR, "(9:abcdefghi) " }, |
225 | { 16, 15, 0, GPG_ERR_NO_ERROR, "(10:abcdefghix)" }, | 225 | { 16, 15, 0, GPG_ERR_NO_ERROR, "(10:abcdefghix)" }, |
226 | { 14, 0,14, GPG_ERR_SEXP_STRING_TOO_LONG, "(10:abcdefghi)" }, | 226 | { 14, 0,14, GPG_ERR_SEXP_STRING_TOO_LONG, "(10:abcdefghi)" }, |
227 | { 15, 0, 1, GPG_ERR_SEXP_ZERO_PREFIX, "(010:abcdefghi)" }, | 227 | { 15, 0, 1, GPG_ERR_SEXP_ZERO_PREFIX, "(010:abcdefghi)" }, |
228 | { 2, 0, 0, GPG_ERR_SEXP_NOT_CANONICAL, "1:"}, | 228 | { 2, 0, 0, GPG_ERR_SEXP_NOT_CANONICAL, "1:"}, |
229 | { 4, 0, 4, GPG_ERR_SEXP_STRING_TOO_LONG, "(1:)"}, | 229 | { 4, 0, 4, GPG_ERR_SEXP_STRING_TOO_LONG, "(1:)"}, |
230 | { 5, 5, 0, GPG_ERR_NO_ERROR, "(1:x)"}, | 230 | { 5, 5, 0, GPG_ERR_NO_ERROR, "(1:x)"}, |
231 | { 2, 2, 0, GPG_ERR_NO_ERROR, "()"}, | 231 | { 2, 2, 0, GPG_ERR_NO_ERROR, "()"}, |
232 | { 4, 2, 0, GPG_ERR_NO_ERROR, "()()"}, | 232 | { 4, 2, 0, GPG_ERR_NO_ERROR, "()()"}, |
233 | { 4, 4, 0, GPG_ERR_NO_ERROR, "(())"}, | 233 | { 4, 4, 0, GPG_ERR_NO_ERROR, "(())"}, |
234 | { 3, 0, 3, GPG_ERR_SEXP_STRING_TOO_LONG, "(()"}, | 234 | { 3, 0, 3, GPG_ERR_SEXP_STRING_TOO_LONG, "(()"}, |
235 | { 3, 0, 1, GPG_ERR_SEXP_BAD_CHARACTER, "( )"}, | 235 | { 3, 0, 1, GPG_ERR_SEXP_BAD_CHARACTER, "( )"}, |
236 | { 9, 9, 0, GPG_ERR_NO_ERROR, "(3:abc())"}, | 236 | { 9, 9, 0, GPG_ERR_NO_ERROR, "(3:abc())"}, |
237 | { 10, 0, 6, GPG_ERR_SEXP_BAD_CHARACTER, "(3:abc ())"}, | 237 | { 10, 0, 6, GPG_ERR_SEXP_BAD_CHARACTER, "(3:abc ())"}, |
238 | /* fixme: we need much more cases */ | 238 | /* fixme: we need much more cases */ |
239 | { 0 }, | 239 | { 0 }, |
240 | }; | 240 | }; |
241 | int idx; | 241 | int idx; |
242 | gcry_error_t errcode; | 242 | gcry_error_t errcode; |
243 | size_t n, erroff; | 243 | size_t n, erroff; |
244 | 244 | ||
245 | info ("checking canoncial length test function\n"); | 245 | info ("checking canoncial length test function\n"); |
246 | for (idx=0; values[idx].text; idx++) | 246 | for (idx=0; values[idx].text; idx++) |
247 | { | 247 | { |
248 | n = gcry_sexp_canon_len ((const unsigned char*)values[idx].text, | 248 | n = gcry_sexp_canon_len ((const unsigned char*)values[idx].text, |
249 | values[idx].textlen, | 249 | values[idx].textlen, |
250 | &erroff, &errcode); | 250 | &erroff, &errcode); |
251 | 251 | ||
252 | if (n && n == values[idx].expected) | 252 | if (n && n == values[idx].expected) |
253 | ; /* success */ | 253 | ; /* success */ |
254 | else if (!n && !values[idx].expected) | 254 | else if (!n && !values[idx].expected) |
255 | { /* we expected an error - check that this is the right one */ | 255 | { /* we expected an error - check that this is the right one */ |
256 | if (values[idx].erroff != erroff) | 256 | if (values[idx].erroff != erroff) |
257 | fail ("canonical length test %d - wrong error offset %u\n", | 257 | fail ("canonical length test %d - wrong error offset %u\n", |
258 | idx, (unsigned int)erroff); | 258 | idx, (unsigned int)erroff); |
259 | if (gcry_err_code (errcode) != values[idx].errcode) | 259 | if (gcry_err_code (errcode) != values[idx].errcode) |
260 | fail ("canonical length test %d - wrong error code %d\n", | 260 | fail ("canonical length test %d - wrong error code %d\n", |
261 | idx, errcode); | 261 | idx, errcode); |
262 | } | 262 | } |
263 | else | 263 | else |
264 | fail ("canonical length test %d failed - n=%u, off=%u, err=%d\n", | 264 | fail ("canonical length test %d failed - n=%u, off=%u, err=%d\n", |
265 | idx, (unsigned int)n, (unsigned int)erroff, errcode); | 265 | idx, (unsigned int)n, (unsigned int)erroff, errcode); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | 269 | ||
270 | static void | 270 | static void |
271 | back_and_forth_one (int testno, const char *buffer, size_t length) | 271 | back_and_forth_one (int testno, const char *buffer, size_t length) |
272 | { | 272 | { |
273 | gcry_error_t rc; | 273 | gcry_error_t rc; |
274 | gcry_sexp_t se, se1; | 274 | gcry_sexp_t se, se1; |
275 | size_t n, n1; | 275 | size_t n, n1; |
276 | char *p1; | 276 | char *p1; |
277 | 277 | ||
278 | rc = gcry_sexp_new (&se, buffer, length, 1); | 278 | rc = gcry_sexp_new (&se, buffer, length, 1); |
279 | if (rc) | 279 | if (rc) |
280 | { | 280 | { |
281 | fail ("baf %d: gcry_sexp_new failed: %s\n", testno, gpg_strerror (rc)); | 281 | fail ("baf %d: gcry_sexp_new failed: %s\n", testno, gpg_strerror (rc)); |
282 | return; | 282 | return; |
283 | } | 283 | } |
284 | n1 = gcry_sexp_sprint (se, GCRYSEXP_FMT_CANON, NULL, 0); | 284 | n1 = gcry_sexp_sprint (se, GCRYSEXP_FMT_CANON, NULL, 0); |
285 | if (!n1) | 285 | if (!n1) |
286 | { | 286 | { |
287 | fail ("baf %d: get required length for canon failed\n", testno); | 287 | fail ("baf %d: get required length for canon failed\n", testno); |
288 | return; | 288 | return; |
289 | } | 289 | } |
290 | p1 = gcry_xmalloc (n1); | 290 | p1 = gcry_xmalloc (n1); |
291 | n = gcry_sexp_sprint (se, GCRYSEXP_FMT_CANON, p1, n1); | 291 | n = gcry_sexp_sprint (se, GCRYSEXP_FMT_CANON, p1, n1); |
292 | if (n1 != n+1) /* sprints adds an extra 0 but dies not return it */ | 292 | if (n1 != n+1) /* sprints adds an extra 0 but dies not return it */ |
293 | { | 293 | { |
294 | fail ("baf %d: length mismatch for canon\n", testno); | 294 | fail ("baf %d: length mismatch for canon\n", testno); |
295 | return; | 295 | return; |
296 | } | 296 | } |
297 | rc = gcry_sexp_create (&se1, p1, n, 0, gcry_free); | 297 | rc = gcry_sexp_create (&se1, p1, n, 0, gcry_free); |
298 | if (rc) | 298 | if (rc) |
299 | { | 299 | { |
300 | fail ("baf %d: gcry_sexp_create failed: %s\n", | 300 | fail ("baf %d: gcry_sexp_create failed: %s\n", |
301 | testno, gpg_strerror (rc)); | 301 | testno, gpg_strerror (rc)); |
302 | return; | 302 | return; |
303 | } | 303 | } |
304 | gcry_sexp_release (se1); | 304 | gcry_sexp_release (se1); |
305 | 305 | ||
306 | /* FIXME: we need a lot more tests */ | 306 | /* FIXME: we need a lot more tests */ |
307 | 307 | ||
308 | gcry_sexp_release (se); | 308 | gcry_sexp_release (se); |
309 | } | 309 | } |
310 | 310 | ||
311 | 311 | ||
312 | 312 | ||
313 | static void | 313 | static void |
314 | back_and_forth (void) | 314 | back_and_forth (void) |
315 | { | 315 | { |
316 | static struct { char *buf; int len; } tests[] = { | 316 | static struct { char *buf; int len; } tests[] = { |
317 | { "(7:g34:fgh1::2:())", 0 }, | 317 | { "(7:g34:fgh1::2:())", 0 }, |
318 | { "(7:g34:fgh1::2:())", 18 }, | 318 | { "(7:g34:fgh1::2:())", 18 }, |
319 | { NULL, 0 } | 319 | { NULL, 0 } |
320 | }; | 320 | }; |
321 | int idx; | 321 | int idx; |
322 | 322 | ||
323 | for (idx=0; tests[idx].buf; idx++) | 323 | for (idx=0; tests[idx].buf; idx++) |
324 | back_and_forth_one (idx, tests[idx].buf, tests[idx].len); | 324 | back_and_forth_one (idx, tests[idx].buf, tests[idx].len); |
325 | } | 325 | } |
326 | 326 | ||
327 | 327 | ||
328 | static void | 328 | static void |
329 | check_sscan (void) | 329 | check_sscan (void) |
330 | { | 330 | { |
331 | static struct { | 331 | static struct { |
332 | const char *text; | 332 | const char *text; |
333 | gcry_error_t expected_err; | 333 | gcry_error_t expected_err; |
334 | } values[] = { | 334 | } values[] = { |
335 | /* Bug reported by Olivier L'Heureux 2003-10-07 */ | 335 | /* Bug reported by Olivier L'Heureux 2003-10-07 */ |
336 | { "(7:sig-val(3:dsa" | 336 | { "(7:sig-val(3:dsa" |
337 | "(1:r20:\x7e\xff\xd5\xba\xc9\xc9\xa4\x9b\xd4\x26\x8b\x64" | 337 | "(1:r20:\x7e\xff\xd5\xba\xc9\xc9\xa4\x9b\xd4\x26\x8b\x64" |
338 | "\x06\x7a\xcf\x42\x7b\x6c\x51\xfb)" | 338 | "\x06\x7a\xcf\x42\x7b\x6c\x51\xfb)" |
339 | "(1:s21:\x01\x8c\x6c\x6f\x37\x1a\x8d\xfd\x5a\xb3\x2a\x3d" | 339 | "(1:s21:\x01\x8c\x6c\x6f\x37\x1a\x8d\xfd\x5a\xb3\x2a\x3d" |
340 | "\xc5\xae\x23\xed\x32\x62\x30\x62\x3e)))", | 340 | "\xc5\xae\x23\xed\x32\x62\x30\x62\x3e)))", |
341 | GPG_ERR_NO_ERROR }, | 341 | GPG_ERR_NO_ERROR }, |
342 | { "(7:sig-val(3:dsa" | 342 | { "(7:sig-val(3:dsa" |
343 | "(1:r20:\x7e\xff\xd5\xba\xc9\xc9\xa4\x9b\xd4\x26\x8b\x64" | 343 | "(1:r20:\x7e\xff\xd5\xba\xc9\xc9\xa4\x9b\xd4\x26\x8b\x64" |
344 | "\x06\x7a\xcf\x42\x7b\x6c\x51\xfb)" | 344 | "\x06\x7a\xcf\x42\x7b\x6c\x51\xfb)" |
345 | "(1:s21:\x01\x8c\x6c\x6f\x37\x1a\x8d\xfd\x5a\xb3\x2a\x3d" | 345 | "(1:s21:\x01\x8c\x6c\x6f\x37\x1a\x8d\xfd\x5a\xb3\x2a\x3d" |
346 | "\xc5\xae\x23\xed\x32\x62\x30\x62\x3e))", | 346 | "\xc5\xae\x23\xed\x32\x62\x30\x62\x3e))", |
347 | GPG_ERR_SEXP_UNMATCHED_PAREN }, | 347 | GPG_ERR_SEXP_UNMATCHED_PAREN }, |
348 | { "(7:sig-val(3:dsa" | 348 | { "(7:sig-val(3:dsa" |
349 | "(1:r20:\x7e\xff\xd5\xba\xc9\xc9\xa4\x9b\xd4\x26\x8b\x64" | 349 | "(1:r20:\x7e\xff\xd5\xba\xc9\xc9\xa4\x9b\xd4\x26\x8b\x64" |
350 | "\x06\x7a\xcf\x42\x7b\x6c\x51\xfb)" | 350 | "\x06\x7a\xcf\x42\x7b\x6c\x51\xfb)" |
351 | "(1:s21:\x01\x8c\x6c\x6f\x37\x1a\x8d\xfd\x5a\xb3\x2a\x3d" | 351 | "(1:s21:\x01\x8c\x6c\x6f\x37\x1a\x8d\xfd\x5a\xb3\x2a\x3d" |
352 | "\xc5\xae\x23\xed\x32\x62\x30\x62\x3e))))", | 352 | "\xc5\xae\x23\xed\x32\x62\x30\x62\x3e))))", |
353 | GPG_ERR_SEXP_UNMATCHED_PAREN }, | 353 | GPG_ERR_SEXP_UNMATCHED_PAREN }, |
354 | { NULL, 0 } | 354 | { NULL, 0 } |
355 | }; | 355 | }; |
356 | int idx; | 356 | int idx; |
357 | gcry_error_t err; | 357 | gcry_error_t err; |
358 | gcry_sexp_t s; | 358 | gcry_sexp_t s; |
359 | 359 | ||
360 | info ("checking gcry_sexp_sscan\n"); | 360 | info ("checking gcry_sexp_sscan\n"); |
361 | for (idx=0; values[idx].text; idx++) | 361 | for (idx=0; values[idx].text; idx++) |
362 | { | 362 | { |
363 | err = gcry_sexp_sscan (&s, NULL, | 363 | err = gcry_sexp_sscan (&s, NULL, |
364 | values[idx].text, | 364 | values[idx].text, |
365 | strlen (values[idx].text)); | 365 | strlen (values[idx].text)); |
366 | if (gpg_err_code (err) != values[idx].expected_err) | 366 | if (gpg_err_code (err) != values[idx].expected_err) |
367 | fail ("gcry_sexp_sscan test %d failed: %s\n", idx, gpg_strerror (err)); | 367 | fail ("gcry_sexp_sscan test %d failed: %s\n", idx, gpg_strerror (err)); |
368 | gcry_sexp_release (s); | 368 | gcry_sexp_release (s); |
369 | } | 369 | } |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | 373 | ||
374 | 374 | ||
375 | int | 375 | int |
376 | main (int argc, char **argv) | 376 | main (int argc, char **argv) |
377 | { | 377 | { |
378 | if (argc > 1 && !strcmp (argv[1], "-v")) | 378 | if (argc > 1 && !strcmp (argv[1], "-v")) |
379 | verbose = 1; | 379 | verbose = 1; |
380 | 380 | ||
381 | gcry_control (GCRYCTL_DISABLE_SECMEM_WARN); | 381 | gcry_control (GCRYCTL_DISABLE_SECMEM_WARN); |
382 | gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0); | 382 | gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0); |
383 | 383 | ||
384 | basic (); | 384 | basic (); |
385 | canon_len (); | 385 | canon_len (); |
386 | back_and_forth (); | 386 | back_and_forth (); |
387 | check_sscan (); | 387 | check_sscan (); |
388 | 388 | ||
389 | return error_count? 1:0; | 389 | return error_count? 1:0; |
390 | } | 390 | } |
391 | 391 | ||
392 | 392 | ||
393 | 393 | ||
394 | 394 | ||
395 | 395 | ||
396 | 396 | ||