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 FSecPkcsPkcs08Attribute.cpp
19 * @brief This is the implementation file for Pkcs08Attribute class.
21 * This header file contains the implementation of Pkcs08Attributer class.
25 #include <unique_ptr.h>
26 #include <FBaseByteBuffer.h>
27 #include <FBaseResult.h>
28 #include <FBaseSysLog.h>
29 #include <FBaseColArrayList.h>
30 #include <FSecPkcsPkcs08Attribute.h>
31 #include <FSecPkcsPkcs08AttributeValue.h>
33 #include "FSecPkcs_Pkcs08AttributeImpl.h"
35 using namespace Tizen::Base;
37 namespace Tizen { namespace Security { namespace Pkcs
40 Pkcs08Attribute::Pkcs08Attribute(void)
41 : __pPkcs08AttributeImpl(null)
46 Pkcs08Attribute::~Pkcs08Attribute(void)
48 delete __pPkcs08AttributeImpl;
52 Pkcs08Attribute::Construct(const Tizen::Base::ByteBuffer& encodedData)
56 SysAssertf(__pPkcs08AttributeImpl == null,
57 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
59 __pPkcs08AttributeImpl = new (std::nothrow) _Pkcs08AttributeImpl();
60 SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08AttributeImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
62 r = __pPkcs08AttributeImpl->Construct(encodedData);
63 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
69 delete __pPkcs08AttributeImpl;
70 __pPkcs08AttributeImpl = null;
76 Pkcs08Attribute::Construct(const Tizen::Base::String& attrType)
78 //Variables local to function
81 SysAssertf(__pPkcs08AttributeImpl == null,
82 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
84 __pPkcs08AttributeImpl = new (std::nothrow) _Pkcs08AttributeImpl();
85 SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08AttributeImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
87 r = __pPkcs08AttributeImpl->Construct(attrType);
88 SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
94 delete __pPkcs08AttributeImpl;
95 __pPkcs08AttributeImpl = null;
102 Pkcs08Attribute::AddAttributeValue(const Pkcs08AttributeValue& value)
104 result r = E_SUCCESS;
106 SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object.");
107 r = __pPkcs08AttributeImpl->AddAttributeValue(value);
108 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
114 Pkcs08Attribute::RemoveAttributeValue(const Pkcs08AttributeValue& value)
116 result r = E_SUCCESS;
118 SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object.");
119 r = __pPkcs08AttributeImpl->RemoveAttributeValue(value);
120 SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
126 Pkcs08Attribute::GetAttributeType(void) const
130 SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object.");
132 return __pPkcs08AttributeImpl->GetAttributeType();
136 const Tizen::Base::Collection::ArrayList&
137 Pkcs08Attribute::GetAttributeValues(void) const
141 SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object.");
143 return __pPkcs08AttributeImpl->GetAttributeValues();
147 Pkcs08Attribute::GetEncodedDataN(void) const
149 result r = E_SUCCESS;
153 SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object.");
154 std::unique_ptr< ByteBuffer > pEncodedBuffer(__pPkcs08AttributeImpl->GetEncodedDataN());
155 SysTryReturn(NID_SEC_CRYPTO, pEncodedBuffer != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r));
157 return pEncodedBuffer.release();