Add some tests for the newly added raw private/public key functions
[openssl.git] / test / wpackettest.c
index b2fa6504248d35257faedbf234803f5ca7498fae..b03dfcd2e04e42546b5ee62a1c722277c5f47b60 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -360,6 +360,8 @@ static int test_WPACKET_init_der(void)
     unsigned char testdata[] = { 0x00, 0x01, 0x02, 0x03 };
     unsigned char testdata2[259]  = { 0x82, 0x01, 0x00 };
     size_t written[2];
+    size_t size1, size2;
+    int flags = WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH;
     int i;
 
     /* Test initialising for writing DER */
@@ -370,6 +372,13 @@ static int test_WPACKET_init_der(void)
             || !TEST_true(WPACKET_memcpy(&pkt, testdata, sizeof(testdata)))
             || !TEST_true(WPACKET_close(&pkt))
             || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xfc))
+            /* this sub-packet is empty, and should render zero bytes */
+            || (!TEST_true(WPACKET_start_sub_packet(&pkt))
+                || !TEST_true(WPACKET_set_flags(&pkt, flags))
+                || !TEST_true(WPACKET_get_total_written(&pkt, &size1))
+                || !TEST_true(WPACKET_close(&pkt))
+                || !TEST_true(WPACKET_get_total_written(&pkt, &size2))
+                || !TEST_size_t_eq(size1, size2))
             || !TEST_true(WPACKET_finish(&pkt))
             || !TEST_true(WPACKET_get_total_written(&pkt, &written[0]))
             || !TEST_mem_eq(WPACKET_get_curr(&pkt), written[0], simpleder,