]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/pemtest.c
2 * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include <openssl/bio.h>
12 #include <openssl/pem.h>
15 #include "internal/nelem.h"
22 static TESTDATA b64_pem_data
[] = {
25 { "a very ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong input",
26 "YSB2ZXJ5IG9vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29vb29uZyBpbnB1dA==" }
29 static const char *pemtype
= "PEMTESTDATA";
31 static int test_b64(int idx
)
33 BIO
*b
= BIO_new(BIO_s_mem());
34 char *name
= NULL
, *header
= NULL
;
35 unsigned char *data
= NULL
;
38 const char *raw
= b64_pem_data
[idx
].raw
;
39 const char *encoded
= b64_pem_data
[idx
].encoded
;
42 || !TEST_true(BIO_printf(b
, "-----BEGIN %s-----\n", pemtype
))
43 || !TEST_true(BIO_printf(b
, "%s\n", encoded
))
44 || !TEST_true(BIO_printf(b
, "-----END %s-----\n", pemtype
))
45 || !TEST_true(PEM_read_bio_ex(b
, &name
, &header
, &data
, &len
,
48 if (!TEST_int_eq(memcmp(pemtype
, name
, strlen(pemtype
)), 0)
49 || !TEST_int_eq(len
, strlen(raw
))
50 || !TEST_int_eq(memcmp(data
, raw
, strlen(raw
)), 0))
61 static int test_invalid(void)
63 BIO
*b
= BIO_new(BIO_s_mem());
64 char *name
= NULL
, *header
= NULL
;
65 unsigned char *data
= NULL
;
67 const char *encoded
= b64_pem_data
[0].encoded
;
70 || !TEST_true(BIO_printf(b
, "-----BEGIN %s-----\n", pemtype
))
71 || !TEST_true(BIO_printf(b
, "%c%s\n", '\t', encoded
))
72 || !TEST_true(BIO_printf(b
, "-----END %s-----\n", pemtype
))
73 /* Expected to fail due to non-base64 character */
74 || TEST_true(PEM_read_bio_ex(b
, &name
, &header
, &data
, &len
,
75 PEM_FLAG_ONLY_B64
))) {
88 ADD_ALL_TESTS(test_b64
, OSSL_NELEM(b64_pem_data
));
89 ADD_TEST(test_invalid
);