r = Tizen::Base::Utility::StringUtil::EncodeToBase64String(buffer, encodedStr);
SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Failed to encode base 64 data.");
- std::unique_ptr< char > pEncodedBuffer(Tizen::Base::_StringConverter::CopyToCharArrayN(encodedStr));
+ std::unique_ptr< char[] > pEncodedBuffer(Tizen::Base::_StringConverter::CopyToCharArrayN(encodedStr));
SysTryReturn(NID_SEC_CERT, pEncodedBuffer != null, GetLastResult(), GetLastResult(), "[%s] Failed to convert string to char buffer.", GetErrorMessage(GetLastResult()));
if (outSize > encodedStr.GetLength())
using namespace Tizen::Base;
using namespace Tizen::Io;
+namespace
+{
+struct ByteDeleter
+{
+ void operator ()(byte* c)
+ {
+ free(c);
+ }
+};
+}
+
namespace Tizen { namespace Security { namespace Cert
{
_CertDbManager* _CertDbManager::__pCertDb = null;
SysTryReturnResult(NID_SEC_CERT, pCert != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
certBufFormat = _CertManager::GetEncodedCertBuffer(pCertBuf, certLen, &pDerCert, &derCertBufferLength, &encodingType);
- std::unique_ptr< byte[] > pDerCertBuffer(pDerCert);
+ std::unique_ptr< byte, ByteDeleter > pDerCertBuffer(pDerCert);
pDerCert = null;
SysTryReturnResult(NID_SEC_CERT, pDerCertBuffer != null, E_INVALID_CONDITION, "Input certificate buffer.");
SysTryReturnResult(NID_SEC_CERT, certBufFormat == _CERT_X509, E_INVALID_CONDITION, "Unsupported certificate format.");
using namespace Tizen::System;
using namespace Tizen::Io;
+namespace
+{
+struct ByteDeleter
+{
+ void operator ()(byte* c)
+ {
+ free(c);
+ }
+};
+}
+
namespace Tizen { namespace Security { namespace Cert
{
File fileCrt;
FileAttributes attr;
byte certBufData[_MAX_CERTIFICATE_SIZE] = {0, };
- const unsigned char* pCertBuffer = null;
long fileSize = 0;
int certBufferLen = 0;
int readLength = 0;
pBio = BIO_new(BIO_s_mem());
SysTryCatch(NID_SEC_CERT, pBio != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
- pCertBuffer = new (std::nothrow) unsigned char[readCnt];
+ std::unique_ptr<unsigned char[]> pCertBuffer(new (std::nothrow) unsigned char[readCnt]);
SysTryCatch(NID_SEC_CERT, pCertBuffer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
- memcpy((void*) pCertBuffer, certBufData, readCnt);
+ memcpy(static_cast<void*>(pCertBuffer.get()), certBufData, readCnt);
certBufferLen = readCnt;
- pCert = d2i_X509(null, &pCertBuffer, certBufferLen);
+ const unsigned char* pTemp = pCertBuffer.get();
+ pCert = d2i_X509(null, &pTemp, certBufferLen);
SysTryCatch(NID_SEC_CERT, pCert != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Certificate conversion failed.");
readLength = PEM_write_bio_X509(pBio, pCert);
}
else if (pX509Cert->Parse(pCertBuffer, certBufferLen) == E_SUCCESS)
{
- std::unique_ptr< byte[] > pCertBuf(new (std::nothrow) byte[certBufferLen]);
+ std::unique_ptr< byte, ByteDeleter > pCertBuf(static_cast<byte*>(malloc(sizeof(byte) * certBufferLen)));
SysTryReturn(NID_SEC_CERT, pCertBuf != null, _CERT_UNKNOWN, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
memcpy(pCertBuf.get(), pCertBuffer, certBufferLen);
certBufLen = _Base64::GetDecodedSize(certBufferLen);
SysTryReturn(NID_SEC_CERT, certBufLen > 0, _CERT_UNKNOWN, E_SYSTEM, "[E_SYSTEM] Invalid certificate length.");
- std::unique_ptr< byte[] > pCertBuf(new (std::nothrow) byte[certBufLen]);
+ std::unique_ptr< byte, ByteDeleter > pCertBuf(static_cast<byte*>(malloc(sizeof(byte) * certBufLen)));
SysTryReturn(NID_SEC_CERT, pCertBuf != null, _CERT_UNKNOWN, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
memset(pCertBuf.get(), 0, certBufLen);