Add recovery APIs to use when there is something wrong with encryption
[platform/core/security/ode.git] / lib / external-encryption.cpp
1 /*
2  *  Copyright (c) 2015 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 #include "rmi/external-encryption.h"
17
18 namespace ode {
19
20 ExternalEncryption::ExternalEncryption(ODEControlContext& ctx) :
21         context(ctx)
22 {
23 }
24
25 ExternalEncryption::~ExternalEncryption()
26 {
27 }
28
29 int ExternalEncryption::mount(const std::string& password)
30 {
31         try {
32                 return context->methodCall<int>("ExternalEncryption::mount", password);
33         } catch (runtime::Exception& e) {
34                 return -1;
35         }
36 }
37
38 int ExternalEncryption::umount()
39 {
40         try {
41                 return context->methodCall<int>("ExternalEncryption::umount");
42         } catch (runtime::Exception& e) {
43                 return -1;
44         }
45 }
46
47 int ExternalEncryption::encrypt(const std::string& password, unsigned int options)
48 {
49         try {
50                 return context->methodCall<int>("ExternalEncryption::encrypt", password, options);
51         } catch (runtime::Exception& e) {
52                 return -1;
53         }
54 }
55
56 int ExternalEncryption::decrypt(const std::string& password)
57 {
58         try {
59                 return context->methodCall<int>("ExternalEncryption::decrypt", password);
60         } catch (runtime::Exception& e) {
61                 return -1;
62         }
63 }
64
65 int ExternalEncryption::recovery()
66 {
67         try {
68                 return context->methodCall<int>("ExternalEncryption::recovery");
69         } catch (runtime::Exception& e) {
70                 return -1;
71         }
72 }
73
74 int ExternalEncryption::isPasswordInitialized()
75 {
76         try {
77                 return context->methodCall<int>("ExternalEncryption::isPasswordInitialized");
78         } catch (runtime::Exception& e) {
79                 return -1;
80         }
81 }
82
83 int ExternalEncryption::initPassword(const std::string& password)
84 {
85         try {
86                 return context->methodCall<int>("ExternalEncryption::initPassword",
87                                                                                 password);
88         } catch (runtime::Exception& e) {
89                 return -1;
90         }
91 }
92
93 int ExternalEncryption::cleanPassword(const std::string& password)
94 {
95         try {
96                 return context->methodCall<int>("ExternalEncryption::cleanPassword",
97                                                                                 password);
98         } catch (runtime::Exception& e) {
99                 return -1;
100         }
101 }
102
103 int ExternalEncryption::changePassword(const std::string& oldPassword,
104                                                                         const std::string& newPassword)
105 {
106         try {
107                 return context->methodCall<int>("ExternalEncryption::changePassword",
108                                                                                 oldPassword, newPassword);
109         } catch (runtime::Exception& e) {
110                 return -1;
111         }
112 }
113
114 int ExternalEncryption::verifyPassword(const std::string& password)
115 {
116         try {
117                 return context->methodCall<int>("ExternalEncryption::verifyPassword",
118                                                                                 password);
119         } catch (runtime::Exception& e) {
120                 return -1;
121         }
122 }
123
124 int ExternalEncryption::getState()
125 {
126         try {
127                 return context->methodCall<int>("ExternalEncryption::getState");
128         } catch (runtime::Exception& e) {
129                 return -1;
130         }
131 }
132
133 unsigned int ExternalEncryption::getSupportedOptions()
134 {
135         try {
136                 return context->methodCall<unsigned int>("ExternalEncryption::getSupportedOptions");
137         } catch (runtime::Exception& e) {
138                 return -1;
139         }
140 }
141
142 } // namespace ode