static X509 *load_pem_cert(const char *dir, const char *file) { X509 *cert = NULL; char *file_path = mk_file_path(dir, file); if (file_path != NULL) { BIO *cert_io = BIO_new_file(file_path, "r"); OPENSSL_free(file_path); if (cert_io != NULL) cert = PEM_read_bio_X509(cert_io, NULL, NULL, NULL); BIO_free(cert_io); } return cert; }
static int read_text_file(const char *dir, const char *file, char *buffer, int buffer_length) { int len = -1; char *file_path = mk_file_path(dir, file); if (file_path != NULL) { BIO *file_io = BIO_new_file(file_path, "r"); if (file_io != NULL) len = BIO_read(file_io, buffer, buffer_length); BIO_free(file_io); } OPENSSL_free(file_path); return len; }