header depdency correction
[platform/framework/native/appfw.git] / src / security / pkcs / FSecPkcsPkcs08Attribute.cpp
1 ///
2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FSecPkcsPkcs08Attribute.cpp
19  * @brief               This is the implementation file for Pkcs08Attribute class.
20  *
21  * This header file contains the implementation of Pkcs08Attributer class.
22  *
23  */
24
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>
32
33 #include "FSecPkcs_Pkcs08AttributeImpl.h"
34
35 using namespace Tizen::Base;
36
37 namespace Tizen { namespace Security { namespace Pkcs
38 {
39
40 Pkcs08Attribute::Pkcs08Attribute(void)
41         : __pPkcs08AttributeImpl(null)
42 {
43
44 }
45
46 Pkcs08Attribute::~Pkcs08Attribute(void)
47 {
48         delete __pPkcs08AttributeImpl;
49 }
50
51 result
52 Pkcs08Attribute::Construct(const Tizen::Base::ByteBuffer& encodedData)
53 {
54         result r = E_SUCCESS;
55
56         SysAssertf(__pPkcs08AttributeImpl == null,
57                            "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
58
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.");
61
62         r = __pPkcs08AttributeImpl->Construct(encodedData);
63         SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
64
65         return r;
66
67 CATCH:
68
69         delete __pPkcs08AttributeImpl;
70         __pPkcs08AttributeImpl = null;
71
72         return r;
73 }
74
75 result
76 Pkcs08Attribute::Construct(const Tizen::Base::String& attrType)
77 {
78         //Variables local to function
79         result r = E_SUCCESS;
80
81         SysAssertf(__pPkcs08AttributeImpl == null,
82                            "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
83
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.");
86
87         r = __pPkcs08AttributeImpl->Construct(attrType);
88         SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
89
90         return r;
91
92 CATCH:
93
94         delete __pPkcs08AttributeImpl;
95         __pPkcs08AttributeImpl = null;
96
97         return r;
98 }
99
100
101 result
102 Pkcs08Attribute::AddAttributeValue(const Pkcs08AttributeValue& value)
103 {
104         result r = E_SUCCESS;
105
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));
109
110         return r;
111 }
112
113 result
114 Pkcs08Attribute::RemoveAttributeValue(const Pkcs08AttributeValue& value)
115 {
116         result r = E_SUCCESS;
117
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));
121
122         return r;
123 }
124
125 Tizen::Base::String
126 Pkcs08Attribute::GetAttributeType(void) const
127 {
128         ClearLastResult();
129
130         SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object.");
131
132         return __pPkcs08AttributeImpl->GetAttributeType();
133
134 }
135
136 const Tizen::Base::Collection::ArrayList&
137 Pkcs08Attribute::GetAttributeValues(void) const
138 {
139         ClearLastResult();
140
141         SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object.");
142
143         return __pPkcs08AttributeImpl->GetAttributeValues();
144 }
145
146 ByteBuffer*
147 Pkcs08Attribute::GetEncodedDataN(void) const
148 {
149         result r = E_SUCCESS;
150
151         ClearLastResult();
152
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));
156
157         return pEncodedBuffer.release();
158
159 }
160 } } }