2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FSecPkcsPkcs08PrivateKeyInfo.cpp
19 * @brief This is the implementation file for Pkcs08PrivateKeyInfo class.
21 * This header file contains the implementation of Pkcs08PrivateKeyInfo class.
25 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseByteBuffer.h>
28 #include <FBaseResult.h>
29 #include <FSecPkcsPkcs08PrivateKeyInfo.h>
30 #include <FSecPkcsAlgorithmIdentifier.h>
31 #include "FSecPkcs_Pkcs08PrivateKeyInfoImpl.h"
33 using namespace Tizen::Base;
35 namespace Tizen { namespace Security { namespace Pkcs
38 Pkcs08PrivateKeyInfo::Pkcs08PrivateKeyInfo(void)
39 : __pPkcs08PrivateKeyInfoImpl(null)
45 Pkcs08PrivateKeyInfo::~Pkcs08PrivateKeyInfo(void)
47 delete __pPkcs08PrivateKeyInfoImpl;
52 Pkcs08PrivateKeyInfo::Construct(const Tizen::Base::ByteBuffer& encodedData)
56 SysAssertf(__pPkcs08PrivateKeyInfoImpl == null,
57 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
59 __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl();
60 SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
62 r = __pPkcs08PrivateKeyInfoImpl->Construct(encodedData);
63 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
69 delete __pPkcs08PrivateKeyInfoImpl;
70 __pPkcs08PrivateKeyInfoImpl = null;
76 Pkcs08PrivateKeyInfo::Construct(const AlgorithmIdentifier& privAlgoId, const Tizen::Base::ByteBuffer& privKey)
80 SysAssertf(__pPkcs08PrivateKeyInfoImpl == null,
81 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
83 __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl();
84 SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
87 r = __pPkcs08PrivateKeyInfoImpl->Construct(privAlgoId, privKey);
88 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
94 delete __pPkcs08PrivateKeyInfoImpl;
95 __pPkcs08PrivateKeyInfoImpl = null;
101 Pkcs08PrivateKeyInfo::GetVersion(void) const
105 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
107 return __pPkcs08PrivateKeyInfoImpl->GetVersion();
111 const AlgorithmIdentifier&
112 Pkcs08PrivateKeyInfo::GetPrivateKeyAlgorithm(void) const
116 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
118 return __pPkcs08PrivateKeyInfoImpl->GetPrivateKeyAlgorithm();
122 Pkcs08PrivateKeyInfo::GetPrivateKey(void) const
126 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
128 return __pPkcs08PrivateKeyInfoImpl->GetPrivateKey();
131 const Tizen::Base::Collection::ArrayList&
132 Pkcs08PrivateKeyInfo::GetAttributes(void) const
136 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
137 return __pPkcs08PrivateKeyInfoImpl->GetAttributes();
142 Pkcs08PrivateKeyInfo::AddAttribute(const Pkcs08Attribute& attribute)
144 result r = E_SUCCESS;
148 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
149 r = __pPkcs08PrivateKeyInfoImpl->AddAttribute(attribute);
150 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
156 Pkcs08PrivateKeyInfo::RemoveAttribute(const Pkcs08Attribute& attribute)
158 result r = E_SUCCESS;
162 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
163 r = __pPkcs08PrivateKeyInfoImpl->RemoveAttribute(attribute);
164 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
170 Pkcs08PrivateKeyInfo::GetEncodedDataN(void) const
172 result r = E_SUCCESS;
176 SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
177 std::unique_ptr< ByteBuffer > pEncodedData(__pPkcs08PrivateKeyInfoImpl->GetEncodedDataN());
178 SysTryReturn(NID_SEC_CRYPTO, pEncodedData != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
180 return pEncodedData.release();