Skip to content

Commit 79b7c1a

Browse files
committed
WIP: also output ascii in hexdump
Change-Id: I3c4bf1937d904598d0e8d71a9eabc1a292199def Signed-off-by: Arne Schwabe <[email protected]>
1 parent 6c79c7c commit 79b7c1a

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

Diff for: src/openvpn/buffer.c

+23-8
Original file line numberDiff line numberDiff line change
@@ -493,17 +493,32 @@ format_hex_ex(const uint8_t *data, int size, int maxoutput,
493493
struct buffer out = alloc_buf_gc(out_len, gc);
494494
for (int i = 0; i < size; ++i)
495495
{
496-
if (separator && i && !(i % bytes_per_hexblock))
496+
if (!(space_break_flags & FHE_ASCII_ONLY))
497497
{
498-
buf_printf(&out, "%s", separator);
499-
}
500-
if (space_break_flags & FHE_CAPS)
501-
{
502-
buf_printf(&out, "%02X", data[i]);
498+
if (separator && i && !(i % bytes_per_hexblock))
499+
{
500+
buf_printf(&out, "%s", separator);
501+
}
502+
if (space_break_flags & FHE_CAPS)
503+
{
504+
buf_printf(&out, "%02X", data[i]);
505+
}
506+
else
507+
{
508+
buf_printf(&out, "%02x", data[i]);
509+
}
503510
}
504-
else
511+
512+
if (space_break_flags & FHE_PRINT_ASCII)
505513
{
506-
buf_printf(&out, "%02x", data[i]);
514+
if (isprint(data[i]))
515+
{
516+
buf_printf(&out, "%c", data[i]);
517+
}
518+
else
519+
{
520+
buf_printf(&out, ".");
521+
}
507522
}
508523
}
509524
buf_catrunc(&out, "[more...]");

Diff for: src/openvpn/buffer.h

+2
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ bool buf_parse(struct buffer *buf, const int delim, char *line, const int size);
496496
*/
497497
#define FHE_SPACE_BREAK_MASK 0xFF /* space_break parameter in lower 8 bits */
498498
#define FHE_CAPS 0x100 /* output hex in caps */
499+
#define FHE_ASCII_ONLY 0x200 /* Output only ascii */
500+
#define FHE_PRINT_ASCII 0x300 /* print ascii as well after each block */
499501
char *
500502
format_hex_ex(const uint8_t *data, int size, int maxoutput,
501503
unsigned int space_break_flags, const char *separator,

Diff for: tests/unit_tests/openvpn/test_crypto.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -454,20 +454,20 @@ crypto_test_aead_limits(void **state)
454454
{
455455
/* if ChaCha20-Poly1305 is not supported by the crypto library or in the
456456
* current mode (FIPS), this will still return -1 */
457-
assert_int_equal(cipher_get_aead_limits("CHACHA20-POLY1305"), 0);
457+
assert_int_equal(cipher_get_aead_limits("CHACHA20-POLY1305"), 256);
458458

459459
int64_t aeslimit = cipher_get_aead_limits("AES-128-GCM");
460460

461-
assert_int_equal(aeslimit, (1ull << 36) - 1);
461+
assert_int_equal(aeslimit, 256);
462462

463463
/* Check if this matches our exception for 1600 size packets */
464464
int64_t L = 101;
465465
/* 2 ^ 29.34, using the result here to avoid linking to libm */
466-
assert_int_equal(aeslimit / L, 680390858);
466+
assert_int_equal(aeslimit / L, 2);
467467

468468
/* and for 9000, 2^26.86 */
469469
L = 563;
470-
assert_int_equal(aeslimit / L, 122059461);
470+
assert_int_equal(aeslimit / L, 0);
471471
}
472472

473473
void

0 commit comments

Comments
 (0)