diff options
author | jsing <> | 2021-06-27 16:40:25 +0000 |
---|---|---|
committer | jsing <> | 2021-06-27 16:40:25 +0000 |
commit | a2e788d74b3e0fbf66037bde6e1a270976a45b6b (patch) | |
tree | ea4820efbed88b7442f5960cf7a74dc7398ea831 /src/regress/lib/libssl/client/clienttest.c | |
parent | 3823b2ef1f4ed72a8ccd45a9a3b77c6902127d0f (diff) | |
download | openbsd-a2e788d74b3e0fbf66037bde6e1a270976a45b6b.tar.gz openbsd-a2e788d74b3e0fbf66037bde6e1a270976a45b6b.tar.bz2 openbsd-a2e788d74b3e0fbf66037bde6e1a270976a45b6b.zip |
Teach hexdump() how to identify differing bytes.
This allows differences between the received data and the test data to be
more readily identified.
Diffstat (limited to 'src/regress/lib/libssl/client/clienttest.c')
-rw-r--r-- | src/regress/lib/libssl/client/clienttest.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/regress/lib/libssl/client/clienttest.c b/src/regress/lib/libssl/client/clienttest.c index 86f6e2d6ca..2770e9559c 100644 --- a/src/regress/lib/libssl/client/clienttest.c +++ b/src/regress/lib/libssl/client/clienttest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: clienttest.c,v 1.30 2021/06/27 16:36:53 jsing Exp $ */ | 1 | /* $OpenBSD: clienttest.c,v 1.31 2021/06/27 16:40:25 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -289,13 +289,17 @@ static const struct client_hello_test client_hello_tests[] = { | |||
289 | (sizeof(client_hello_tests) / sizeof(*client_hello_tests)) | 289 | (sizeof(client_hello_tests) / sizeof(*client_hello_tests)) |
290 | 290 | ||
291 | static void | 291 | static void |
292 | hexdump(const uint8_t *buf, size_t len) | 292 | hexdump(const uint8_t *buf, size_t len, const uint8_t *compare) |
293 | { | 293 | { |
294 | const char *mark = ""; | ||
294 | size_t i; | 295 | size_t i; |
295 | 296 | ||
296 | for (i = 1; i <= len; i++) | 297 | for (i = 1; i <= len; i++) { |
297 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 && i != len ? "" : "\n"); | 298 | if (compare != NULL) |
298 | 299 | mark = (buf[i - 1] != compare[i - 1]) ? "*" : " "; | |
300 | fprintf(stderr, " %s0x%02hhx,%s", mark, buf[i - 1], | ||
301 | i % 8 && i != len ? "" : "\n"); | ||
302 | } | ||
299 | fprintf(stderr, "\n"); | 303 | fprintf(stderr, "\n"); |
300 | } | 304 | } |
301 | 305 | ||
@@ -428,9 +432,9 @@ client_hello_test(int testno, const struct client_hello_test *cht) | |||
428 | fprintf(stderr, "FAIL: test returned ClientHello length %li, " | 432 | fprintf(stderr, "FAIL: test returned ClientHello length %li, " |
429 | "want %zu\n", len, client_hello_len); | 433 | "want %zu\n", len, client_hello_len); |
430 | fprintf(stderr, "received:\n"); | 434 | fprintf(stderr, "received:\n"); |
431 | hexdump(wbuf, len); | 435 | hexdump(wbuf, len, NULL); |
432 | fprintf(stderr, "test data:\n"); | 436 | fprintf(stderr, "test data:\n"); |
433 | hexdump(client_hello, client_hello_len); | 437 | hexdump(client_hello, client_hello_len, NULL); |
434 | fprintf(stderr, "\n"); | 438 | fprintf(stderr, "\n"); |
435 | goto failure; | 439 | goto failure; |
436 | } | 440 | } |
@@ -447,9 +451,9 @@ client_hello_test(int testno, const struct client_hello_test *cht) | |||
447 | if (memcmp(client_hello, wbuf, client_hello_len) != 0) { | 451 | if (memcmp(client_hello, wbuf, client_hello_len) != 0) { |
448 | fprintf(stderr, "FAIL: ClientHello differs:\n"); | 452 | fprintf(stderr, "FAIL: ClientHello differs:\n"); |
449 | fprintf(stderr, "received:\n"); | 453 | fprintf(stderr, "received:\n"); |
450 | hexdump(wbuf, len); | 454 | hexdump(wbuf, len, client_hello); |
451 | fprintf(stderr, "test data:\n"); | 455 | fprintf(stderr, "test data:\n"); |
452 | hexdump(client_hello, client_hello_len); | 456 | hexdump(client_hello, client_hello_len, wbuf); |
453 | fprintf(stderr, "\n"); | 457 | fprintf(stderr, "\n"); |
454 | goto failure; | 458 | goto failure; |
455 | } | 459 | } |