if (pPrivKeyInfo != null)
{
pEvpKey = EVP_PKCS82PKEY(pPrivKeyInfo);
+ SysTryCatch(NID_SEC, pEvpKey != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid");
PKCS8_PRIV_KEY_INFO_free(pPrivKeyInfo);
}
pBio = BIO_new(BIO_s_mem());
}
pBlock = std::unique_ptr <byte[]> (new (std::nothrow) byte[blockSize]);
- SysTryCatch(NID_SEC, pBlock != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
+ SysTryReturn(NID_SEC, pBlock != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
pInterVal1 = std::unique_ptr <byte[]> (new (std::nothrow) byte[blockSize]);
- SysTryCatch(NID_SEC, pInterVal1 != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
+ SysTryReturn(NID_SEC, pInterVal1 != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
pInterVal2 = std::unique_ptr <byte[]> (new (std::nothrow) byte[blockSize]);
- SysTryCatch(NID_SEC, pInterVal2 != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
+ SysTryReturn(NID_SEC, pInterVal2 != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
pInterVal1XorBlock = std::unique_ptr <byte[]> (new (std::nothrow) byte[blockSize]);
- SysTryCatch(NID_SEC, pInterVal1XorBlock != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
+ SysTryReturn(NID_SEC, pInterVal1XorBlock != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
pInterVal2XorInterVal1 = std::unique_ptr <byte[]> (new (std::nothrow) byte[blockSize]);
- SysTryCatch(NID_SEC, pInterVal2XorInterVal1 != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
+ SysTryReturn(NID_SEC, pInterVal2XorInterVal1 != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocating new byte array failed.");
lenInterVal1 = blockSize;
lenInterVal2 = blockSize;
{
r = E_INVALID_ARG;
SysLogException(NID_SEC, r, "The seed length do not match the data block size.");
- goto CATCH;
+ return r;
}
memcpy(pBlock.get(), pDt, dtLen);
using namespace Tizen::Io;
using namespace Tizen::Security;
+struct FreeCharPtr
+{
+ void operator ()(char* p)
+ {
+ if (p != null)
+ {
+ free(p);
+ }
+ }
+};
+
+
namespace Tizen { namespace Security { namespace Cert
{
int err = 0;
EVP_CIPHER_CTX ctx;
- std::unique_ptr< char > pUniqueKey(GetDeviceUniqueKey(certMgrInfo, certMgrInfoLen, aesBlockLen));
+ std::unique_ptr< char, FreeCharPtr > pUniqueKey(GetDeviceUniqueKey(certMgrInfo, certMgrInfoLen, aesBlockLen));
SysTryReturnResult(NID_SEC_CERT, pUniqueKey != null, E_SYSTEM, "Failed to generate unique key.");
memset(uniqueKey, 0, aesBlockLen);
long tempkeyLen = 0;
byte* pPrivKey = null;
- std::unique_ptr< char > pUniqueKey(GetDeviceUniqueKey(certMgrInfo, certMgrInfoLen, aesBlockLen));
+ std::unique_ptr< char, FreeCharPtr > pUniqueKey(GetDeviceUniqueKey(certMgrInfo, certMgrInfoLen, aesBlockLen));
SysTryReturnResult(NID_SEC_CERT, pUniqueKey != null, E_SYSTEM, "Failed to generate unique key.");
memset(uniqueKey, 0, aesBlockLen);
SysTryReturnResult(NID_SEC_CERT, pKey != null, E_PARSING_FAILED, "Failed to get certificate public key.");
pubKeyLen = i2d_PublicKey(pKey, &pPubKey);
+ SysTryReturnResult(NID_SEC_CERT, pPubKey != null, E_PARSING_FAILED, "Failed to get certificate public key.");
__tbsCert.SetPublicKeyInfo(pubKeyLen, pPubKey);
int ret = 0;
int outLen = 0;
std::unique_ptr<ByteBuffer> pOutput(null);
+ std::unique_ptr<byte[]> pTempBuf(null);
ClearLastResult();
SysAssertf(__pEvpMdCtx != null && __pAlgorithm != null, "Not yet constructed. Initialize() and SetAlgorithm() should be called before use.");
outLen = EVP_MD_size(__pAlgorithm);
+ SysTryCatch(NID_SEC_CRYPTO, outLen > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
- std::unique_ptr<byte[]> pTempBuf(new (std::nothrow) byte[outLen]);
+ pTempBuf = std::unique_ptr<byte[]>(new (std::nothrow) byte[outLen]);
SysTryCatch(NID_SEC_CRYPTO, pTempBuf != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
ret = EVP_DigestFinal(__pEvpMdCtx, pTempBuf.get(), null);
SysTryReturn(NID_SEC_CRYPTO, keyLen > 0, null, E_KEY_NOT_FOUND, "[E_KEY_NOT_FOUND] Key length should be positive.");
mdLen = EVP_MD_size(__pAlgorithm);
+ SysTryReturn(NID_SEC_CRYPTO, mdLen > 0, null, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
std::unique_ptr<byte[]> pMd(new (std::nothrow) byte[mdLen]);
SysTryReturn(NID_SEC_CRYPTO, pMd != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
{
r = E_SYSTEM;
SysLogException(NID_SEC_CRYPTO, r, "An Unexpected system error occurred.");
- goto CATCH;
+ SetLastResult(r);
+ return null;
}
default:
r = E_UNSUPPORTED_ALGORITHM;
SysLogException(NID_SEC_CRYPTO, r, " The algorithm for input key length is not supported");
- goto CATCH;
+ SetLastResult(r);
+ return null;
}
pOut = std::unique_ptr <byte[]> (new (std::nothrow) byte[dataLen + 8]);
pOutBuf->Flip();
CATCH:
-
+
EVP_CIPHER_CTX_cleanup(&cipherCtx);
SetLastResult(r);
if (numVal < _MIN_WRAP_KEY_LEN_REFACTOR || dataLen > _MAX_AES_WRAP_DATA_LENGTH)
{
- ret = E_SYSTEM;
+ r = E_SYSTEM;
SysLogException(NID_SEC_CRYPTO, r, "An Unexpected system error occurred.");
- goto CATCH;
+ SetLastResult(r);
+ return null;
}
default:
r = E_UNSUPPORTED_ALGORITHM;
SysLogException(NID_SEC_CRYPTO, r, " The algorithm for input key length is not supported");
- goto CATCH;
+ SetLastResult(r);
+ return null;
}
pOut = std::unique_ptr <byte[]> (new (std::nothrow) byte[dataLen]);