1 /* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License
16 * @file client-certificate-impl.cpp
17 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19 * @brief Key implementation.
21 #include <openssl/x509.h>
23 #include <dpl/log/log.h>
25 #include <client-certificate-impl.h>
30 CertificateImpl::CertificateImpl(const RawBuffer &der, Certificate::Format format) {
32 const unsigned char *ptr;
35 if (Certificate::Format::FORM_BASE64 == format) {
41 ptr = reinterpret_cast<const unsigned char*>(tmp.data());
42 size = static_cast<int>(tmp.size());
44 ptr = reinterpret_cast<const unsigned char*>(der.data());
45 size = static_cast<int>(der.size());
48 m_x509 = d2i_X509(NULL, &ptr, size);
51 // LogError("Internal Openssl error in d2i_X509 function.");
52 // ThrowMsg(Exception::OpensslInternalError,
53 // "Internal Openssl error in d2i_X509 function.");
57 RawBuffer CertificateImpl::getDER(void) const {
58 unsigned char *rawDer = NULL;
59 int size = i2d_X509(m_x509, &rawDer);
60 if (!rawDer || size <= 0) {
62 // LogError("i2d_X509 failed");
63 // ThrowMsg(Exception::OpensslInternalError,
64 // "i2d_X509 failed");
68 reinterpret_cast<char*>(rawDer),
69 reinterpret_cast<char*>(rawDer) + size);
74 bool CertificateImpl::empty() const {
75 return m_x509 == NULL;
78 CertificateImpl::~CertificateImpl() {