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