Change to allow duplicated mount/umount API calls for lockscreen
[platform/core/security/ode.git] / server / engine / encryption / dmcrypt-engine.h
1 /*
2  *  Copyright (c) 2016 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 #ifndef __DMCRYPT_ENGINE_H__
18 #define __DMCRYPT_ENGINE_H__
19
20 #include <vector>
21 #include <string>
22 #include <atomic>
23
24 #include "progress-bar.h"
25
26 namespace ode {
27
28 class DMCryptEngine final {
29 public:
30         DMCryptEngine(const std::string &src, const std::string &dest, const ProgressBar &prgsBar);
31         DMCryptEngine(const DMCryptEngine &) = delete;
32         DMCryptEngine(DMCryptEngine &&) = delete;
33         ~DMCryptEngine();
34
35         DMCryptEngine &operator=(const DMCryptEngine &) = delete;
36         DMCryptEngine &operator=(DMCryptEngine &&) = delete;
37
38         const std::string &getSource()
39         {
40                 return source;
41         }
42
43         const std::string &getDestination()
44         {
45                 return destination;
46         }
47
48         typedef std::vector<unsigned char> data;
49
50         void mount(const data &key, unsigned int options);
51         void umount();
52         bool isMounted();
53
54         void encrypt(const data &key, unsigned int options);
55         void decrypt(const data &key, unsigned int options);
56
57         bool isKeyMetaSet();
58         const data getKeyMeta();
59         void setKeyMeta(const data &data);
60         void clearKeyMeta();
61
62         unsigned int getSupportedOptions();
63
64 private:
65         std::string source, destination;
66         ProgressBar progress;
67         std::atomic<bool> mounted;
68 };
69
70 } // namespace ode
71 #endif // __DMCRYPT_ENGINE_H__