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)
42 __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl();
43 SysTryReturnVoidResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
47 Pkcs08PrivateKeyInfo::~Pkcs08PrivateKeyInfo(void)
49 delete __pPkcs08PrivateKeyInfoImpl;
54 Pkcs08PrivateKeyInfo::Construct(const Tizen::Base::ByteBuffer& encodedData)
58 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
59 r = __pPkcs08PrivateKeyInfoImpl->Construct(encodedData);
60 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
66 Pkcs08PrivateKeyInfo::Construct(const AlgorithmIdentifier& privAlgoId, const Tizen::Base::ByteBuffer& privKey)
70 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
71 r = __pPkcs08PrivateKeyInfoImpl->Construct(privAlgoId, privKey);
72 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
78 Pkcs08PrivateKeyInfo::GetVersion(void) const
82 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
84 return __pPkcs08PrivateKeyInfoImpl->GetVersion();
88 const AlgorithmIdentifier&
89 Pkcs08PrivateKeyInfo::GetPrivateKeyAlgorithm(void) const
93 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
95 return __pPkcs08PrivateKeyInfoImpl->GetPrivateKeyAlgorithm();
99 Pkcs08PrivateKeyInfo::GetPrivateKey(void) const
103 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
105 return __pPkcs08PrivateKeyInfoImpl->GetPrivateKey();
108 const Tizen::Base::Collection::ArrayList&
109 Pkcs08PrivateKeyInfo::GetAttributes(void) const
113 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
114 return __pPkcs08PrivateKeyInfoImpl->GetAttributes();
119 Pkcs08PrivateKeyInfo::AddAttribute(const Pkcs08Attribute& attribute)
121 result r = E_SUCCESS;
125 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
126 r = __pPkcs08PrivateKeyInfoImpl->AddAttribute(attribute);
127 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
133 Pkcs08PrivateKeyInfo::RemoveAttribute(const Pkcs08Attribute& attribute)
135 result r = E_SUCCESS;
139 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
140 r = __pPkcs08PrivateKeyInfoImpl->RemoveAttribute(attribute);
141 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
147 Pkcs08PrivateKeyInfo::GetEncodedDataN(void) const
149 result r = E_SUCCESS;
153 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
154 std::unique_ptr< ByteBuffer > pEncodedData(__pPkcs08PrivateKeyInfoImpl->GetEncodedDataN());
155 SysTryReturn(NID_SEC_CRYPTO, pEncodedData != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
157 return pEncodedData.release();