Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / security / FSec_PrivilegeInfo.h
1 //
2 // Copyright (c) 2012 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        FSec_PrivilegeManagerInfo.h
19  * @brief       This is the header file for the FSec_PrivilegeInfo.
20  * This header file contains the declarations of the FSec_PrivilegeInfo.
21  */
22
23 #ifndef _FSEC_INTERNAL_PRIVILEGE_INFO_H_
24 #define _FSEC_INTERNAL_PRIVILEGE_INFO_H_
25
26 #include <FOspConfig.h>
27 #include "FSec_AccessControlTypes.h"
28
29 namespace Tizen { namespace Security
30 {
31
32 /**
33  * @class       _PrivilegeInfo
34  * @brief       This class provides a basic information of privilege manager.
35  * @since       2.0
36  *
37  * This class provides a basic information of privilege manager.
38  *
39  */
40 class _PrivilegeInfo
41         : public Tizen::Base::Object
42 {
43
44 public:
45         /**
46          * This is the default constructor for this class.      @n
47          * This method creates an uninitialized instance of _PrivilegeCache.
48          *
49          * @since       2.0
50          */
51         _PrivilegeInfo(void);
52
53         /**
54          * This is the destructor for this class.
55          *
56          * @since       2.0
57          */
58         virtual ~_PrivilegeInfo(void);
59
60         /**
61          * Initializes an instance of _PrivilegeInfo and sets its base information directly.
62          *
63          * @since               2.0
64          * @return              An error code
65          * @param[in]   appId                           The application ID.
66          * @param[in]   pBitwisePrivilege       The bitwise privilege information.
67          * @exception   E_SUCCESS                       The method is successful.
68          * @exception   E_INVALID_ARG           A specified input parameter is invalid.
69          */
70         result Construct(const Tizen::App::AppId& appId, const byte* pBitwisePrivilege, const Tizen::Base::Collection::ArrayList* pPrivilegeStringList);
71
72         /**
73          * Initializes an instance of _PrivilegeInfo and sets its base information using stored privilege information.
74          *
75          * @since               2.0
76          * @return              An error code
77          * @param[in]   appId                                   The application ID.
78          * @param[in]   encryptedPrivileges             A string containing encrypted privilege information.
79          * @param[in]   checksum                                A string containing checksum of privilege information.
80          * @exception   E_SUCCESS                               The method is successful.
81          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
82          */
83         result Construct(const Tizen::App::AppId& appId, const Tizen::Base::String& encryptedPrivileges, const Tizen::Base::String& checksum,
84                         const Tizen::Base::Collection::ArrayList* pPrivilegeStringList);
85
86         /**
87          * Initializes an instance of _PrivilegeInfo and sets its base information using stored privilege and visibility information.
88          *
89          * @since               2.0
90          * @return              An error code
91          * @param[in]   appId                                   The application ID.
92          * @param[in]   encryptedPrivileges             A string containing encrypted privilege information.
93          * @param[in]   checksum                                A string containing checksum of privilege information.
94          * @exception   E_SUCCESS                               The method is successful.
95          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
96          */
97         result Construct(const Tizen::App::AppId& appId, const Tizen::Base::String& encryptedPrivileges, const Tizen::Base::String& checksum,
98                         const Tizen::Base::String& encryptedVisibiliity, const Tizen::Base::String& visibilityChecksum, const Tizen::Base::Collection::ArrayList* pPrivilegeStringList);
99
100         /**
101          * Initializes an instance of _PrivilegeInfo and sets its base information using _PrivilegeInfo instance.
102          *
103          * @since               2.0
104          * @return              An error code
105          * @param[in]   privilegeInfo                   An instance of _PrivilegeInfo.
106          * @exception   E_SUCCESS                               The method is successful.
107          * @exception   E_AUTHENTICATION                The authentication has failed.
108          * @exception   E_INVALID_ARG                   A specified input parameter is invalid.
109          */
110         result Construct(const _PrivilegeInfo& privilegeInfo);
111
112         /**
113          * CCreates and returns a polymorphic copy of _PrivilegeInfo instance.
114          *
115          * @return      The clone of this instance
116          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
117          */
118
119         _PrivilegeInfo* CloneN(void) const;
120
121         /**
122          * Gets the application ID.
123          *
124          * @since               2.0
125          * @return              The application id
126          */
127         const Tizen::Base::String GetAppId(void) const;
128
129         /**
130          * Gets the bitwise privilege information.
131          *
132          * @since               2.0
133          * @return              An error code
134          * @param[out]  pBitwisePrivilege       The bitwise privilege information.
135          * @exception   E_SUCCESS                       The method is successful.
136          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
137          */
138         result GetBitwisePrivilegeN(byte*& pBitwisePrivilege) const;
139
140         /**
141          * Gets the encrypted string of bitwise privilege information.
142          *
143          * @since               2.0
144          * @return              An error code
145          * @param[out]  encryptedPrivileges     A string containing encrypted privilege information.
146          * @exception   E_SUCCESS                       The method is successful.
147          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
148          * @exception   E_SYSTEM                        An unexpected system error occurred.
149          */
150         result GetEncryptedBitwise(Tizen::Base::String& encryptedPrivileges) const;
151
152         /**
153          * Gets the checksum of bitwise privilege information.
154          *
155          * @since               2.0
156          * @return              An error code
157          * @param[out]  checksum                        A string containing checksum of privilege information.
158          * @exception   E_SUCCESS                       The method is successful.
159          * @exception   E_SYSTEM                        An unexpected system error occurred.
160          */
161         result GetChecksum(Tizen::Base::String& checksum) const;
162
163         /**
164          * Checks whether the application has a privilege to invoke.
165          *
166          * @since               2.0
167          * @return              A boolean value of the result
168          * @param[int]  privilege               A value of enumerator of the specified privilege.
169          */
170         bool HasPrivilege(_Privilege privilege) const;
171
172         /**
173          * Checks whether the application has a privilege to invoke. @n
174          * Unlike HasPrivilege, HasPrivilegeEx does not print the log.
175          *
176          * @since               2.1
177          * @return              A boolean value of the result
178          * @param[int]  privilege               A value of enumerator of the specified privilege.
179          */
180         bool HasPrivilegeEx(_Privilege privilege) const;
181
182         /**
183          * Checks whether the application has a privilege to invoke.
184          *
185          * @since               2.1
186          * @return              A boolean value of the result
187          * @param[in]   privilege               A string of the specified privilege.
188          */
189         bool HasPrivilege(const Tizen::Base::String& privilege) const;
190
191 private:
192
193         result VerifyIntegrity(const Tizen::App::AppId& appId, const byte* targetBitwisePrivilege, const Tizen::Base::String& storedChecksum, int length);
194         result VerifyIntegrity(const Tizen::App::AppId& appId, const byte* targetBitwisePrivilege, const Tizen::Base::String& storedChecksum, int length, int visibility, const Tizen::Base::String& storedVisibilityChecksum);
195         result VerifyIntegrityEx(const Tizen::App::AppId& appId, const byte* targetBitwisePrivilege, const Tizen::Base::String& storedChecksum, int length);
196
197         _PrivilegeInfo(const _PrivilegeInfo& rhs);
198         _PrivilegeInfo& operator =(const _PrivilegeInfo& rhs);
199
200 private:
201         Tizen::App::AppId __appId;
202         int __apiVisibility;
203         byte __bitwisePrivilege[MAX_BITWISE_PRIV_SIZE];
204         int __bitwiseLength;
205         Tizen::Base::Collection::ArrayList __privilegeList;
206
207 };  // _PrivilegeInfo
208
209 }} // Tizen::Security
210
211 #endif // _FSEC_INTERNAL_PRIVILEGE_INFO_H_