2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FSecPkcsPkcs08PrivateKeyInfo.cpp
20 * @brief This is the implementation file for Pkcs08PrivateKeyInfo class.
22 * This header file contains the implementation of Pkcs08PrivateKeyInfo class.
26 #include <unique_ptr.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseByteBuffer.h>
29 #include <FBaseResult.h>
30 #include <FSecPkcsPkcs08PrivateKeyInfo.h>
31 #include <FSecPkcsAlgorithmIdentifier.h>
32 #include "FSecPkcs_Pkcs08PrivateKeyInfoImpl.h"
34 using namespace Tizen::Base;
36 namespace Tizen { namespace Security { namespace Pkcs
39 Pkcs08PrivateKeyInfo::Pkcs08PrivateKeyInfo(void)
40 : __pPkcs08PrivateKeyInfoImpl(null)
46 Pkcs08PrivateKeyInfo::~Pkcs08PrivateKeyInfo(void)
53 Pkcs08PrivateKeyInfo::Construct(const Tizen::Base::ByteBuffer& encodedData)
57 SysAssertf(__pPkcs08PrivateKeyInfoImpl == null,
58 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
60 __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl();
61 SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
63 r = __pPkcs08PrivateKeyInfoImpl->Construct(encodedData);
64 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
70 delete __pPkcs08PrivateKeyInfoImpl;
71 __pPkcs08PrivateKeyInfoImpl = null;
77 Pkcs08PrivateKeyInfo::Construct(const AlgorithmIdentifier& privAlgoId, const Tizen::Base::ByteBuffer& privKey)
81 SysAssertf(__pPkcs08PrivateKeyInfoImpl == null,
82 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
84 __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl();
85 SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
88 r = __pPkcs08PrivateKeyInfoImpl->Construct(privAlgoId, privKey);
89 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
95 delete __pPkcs08PrivateKeyInfoImpl;
96 __pPkcs08PrivateKeyInfoImpl = null;
102 Pkcs08PrivateKeyInfo::GetVersion(void) const
106 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
108 return __pPkcs08PrivateKeyInfoImpl->GetVersion();
112 const AlgorithmIdentifier&
113 Pkcs08PrivateKeyInfo::GetPrivateKeyAlgorithm(void) const
117 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
119 return __pPkcs08PrivateKeyInfoImpl->GetPrivateKeyAlgorithm();
123 Pkcs08PrivateKeyInfo::GetPrivateKey(void) const
127 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
129 return __pPkcs08PrivateKeyInfoImpl->GetPrivateKey();
132 const Tizen::Base::Collection::ArrayList&
133 Pkcs08PrivateKeyInfo::GetAttributes(void) const
137 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
138 return __pPkcs08PrivateKeyInfoImpl->GetAttributes();
143 Pkcs08PrivateKeyInfo::AddAttribute(const Pkcs08Attribute& attribute)
145 result r = E_SUCCESS;
149 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
150 r = __pPkcs08PrivateKeyInfoImpl->AddAttribute(attribute);
151 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
157 Pkcs08PrivateKeyInfo::RemoveAttribute(const Pkcs08Attribute& attribute)
159 result r = E_SUCCESS;
163 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
164 r = __pPkcs08PrivateKeyInfoImpl->RemoveAttribute(attribute);
165 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
171 Pkcs08PrivateKeyInfo::GetEncodedDataN(void) const
173 result r = E_SUCCESS;
177 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
178 std::unique_ptr< ByteBuffer > pEncodedData(__pPkcs08PrivateKeyInfoImpl->GetEncodedDataN());
179 SysTryReturn(NID_SEC_CRYPTO, pEncodedData != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
181 return pEncodedData.release();