e3b314d724c50acdd67ee131a56b9a9dd7ea6d98
[platform/core/test/security-tests.git] / src / ode / ode-tests-common.cpp
1 /*
2  *  Copyright (c) 2018 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  *  @file   ode-tests-common.cpp
17  *  @author Pawel Kowalski (p.kowalski2@partner.samsung.com)
18  *  @brief  Tests for the ODE API
19  */
20
21 #include <dpl/log/log.h>
22 #include <ode/keys.h>
23 #include "ode-tests-common.h"
24
25 #define ERRORDESCRIBE(name) case name: return #name
26
27 const char* ODEErrorToString(int error) {
28     switch(error) {
29         ERRORDESCRIBE(ODE_ERROR_NONE);
30         ERRORDESCRIBE(ODE_ERROR_INVALID_PARAMETER);
31         ERRORDESCRIBE(ODE_ERROR_CONNECTION_REFUSED);
32         ERRORDESCRIBE(ODE_ERROR_PERMISSION_DENIED);
33         ERRORDESCRIBE(ODE_ERROR_NO_SUCH_FILE);
34         ERRORDESCRIBE(ODE_ERROR_NO_SUCH_DEVICE);
35         ERRORDESCRIBE(ODE_ERROR_KEY_REJECTED);
36         ERRORDESCRIBE(ODE_ERROR_NO_DATA);
37         ERRORDESCRIBE(ODE_ERROR_RESOURCE_BUSY);
38         ERRORDESCRIBE(ODE_ERROR_UNKNOWN);
39         default: return "Error not defined";
40     }
41 }
42
43 #undef ERRORDESCRIBE
44
45 HelperKeys::HelperKeys(const char* device, const char* password, bool initialize) {
46     dev = device;
47     pass = password;
48
49     if (initialize) {
50         bool result;
51         assert_positive(ode_key_is_initialized, dev, &result);
52
53         if (!result) {
54             assert_positive(ode_key_init, dev, pass, ODE_KEY_DEFAULT_256BIT);
55         }
56     }
57 }
58
59 HelperKeys::~HelperKeys() {
60     ode_key_remove_master_key(dev);
61     ode_key_remove(dev, pass);
62 };