diff options
author | Matt Caswell <matt@openssl.org> | 2016-11-08 10:33:35 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-11-09 10:36:54 +0000 |
commit | 9b36b7d9bdb33d1edbc2bbfd8a773a0eb8645788 (patch) | |
tree | 668a1ea4172315f0ac08291bf9a44dc8bde80b8f /test/wpackettest.c | |
parent | 327c1627923288d3dbbfc34d1c7d8785552f6ad8 (diff) |
Add support for initialising WPACKETs from a static buffer
Normally WPACKETs will use a BUF_MEM which can grow as required. Sometimes
though that may be overkill for what is needed - a static buffer may be
sufficient. This adds that capability.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'test/wpackettest.c')
-rw-r--r-- | test/wpackettest.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/wpackettest.c b/test/wpackettest.c index aabf781952..e082b1822b 100644 --- a/test/wpackettest.c +++ b/test/wpackettest.c @@ -20,6 +20,7 @@ const static unsigned char seqsub[] = { 0x01, 0xff, 0x01, 0xff }; const static unsigned char empty = 0x00; const static unsigned char alloc[] = { 0x02, 0xfe, 0xff }; const static unsigned char submem[] = { 0x03, 0x02, 0xfe, 0xff }; +const static unsigned char fixed[] = { 0xff, 0xff, 0xff }; static BUF_MEM *buf; @@ -34,6 +35,7 @@ static int test_WPACKET_init(void) WPACKET pkt; int i; size_t written; + unsigned char sbuf[3]; if (!WPACKET_init(&pkt, buf) || !WPACKET_put_bytes_u8(&pkt, 0xff) @@ -95,6 +97,31 @@ static int test_WPACKET_init(void) return 0; } + /* Test initialising from a fixed size buffer */ + if (!WPACKET_init_static_len(&pkt, sbuf, sizeof(sbuf), 0) + /* Adding 3 bytes should succeed */ + || !WPACKET_put_bytes_u24(&pkt, 0xffffff) + /* Adding 1 more byte should fail */ + || WPACKET_put_bytes_u8(&pkt, 0xff) + /* Finishing the top level WPACKET should succeed */ + || !WPACKET_finish(&pkt) + || !WPACKET_get_total_written(&pkt, &written) + || written != sizeof(fixed) + || memcmp(sbuf, fixed, sizeof(sbuf)) != 0 + /* Initialise with 1 len byte */ + || !WPACKET_init_static_len(&pkt, sbuf, sizeof(sbuf), 1) + /* Adding 2 bytes should succeed */ + || !WPACKET_put_bytes_u16(&pkt, 0xfeff) + /* Adding 1 more byte should fail */ + || WPACKET_put_bytes_u8(&pkt, 0xff) + || !WPACKET_finish(&pkt) + || !WPACKET_get_total_written(&pkt, &written) + || written != sizeof(alloc) + || memcmp(sbuf, alloc, written) != 0) { + testfail("test_WPACKET_init():5 failed\n", &pkt); + return 0; + } + return 1; } |