2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @author Tomasz Morawski(t.morawski@samsung.com)
22 #include <openssl/ocsp.h>
25 * This function is needed to fix "Invalid conversion from void* to unsigned char*"
26 * C++ compiler error during calling i2d_OCSP_REQUEST_bio macro
28 int convertToBuffer(OCSP_REQUEST *req, char **buf, int *size) {
33 * size and membuffer for request
35 *size = i2d_OCSP_REQUEST(req, NULL);
36 *buf = (char*) malloc(*size);
41 /* copy request into buffer */
47 * create a new buffer using openssl
49 req_mem_bio = BIO_new(BIO_s_mem());
53 * creation failed, return
60 BIO_set_mem_buf(req_mem_bio, &req_bmem, BIO_NOCLOSE);
65 if (i2d_OCSP_REQUEST_bio(req_mem_bio, req) <= 0) {
68 BIO_free_all(req_mem_bio);
75 if (*size != ((int)req_bmem.length) || req_bmem.length != req_bmem.max)
79 BIO_free_all(req_mem_bio);
84 * free all reserved memory
86 BIO_free_all(req_mem_bio);