byte temp[_PUBLIC_KEY_LENGTH];
ByteBuffer privKey;
ByteBuffer pubKey;
- KeyPair* pKeyPair = null;
+ std::unique_ptr< KeyPair > pKeyPair;
BN_CTX* pCtx = null;
DH* pDh = null;
RSA* pRsa = null;
}
- pKeyPair = new (std::nothrow) KeyPair();
+ pKeyPair = std::unique_ptr< KeyPair >(new (std::nothrow) KeyPair());
SysTryCatch(NID_SEC, pKeyPair != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
r = pKeyPair->SetPrivateKey(privKey);
}
if (IsFailed(r))
{
- delete pKeyPair;
- pKeyPair = null;
+ pKeyPair.reset(null);
}
- return pKeyPair;
+ return pKeyPair.release();
}
KeyPair*
if (isPemFormat == true)
{
PublicKey key;
- r = key.SetKey(*pOutBuffer.get());
+ r = key.SetKey(*pOutBuffer);
SysTryCatch(NID_SEC, !IsFailed(r), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid.");
- pOutBuffer = std::unique_ptr< ByteBuffer >(ConvertDerToPemN(format, key));
+ pOutBuffer.reset(ConvertDerToPemN(format, key));
+ //pOutBuffer = std::unique_ptr< ByteBuffer >(ConvertDerToPemN(format, key));
SysTryCatch(NID_SEC, pOutBuffer != null, r = GetLastResult(), GetLastResult(), "[%s] Failed to convert der to pem encoded byte buffer");
}
BIO_free(pBio);
}
+ if (IsFailed(r))
+ {
+ pOutBuffer.reset(null);
+ }
+
return pOutBuffer.release();
}
std::unique_ptr< AlgorithmIdentifier > pObj(new (std::nothrow) AlgorithmIdentifier());
SysTryReturn(NID_SEC_CRYPTO, pObj, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
- r = pObj->Construct(__pAlgorithmIdentifierImpl->GetAlgorithmObjectId(), __pAlgorithmIdentifierImpl->GetParametersN());
+ std::unique_ptr< IAlgorithmParameters > pParam(__pAlgorithmIdentifierImpl->GetParametersN());
+ SysTryReturn(NID_SEC_CRYPTO, pParam, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+ r = pObj->Construct(__pAlgorithmIdentifierImpl->GetAlgorithmObjectId(), pParam.get());
SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
return pObj.release();
SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
return pInitialVectorObj.release();
-
}
PkcsAlgorithmParameterType
IAlgorithmParameters*
_AlgorithmIdentifierImpl::GetParametersN(void) const
{
+ std::unique_ptr< IAlgorithmParameters > pAlgoParam;
+
//Return the Algorithm Parameter
ClearLastResult();
if (__pAlgoParams != null)
{
- return __pAlgoParams->CloneN();
+ pAlgoParam = std::unique_ptr< IAlgorithmParameters >(__pAlgoParams->CloneN());
+ SysTryReturn(NID_SEC_CRYPTO, pAlgoParam != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+ return pAlgoParam.release();
+ }
+ else
+ {
+ return null;
}
- return null;
+
}
ByteBuffer*
CATCH:
+ if (IsFailed(r))
+ {
+ pEncAlgoIdParam.reset(null);
+ }
X509_ALGOR_free(pAlgoObj);
SetLastResult(r);
return pEncAlgoIdParam.release();
CATCH:
+ if (IsFailed(r))
+ {
+ pEncInitialVector.reset(null);
+ }
+
ASN1_OCTET_STRING_free(pInitialVectorStr);
OPENSSL_free(pTemp);
SetLastResult(r);
SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. ");
SysAssertf(__encryptionScheme.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
- r = __keyDerivationFunction.Construct(keyDerivationFunction.GetAlgorithmObjectId(), keyDerivationFunction.GetParametersN());
+ std::unique_ptr< IAlgorithmParameters > pkdfParam(keyDerivationFunction.GetParametersN());
+ r = GetLastResult();
+ SysTryReturn(NID_SEC_CRYPTO, pkdfParam != null, r, r, "[%s] Failed to get the parameters.", GetErrorMessage(r));
+
+ r = __keyDerivationFunction.Construct(keyDerivationFunction.GetAlgorithmObjectId(), pkdfParam.get());
SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to construct the algorithm identifier.", GetErrorMessage(r));
- r = __encryptionScheme.Construct(encryptionScheme.GetAlgorithmObjectId(), encryptionScheme.GetParametersN());
+ std::unique_ptr< IAlgorithmParameters > pEncParam(encryptionScheme.GetParametersN());
+ r = GetLastResult();
+ SysTryReturn(NID_SEC_CRYPTO, pEncParam != null, r, r, "[%s] Failed to get the parameters.", GetErrorMessage(r));
+
+ r = __encryptionScheme.Construct(encryptionScheme.GetAlgorithmObjectId(), pEncParam.get());
SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to construct the algorithm identifier.", GetErrorMessage(r));
return r;
Tizen::Base::String objectId = __encryptionScheme.GetAlgorithmObjectId();
- IAlgorithmParameters* pParams = __encryptionScheme.GetParametersN();
+ std::unique_ptr< IAlgorithmParameters > pParams(__encryptionScheme.GetParametersN());
SysTryReturn(NID_SEC_CRYPTO, pParams != null, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error.");
- Pkcs05PbKdf2Parameters* pKeyParams = dynamic_cast< Pkcs05PbKdf2Parameters* >(__keyDerivationFunction.GetParametersN());
+ std::unique_ptr< Pkcs05PbKdf2Parameters > pKeyParams(dynamic_cast< Pkcs05PbKdf2Parameters* >(__keyDerivationFunction.GetParametersN()));
SysTryReturn(NID_SEC_CRYPTO, pKeyParams != null, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error.");
pPbes2 = PBE2PARAM_new();
pPbes2->encryption = X509_ALGOR_new();
SysTryCatch(NID_SEC_CRYPTO, pPbes2->encryption != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
- pPbes2->encryption = _PkcsUtility::GenerateAlgorithmIdentifierStructureN(objectId, pParams);
+ pPbes2->encryption = _PkcsUtility::GenerateAlgorithmIdentifierStructureN(objectId, pParams.get());
SysTryCatch(NID_SEC_CRYPTO, pPbes2->encryption != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error.");
// encode the PBE2PARAM structure
if (IsFailed(r))
{
PBE2PARAM_free(pPbes2);
+ pEncPbeParam.reset(null);
}
OPENSSL_free(pTemp);
CATCH:
+ if (IsFailed(r))
+ {
+ pEncKdfParam.reset(null);
+ }
PBKDF2PARAM_free(pKdf);
OPENSSL_free(pTemp);
SetLastResult(r);
__messageAuthScheme.Construct(macOid, null);
SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
- CATCH:
+CATCH:
PBE2PARAM_free(pMacObj);
return r;
SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. ");
SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. ");
- r = __keyDerivationFunction.Construct(keyDerivationFunction.GetAlgorithmObjectId(), keyDerivationFunction.GetParametersN());
+ std::unique_ptr< IAlgorithmParameters > pParam(keyDerivationFunction.GetParametersN());
+ r = GetLastResult();
+ SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to get the parameters.", GetErrorMessage(r));
+
+ r = __keyDerivationFunction.Construct(keyDerivationFunction.GetAlgorithmObjectId(), pParam.get());
SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to construct the algorithm identifier.", GetErrorMessage(r));
- r = __messageAuthScheme.Construct(messageAuthScheme.GetAlgorithmObjectId(), messageAuthScheme.GetParametersN());
+ std::unique_ptr< IAlgorithmParameters > pAuthParam(messageAuthScheme.GetParametersN());
+ r = GetLastResult();
+ SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to get the parameters.", GetErrorMessage(r));
+
+ r = __messageAuthScheme.Construct(messageAuthScheme.GetAlgorithmObjectId(), pAuthParam.get());
SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to construct the algorithm identifier.", GetErrorMessage(r));
return r;
pEncMacParam->Flip();
- CATCH:
+CATCH:
+ if (IsFailed(r))
+ {
+ pEncMacParam.reset(null);
+ }
PBE2PARAM_free(pMacObj);
OPENSSL_free(pTemp);
SetLastResult(r);
pOut->Flip();
+ if (IsFailed(r))
+ {
+ pOut.reset(null);
+ }
return pOut.release();
}
r = GetLastResult();
SysTryReturn(NID_SEC_CRYPTO, pOutBuffer != null, null, r, "[%s] Failed to encrypt message.", GetErrorMessage(r));
+ if (IsFailed(r))
+ {
+ pOutBuffer.reset(null);
+ }
return pOutBuffer.release();
}
r = GetLastResult();
SysTryReturn(NID_SEC_CRYPTO, pOutBuffer != null, null, r, "[%s] Failed to encrypt message.", GetErrorMessage(r));
+ if (IsFailed(r))
+ {
+ pOutBuffer.reset(null);
+ }
+
return pOutBuffer.release();
}
pOutput->Flip();
+ if (IsFailed(r))
+ {
+ pOutput.reset(null);
+ }
return pOutput.release();
}
_Pkcs08AttributeImpl::~_Pkcs08AttributeImpl(void)
{
//do nothing
+ __attributeValues.RemoveAll(true);
}
result
X509_ATTRIBUTE* pAttribute = null;
ASN1_OBJECT* pObject = null;
ASN1_TYPE* pAsnType = null;
- Pkcs08AttributeValue* pNewObj = null;
SysAssertf(__attributeType.GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
pAsnType = sk_ASN1_TYPE_value(pAttribute->value.set, i);
SysTryCatch(NID_SEC_CRYPTO, pAsnType != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid.");
- pNewObj = new (std::nothrow) Pkcs08AttributeValue();
+ std::unique_ptr< Pkcs08AttributeValue > pNewObj(new (std::nothrow) Pkcs08AttributeValue());
SysTryCatch(NID_SEC_CRYPTO, pNewObj != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
value = i2d_ASN1_TYPE(pAsnType, &pTemp);
r = pNewObj->Construct(asn1TypeBuffer);
SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
- r = AddAttributeValue(*pNewObj);
+ r = AddAttributeValue(*pNewObj.release());
SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Failed to add attribute", GetErrorMessage(r));
}
CATCH:
+ if (IsFailed(r))
+ {
+ pAttributeBuffer.reset(null);
+ }
X509_ATTRIBUTE_free(pAttribute);
OPENSSL_free(pTemp);
CATCH:
+ if (IsFailed(r))
+ {
+ pAttributeValue.reset(null);
+ }
ASN1_TYPE_free(pAsn1Type);
OPENSSL_free(pTemp);
SetLastResult(r);
SysTryReturnResult(NID_SEC_CRYPTO, key.GetRemaining() > 0, E_INVALID_ARG, "The specified input parameter is invalid.");
SysTryReturnResult(NID_SEC_CRYPTO, encodedPrivateKeyInfoBuffer.GetRemaining() > 0, E_INVALID_ARG, "The specified input parameter is invalid.");
- r = __encryptionAlgorithm.Construct(algorithmId.GetAlgorithmObjectId(), algorithmId.GetParametersN());
+ std::unique_ptr< IAlgorithmParameters > pParam(algorithmId.GetParametersN());
+ SysTryReturnResult(NID_SEC_CRYPTO, pParam, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+ r = __encryptionAlgorithm.Construct(algorithmId.GetAlgorithmObjectId(), pParam.get());
SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to construct algorithm identifier instance for encryption algorithm..", GetErrorMessage(r));
std::unique_ptr< ByteBuffer > pEncData(_PkcsUtility::EncryptDecryptN(algorithmId, key, encodedPrivateKeyInfoBuffer, 1));
CATCH:
+ if (IsFailed(r))
+ {
+ pEncPrivKey.reset(null);
+ }
X509_SIG_free(sig);
SetLastResult(r);
return pEncPrivKey.release();
_Pkcs08PrivateKeyInfoImpl::~_Pkcs08PrivateKeyInfoImpl(void)
{
//do nothing
+ __attributes.RemoveAll(true);
}
PKCS8_PRIV_KEY_INFO* pPrivKeyInfo = null;
STACK_OF(X509_ATTRIBUTE)* pStackOfAttribute = null;
X509_ATTRIBUTE* pAttribute = null;
- Pkcs08Attribute* pAttributeClassObj = null;
SysAssertf(__privateKey.GetRemaining() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. ");
SysAssertf(__algorithm.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. ");
{
pAttribute = sk_X509_ATTRIBUTE_value(pStackOfAttribute, index);
- pAttributeClassObj = new (std::nothrow) Pkcs08Attribute();
+ std::unique_ptr< Pkcs08Attribute > pAttributeClassObj(new (std::nothrow) Pkcs08Attribute());
SysTryCatch(NID_SEC_CRYPTO, pAttributeClassObj != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
value = i2d_X509_ATTRIBUTE(pAttribute, &pTemp);
r = pAttributeClassObj->Construct(attributeBuffer);
SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
- r = AddAttribute(*pAttributeClassObj);
+ r = AddAttribute(*pAttributeClassObj.release());
SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid.");
}
CATCH:
+ if (IsFailed(r))
+ {
+ pEncPrivateKeyInfo.reset(null);
+ }
PKCS8_PRIV_KEY_INFO_free(pPrivateKeyInfo);
OPENSSL_free(pTemp);
return pEncPrivateKeyInfo.release();
CATCH:
+ if (IsFailed(r))
+ {
+ pOutBuffer.reset(null);
+ }
EVP_CIPHER_CTX_cleanup(&cipherCtx);
SetLastResult(r);
CATCH:
- OPENSSL_free(pTemp);
+ if (pInitialVectorStr != null)
+ {
+ ASN1_OCTET_STRING_free(pInitialVectorStr);
+ }
+ if (pTemp != null)
+ {
+ OPENSSL_free(pTemp);
+ }
+
+ if (pAsn1Type != null)
+ {
+ ASN1_TYPE_free(pAsn1Type);
+ }
+
+ if (IsFailed(r))
+ {
+ pEncRc2CbcParam.reset(null);
+ }
SetLastResult(r);
return pEncRc2CbcParam.release();