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 FSecPkcsAlgorithmIdentifier.cpp
20 * @brief This is the implementation file for AlgorithmIdentifier class.
22 * This header file contains the implementation of AlgorithmIdentifier class.
26 #include <unique_ptr.h>
27 #include <FBaseByteBuffer.h>
28 #include <FBaseResult.h>
29 #include <FBaseSysLog.h>
30 #include <FSecPkcsAlgorithmIdentifier.h>
31 #include <FSecPkcsIAlgorithmParameters.h>
33 #include "FSecPkcs_AlgorithmIdentifierImpl.h"
35 using namespace Tizen::Base;
37 namespace Tizen { namespace Security { namespace Pkcs
40 const wchar_t OID_PKCS_05[] = L"1.2.840.113549.1.5";
41 const wchar_t OID_PBKDF2[] = L"1.2.840.113549.1.5.12";
42 const wchar_t OID_PBES2[] = L"1.2.840.113549.1.5.13";
43 const wchar_t OID_PBMAC1[] = L"1.2.840.113549.1.5.14";
44 const wchar_t OID_HMAC_SHA1[] = L"1.2.840.113549.2.7";
45 const wchar_t OID_HMAC_SHA2_224[] = L"1.2.840.113549.2.8";
46 const wchar_t OID_HMAC_SHA2_256[] = L"1.2.840.113549.2.9";
47 const wchar_t OID_HMAC_SHA2_384[] = L"1.2.840.113549.2.10";
48 const wchar_t OID_HMAC_SHA2_512[] = L"1.2.840.113549.2.11";
49 const wchar_t OID_DES_CBC[] = L"1.3.14.3.2.7";
50 const wchar_t OID_DES_CBC_EDE3[] = L"1.2.840.113549.3.7";
51 const wchar_t OID_AES_128_CBC[] = L"2.16.840.1.101.3.4.1.2";
52 const wchar_t OID_AES_192_CBC[] = L"2.16.840.1.101.3.4.1.22";
53 const wchar_t OID_AES_256_CBC[] = L"2.16.840.1.101.3.4.1.42";
54 const wchar_t OID_RC2_CBC[] = L"1.2.840.113549.3.2";
55 const wchar_t OID_PKCS_08[] = L"1.2.840.113549.1.8";
56 const wchar_t OID_RSA_ENCRYPTION[] = L"1.2.804.113549.1.1.1";
57 const wchar_t OID_ATTR_NAME[] = L"2.5.4.41";
58 const wchar_t OID_ATTR_SURNAME[] = L"2.5.4.4";
59 const wchar_t OID_ATTR_GIVEN_NAME[] = L"2.5.4.42";
60 const wchar_t OID_ATTR_INITIAL[] = L"2.5.4.43";
61 const wchar_t OID_ATTR_GEN_QUALIFIER[] = L"2.5.4.44";
62 const wchar_t OID_ATTR_COMMON_NAME[] = L"2.5.4.3";
63 const wchar_t OID_ATTR_LOCALITY_NAME[] = L"2.5.4.7";
64 const wchar_t OID_ATTR_STATE_OR_PROV_NAME[] = L"2.5.4.8";
65 const wchar_t OID_ATTR_ORG_NAME[] = L"2.5.4.10";
66 const wchar_t OID_ATTR_ORG_UNIT_NAME[] = L"2.5.4.11";
67 const wchar_t OID_ATTR_TITLE[] = L"2.5.4.12";
68 const wchar_t OID_ATTR_DN_QUALIFIER[] = L"2.5.4.46";
69 const wchar_t OID_ATTR_COUNTRY_NAME[] = L"2.5.4.6";
70 const wchar_t OID_ATTR_SERIAL_NUMBER[] = L"2.5.4.5";
71 const wchar_t OID_ATTR_PSEUDONYM[] = L"2.5.4.65";
72 const wchar_t OID_ATTR_DOMAIN_COMPONENT[] = L"0.9.2342.19200300.100.1.25";
73 const wchar_t OID_ATTR_EMAIL_ADDRESS[] = L"1.2.840.113549.1.9.1";
76 AlgorithmIdentifier::AlgorithmIdentifier(void)
77 : __pAlgorithmIdentifierImpl(null)
81 AlgorithmIdentifier::~AlgorithmIdentifier(void)
83 delete __pAlgorithmIdentifierImpl;
87 AlgorithmIdentifier::Construct(const Tizen::Base::String& algorithm, const IAlgorithmParameters* pAlgoParams)
91 SysAssertf(__pAlgorithmIdentifierImpl == null,
92 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
95 __pAlgorithmIdentifierImpl = new (std::nothrow) _AlgorithmIdentifierImpl();
96 SysTryReturnResult(NID_SEC_CRYPTO, __pAlgorithmIdentifierImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
98 r = __pAlgorithmIdentifierImpl->Construct(algorithm, pAlgoParams);
99 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
105 delete __pAlgorithmIdentifierImpl;
106 __pAlgorithmIdentifierImpl = null;
112 AlgorithmIdentifier::Construct(const Tizen::Base::ByteBuffer& encodedData)
114 result r = E_SUCCESS;
116 SysAssertf(__pAlgorithmIdentifierImpl == null,
117 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
119 __pAlgorithmIdentifierImpl = new (std::nothrow) _AlgorithmIdentifierImpl();
120 SysTryReturnResult(NID_SEC_CRYPTO, __pAlgorithmIdentifierImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
122 r = __pAlgorithmIdentifierImpl->Construct(encodedData);
123 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
129 delete __pAlgorithmIdentifierImpl;
130 __pAlgorithmIdentifierImpl = null;
136 AlgorithmIdentifier::CloneN(void) const
138 result r = E_SUCCESS;
142 SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object.");
143 SysAssertf(__pAlgorithmIdentifierImpl->GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Reconstructor the object.");
145 std::unique_ptr< AlgorithmIdentifier > pObj(new (std::nothrow) AlgorithmIdentifier());
146 SysTryReturn(NID_SEC_CRYPTO, pObj, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
148 std::unique_ptr< IAlgorithmParameters > pParam(__pAlgorithmIdentifierImpl->GetParametersN());
149 SysTryReturn(NID_SEC_CRYPTO, pParam, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
151 r = pObj->Construct(__pAlgorithmIdentifierImpl->GetAlgorithmObjectId(), pParam.get());
152 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
154 return pObj.release();
158 AlgorithmIdentifier::GetAlgorithmObjectId(void) const
162 SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object.");
164 return __pAlgorithmIdentifierImpl->__algorithm;
167 IAlgorithmParameters*
168 AlgorithmIdentifier::GetParametersN(void) const
170 //Return the Algorithm Parameter
171 result r = E_SUCCESS;
175 SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object.");
177 std::unique_ptr< IAlgorithmParameters > pObj(__pAlgorithmIdentifierImpl->GetParametersN());
178 SysTryReturn(NID_IO, pObj != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
180 return pObj.release();
185 AlgorithmIdentifier::GetEncodedDataN(void) const
187 result r = E_SUCCESS;
191 SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object.");
193 std::unique_ptr< ByteBuffer > pEncAlgoIdParam(__pAlgorithmIdentifierImpl->GetEncodedDataN());
194 SysTryReturn(NID_IO, pEncAlgoIdParam != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
196 return pEncAlgoIdParam.release();
201 AlgorithmIdentifier::Equals(const Object& obj) const
205 SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object.");
207 const AlgorithmIdentifier* pOther = dynamic_cast< const AlgorithmIdentifier* >(&obj);
213 return __pAlgorithmIdentifierImpl->Equals(*pOther->__pAlgorithmIdentifierImpl);
217 AlgorithmIdentifier::GetHashCode(void) const
220 SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object.");
222 return __pAlgorithmIdentifierImpl->GetHashCode();