Common ckm functions moved to separate file
[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_app(const char* label);
29
30 // Class responsible for db cleanup after positive tests. Will remove all used aliases in destructor
31 class DBCleanup
32 {
33 public:
34     DBCleanup() {}
35
36     const char* key(const char* alias)
37     {
38         return m_keys.insert(CKM::Alias(alias)).first->c_str();
39     }
40
41     const char* cert(const char* alias)
42     {
43         return m_certs.insert(CKM::Alias(alias)).first->c_str();
44     }
45
46     const char* data(const char* alias)
47     {
48         return m_data.insert(CKM::Alias(alias)).first->c_str();
49     }
50
51     ~DBCleanup();
52
53 private:
54     std::unordered_set<CKM::Alias> m_keys;
55     std::unordered_set<CKM::Alias> m_certs;
56     std::unordered_set<CKM::Alias> m_data;
57 };
58
59 // scoped free
60 typedef std::unique_ptr<char, void (*)(void *)> CharPtr;
61
62 // returns process label
63 CharPtr get_label();
64
65 // changes process label
66 void change_label(const char* label);
67
68 // changes process label upon construction and restores it upon destruction
69 class ScopedLabel
70 {
71 public:
72     ScopedLabel(const char* label);
73     ~ScopedLabel();
74
75 private:
76     CharPtr m_original_label;
77 };