Merge branch 'security-manager' into tizen
[platform/core/test/security-tests.git] / src / common / app_def_privilege.h
1 /*
2  * Copyright (c) 2014-2017 Samsung Electronics Co., Ltd All Rights Reserved
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 #pragma once
17
18 #include <string>
19 #include <utility>
20 #include <vector>
21 #include <tuple>
22
23 #include <security-manager-types.h>
24 #include <dpl/test/test_runner.h>
25
26 class Privilege {
27 public:
28     enum Type {
29         UNSET,
30         UNTRUSTED,
31         LICENSED,
32     };
33
34     Privilege(std::string systemPrivilege, Type type = UNSET, std::string license = std::string())
35       : m_name(std::move(systemPrivilege))
36       , m_type(type)
37       , m_license(std::move(license))
38     {}
39
40     Privilege(std::string licensedPrivilege, std::string license)
41       : m_name(std::move(licensedPrivilege))
42       , m_type(LICENSED)
43       , m_license(std::move(license))
44     {}
45
46     bool isUnset() const { return m_type == UNSET; }
47     bool isUntrusted() const { return m_type == UNTRUSTED; }
48     bool isLicensed() const { return m_type == LICENSED; }
49
50     int getType() const { return m_type; }
51     app_defined_privilege_type getSMType () const {
52         RUNNER_ASSERT(m_type != UNSET);
53         if (isLicensed()) return SM_APP_DEFINED_PRIVILEGE_TYPE_LICENSED;
54         return SM_APP_DEFINED_PRIVILEGE_TYPE_UNTRUSTED;
55     }
56
57     const std::string& getName() const { return m_name; }
58     const std::string& getLicense() const { return m_license; }
59
60     const char *getNameC() const { return m_name.c_str(); }
61     const char *getLicenseC() const { return m_license.c_str(); }
62
63     operator const char *() const { return m_name.c_str(); }
64
65     operator std::string() const { return m_name; }
66
67 private:
68     std::string m_name;
69     Type m_type;
70     std::string m_license;
71 };
72
73 typedef std::vector<Privilege> PrivilegeVector;
74