CKM: Add error description in error message.
[platform/core/test/security-tests.git] / tests / ckm / ckm-common.h
1 /*
2  *  Copyright (c) 2000 - 2014 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 /*
17  * @file       ckm-common.h
18  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
19  * @version    1.0
20  */
21
22 #pragma once
23
24 #include <unordered_set>
25 #include <memory>
26 #include <ckm/ckm-type.h>
27
28 void switch_to_storage_user(const char* label);
29 void switch_to_storage_ocsp_user(const char* label);
30
31
32 // service lifecycle management
33 enum ServiceIdx {
34     LISTENER,
35     MANAGER
36 };
37 void start_service(ServiceIdx idx);
38 void stop_service(ServiceIdx idx);
39
40 // support for error printing
41 const char * CKMCErrorToString(int error);
42 std::string CKMCReadableError(int error);
43
44 // Class responsible for db cleanup after positive tests. Will remove all used aliases in destructor
45 class DBCleanup
46 {
47 public:
48     DBCleanup() {}
49
50     const char* alias(const char* alias)
51     {
52         return m_aliases.insert(CKM::Alias(alias)).first->c_str();
53     }
54
55     ~DBCleanup();
56
57 private:
58     std::unordered_set<CKM::Alias> m_aliases;
59 };
60
61 // scoped free
62 typedef std::unique_ptr<char, void (*)(void *)> CharPtr;
63
64 // returns process label
65 CharPtr get_label();
66
67 std::string aliasWithLabel(const char *label, const char *alias);
68
69 // changes process label
70 void change_label(const char* label);
71
72 // changes process label upon construction and restores it upon destruction
73 class ScopedLabel
74 {
75 public:
76     ScopedLabel(const char* label);
77     ~ScopedLabel();
78
79 private:
80     CharPtr m_original_label;
81 };