11 | 11 |
#include <openssl/pem.h>
|
12 | 12 |
|
13 | 13 |
#include "testutil.h"
|
|
14 |
#include "internal/nelem.h"
|
14 | 15 |
|
15 | |
static const char raw[] = "hello world";
|
16 | |
static const char encoded[] = "aGVsbG8gd29ybGQ=";
|
17 | |
static const char pemtype[] = "PEMTESTDATA";
|
|
16 |
typedef struct {
|
|
17 |
const char *raw;
|
|
18 |
const char *encoded;
|
|
19 |
} TESTDATA;
|
18 | 20 |
|
19 | |
static int test_b64(void)
|
|
21 |
static TESTDATA b64_pem_data[] = {
|
|
22 |
{ "hello world",
|
|
23 |
"aGVsbG8gd29ybGQ=" },
|
|
24 |
{ "a very ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong input",
|
|
25 |
"YSB2ZXJ5IG9vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29uZyBpbnB1dA==" }
|
|
26 |
};
|
|
27 |
|
|
28 |
static const char *pemtype = "PEMTESTDATA";
|
|
29 |
|
|
30 |
static int test_b64(int idx)
|
20 | 31 |
{
|
21 | 32 |
BIO *b = BIO_new(BIO_s_mem());
|
22 | 33 |
char *name = NULL, *header = NULL;
|
23 | 34 |
unsigned char *data = NULL;
|
24 | 35 |
long len;
|
25 | 36 |
int ret = 0;
|
|
37 |
const char *raw = b64_pem_data[idx].raw;
|
|
38 |
const char *encoded = b64_pem_data[idx].encoded;
|
26 | 39 |
|
27 | 40 |
if (!TEST_ptr(b)
|
28 | 41 |
|| !TEST_true(BIO_printf(b, "-----BEGIN %s-----\n", pemtype))
|
|
31 | 44 |
|| !TEST_true(PEM_read_bio_ex(b, &name, &header, &data, &len,
|
32 | 45 |
PEM_FLAG_ONLY_B64)))
|
33 | 46 |
goto err;
|
34 | |
if (!TEST_int_eq(memcmp(pemtype, name, sizeof(pemtype) - 1), 0)
|
35 | |
|| !TEST_int_eq(len,sizeof(raw) - 1)
|
36 | |
|| !TEST_int_eq(memcmp(data, raw, sizeof(raw) - 1), 0))
|
|
47 |
if (!TEST_int_eq(memcmp(pemtype, name, strlen(pemtype)), 0)
|
|
48 |
|| !TEST_int_eq(len, strlen(raw))
|
|
49 |
|| !TEST_int_eq(memcmp(data, raw, strlen(raw)), 0))
|
37 | 50 |
goto err;
|
38 | 51 |
ret = 1;
|
39 | 52 |
err:
|
|
50 | 63 |
char *name = NULL, *header = NULL;
|
51 | 64 |
unsigned char *data = NULL;
|
52 | 65 |
long len;
|
|
66 |
const char *encoded = b64_pem_data[0].encoded;
|
53 | 67 |
|
54 | 68 |
if (!TEST_ptr(b)
|
55 | 69 |
|| !TEST_true(BIO_printf(b, "-----BEGIN %s-----\n", pemtype))
|
|
70 | 84 |
|
71 | 85 |
int setup_tests(void)
|
72 | 86 |
{
|
73 | |
ADD_TEST(test_b64);
|
|
87 |
ADD_ALL_TESTS(test_b64, OSSL_NELEM(b64_pem_data));
|
74 | 88 |
ADD_TEST(test_invalid);
|
75 | 89 |
return 1;
|
76 | 90 |
}
|