/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <sstream>
#include <string>
#include <utility>
+#include <vector>
#define OPENSSL_SUCCESS 1
void errorDump()
{
- BIO *bio = BIO_new(BIO_s_mem());
- ERR_print_errors(bio);
- char *buf = NULL;
- long len = BIO_get_mem_data(bio, &buf);
- if(len < 0) {
- LogError("Fail in BIO_get_mem_data()");
+ typedef std::unique_ptr<BIO, std::function<void(BIO *)>> BioUniquePtr;
+ BioUniquePtr bio(BIO_new(BIO_s_mem()), BIO_free_all);
+ if (!bio.get())
return;
+
+ ERR_print_errors(bio.get());
+
+ std::vector<char> message(1024);
+ int len = BIO_read(bio.get(), message.data(), message.size());
+ if (len > 0) {
+ message.resize(len);
+ LogError(std::string(message.begin(), message.end()));
}
- size_t length = static_cast<size_t>(len);
- BIO_free(bio);
- std::string ret(buf, length);
- free(buf);
- LogError(ret);
}
void errorHandle(const char *file, int line, const char *function, int openssl_ret)