Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / security / pkcs / FSecPkcs_Pkcs05PbMacParametersImpl.cpp
index 6369d23..71ad1eb 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -75,10 +74,6 @@ _Pkcs05PbMacParametersImpl::Construct(const Tizen::Base::ByteBuffer& encodedData
        ASN1_TYPE* pParam = null;
        std::unique_ptr< Pkcs05PbKdf2Parameters > pKdf2Parameters;
 
-
-       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. ");
-
        pBuffer = encodedData.GetPointer();
        SysTryReturnResult(NID_SEC_CRYPTO, pBuffer != null, E_INVALID_ARG, "The specified input parameter is invalid.");
 
@@ -125,7 +120,7 @@ _Pkcs05PbMacParametersImpl::Construct(const Tizen::Base::ByteBuffer& encodedData
        r = GetLastResult();
        SysTryCatch(NID_SEC_CRYPTO, r != E_UNSUPPORTED_ALGORITHM, r = E_UNSUPPORTED_ALGORITHM, E_UNSUPPORTED_ALGORITHM, "[E_UNSUPPORTED_ALGORITHM] The input algorithm is not supported.");
 
-       __messageAuthScheme.Construct(macOid, null);
+       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:
@@ -139,19 +134,14 @@ _Pkcs05PbMacParametersImpl::Construct(const AlgorithmIdentifier& keyDerivationFu
 {
        result r = E_SUCCESS;
 
-       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. ");
-
        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));
+       SysTryReturn(NID_SEC_CRYPTO, pParam != null, 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));
 
        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));
+       SysTryReturn(NID_SEC_CRYPTO, pParam != null, 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));
@@ -248,6 +238,10 @@ const AlgorithmIdentifier&
 _Pkcs05PbMacParametersImpl::GetKeyDerivationAlgorithm(void) const
 {
        ClearLastResult();
+
+       SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use.");
+       SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use.");
+
        return __keyDerivationFunction;
 }
 
@@ -255,6 +249,10 @@ const AlgorithmIdentifier&
 _Pkcs05PbMacParametersImpl::GetMacAlgorithm(void) const
 {
        ClearLastResult();
+
+       SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use.");
+       SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use.");
+
        return __messageAuthScheme;
 }
 
@@ -270,6 +268,9 @@ _Pkcs05PbMacParametersImpl::Equals(const Object& obj) const
 {
        bool value = false;
 
+       SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use.");
+       SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use.");
+
        const _Pkcs05PbMacParametersImpl* pOther = dynamic_cast< const _Pkcs05PbMacParametersImpl* >(&obj);
 
        SysTryReturn(NID_SEC_CRYPTO, pOther != null, false, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid.");
@@ -294,7 +295,6 @@ _Pkcs05PbMacParametersImpl::GetHashCode(void) const
        SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use.");
        SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use.");
 
-
        return __keyDerivationFunction.GetHashCode() + __messageAuthScheme.GetHashCode();
 }