2 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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>
16 static const char raw[] = "hello world";
17 static const char encoded[] = "aGVsbG8gd29ybGQ=";
18 static const char pemtype[] = "PEMTESTDATA";
20 static int test_b64(void)
22 BIO *b = BIO_new(BIO_s_mem());
23 char *name = NULL, *header = NULL;
24 unsigned char *data = NULL;
29 || !TEST_true(BIO_printf(b, "-----BEGIN %s-----\n", pemtype))
30 || !TEST_true(BIO_printf(b, "%s\n", encoded))
31 || !TEST_true(BIO_printf(b, "-----END %s-----\n", pemtype))
32 || !TEST_true(PEM_read_bio_ex(b, &name, &header, &data, &len,
35 if (!TEST_int_eq(memcmp(pemtype, name, sizeof(pemtype) - 1), 0)
36 || !TEST_int_eq(len,sizeof(raw) - 1)
37 || !TEST_int_eq(memcmp(data, raw, sizeof(raw) - 1), 0))
48 static int test_invalid(void)
50 BIO *b = BIO_new(BIO_s_mem());
51 char *name = NULL, *header = NULL;
52 unsigned char *data = NULL;
56 || !TEST_true(BIO_printf(b, "-----BEGIN %s-----\n", pemtype))
57 || !TEST_true(BIO_printf(b, "%c%s\n", '\t', encoded))
58 || !TEST_true(BIO_printf(b, "-----END %s-----\n", pemtype))
59 /* Expected to fail due to non-base64 character */
60 || TEST_true(PEM_read_bio_ex(b, &name, &header, &data, &len,
61 PEM_FLAG_ONLY_B64))) {
75 ADD_TEST(test_invalid);