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