X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=test%2Fpemtest.c;h=8c9e04297a49d22da4264ba46f969a699c58ba1e;hb=4f2271d58a36b2aee125062ffb9626c6208fa394;hp=dfef80d7cd2df76d38d75d07a4e685a3c64d37d1;hpb=ad887416f1e59c3294a7d8f83a0ca77120523b4a;p=oweals%2Fopenssl.git diff --git a/test/pemtest.c b/test/pemtest.c index dfef80d7cd..8c9e04297a 100644 --- a/test/pemtest.c +++ b/test/pemtest.c @@ -1,7 +1,7 @@ /* - * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * 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 * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html @@ -12,18 +12,31 @@ #include #include "testutil.h" +#include "internal/nelem.h" -static const char raw[] = "hello world"; -static const char encoded[] = "aGVsbG8gd29ybGQ="; -static const char pemtype[] = "PEMTESTDATA"; +typedef struct { + const char *raw; + const char *encoded; +} TESTDATA; -static int test_b64(void) +static TESTDATA b64_pem_data[] = { + { "hello world", + "aGVsbG8gd29ybGQ=" }, + { "a very ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong input", + "YSB2ZXJ5IG9vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29uZyBpbnB1dA==" } +}; + +static const char *pemtype = "PEMTESTDATA"; + +static int test_b64(int idx) { BIO *b = BIO_new(BIO_s_mem()); char *name = NULL, *header = NULL; unsigned char *data = NULL; long len; int ret = 0; + const char *raw = b64_pem_data[idx].raw; + const char *encoded = b64_pem_data[idx].encoded; if (!TEST_ptr(b) || !TEST_true(BIO_printf(b, "-----BEGIN %s-----\n", pemtype)) @@ -32,9 +45,9 @@ static int test_b64(void) || !TEST_true(PEM_read_bio_ex(b, &name, &header, &data, &len, PEM_FLAG_ONLY_B64))) goto err; - if (!TEST_int_eq(memcmp(pemtype, name, sizeof(pemtype) - 1), 0) - || !TEST_int_eq(len,sizeof(raw) - 1) - || !TEST_int_eq(memcmp(data, raw, sizeof(raw) - 1), 0)) + if (!TEST_int_eq(memcmp(pemtype, name, strlen(pemtype)), 0) + || !TEST_int_eq(len, strlen(raw)) + || !TEST_int_eq(memcmp(data, raw, strlen(raw)), 0)) goto err; ret = 1; err: @@ -51,6 +64,7 @@ static int test_invalid(void) char *name = NULL, *header = NULL; unsigned char *data = NULL; long len; + const char *encoded = b64_pem_data[0].encoded; if (!TEST_ptr(b) || !TEST_true(BIO_printf(b, "-----BEGIN %s-----\n", pemtype)) @@ -71,7 +85,7 @@ static int test_invalid(void) int setup_tests(void) { - ADD_TEST(test_b64); + ADD_ALL_TESTS(test_b64, OSSL_NELEM(b64_pem_data)); ADD_TEST(test_invalid); return 1; }