libstorage-ng
Encryption.h
1 /*
2  * Copyright (c) [2016-2017] SUSE LLC
3  *
4  * All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, contact Novell, Inc.
17  *
18  * To contact Novell about this file by physical or electronic mail, you may
19  * find current contact information at www.novell.com.
20  */
21 
22 
23 #ifndef STORAGE_ENCRYPTION_H
24 #define STORAGE_ENCRYPTION_H
25 
26 
27 #include "storage/Devices/BlkDevice.h"
28 
29 
30 namespace storage
31 {
32 
33  enum class EncryptionType {
34  NONE, TWOFISH, TWOFISH_OLD, TWOFISH256_OLD, LUKS, UNKNOWN
35  };
36 
37 
38  // TODO depending on the encryption types supported the Encryption class
39  // can be dropped or be abstract
40 
41 
45  class Encryption : public BlkDevice
46  {
47  public:
48 
49  static Encryption* create(Devicegraph* devicegraph, const std::string& name);
50  static Encryption* load(Devicegraph* devicegraph, const xmlNode* node);
51 
52  EncryptionType get_type() const;
53 
54  const std::string& get_password() const;
55 
56  void set_password(const std::string& password);
57 
62  MountByType get_mount_by() const;
63 
68  void set_mount_by(MountByType mount_by);
69 
76  void set_default_mount_by();
77 
81  const std::vector<std::string>& get_crypt_options() const;
82 
86  void set_crypt_options(const std::vector<std::string>& crypt_options);
87 
92  bool is_in_etc_crypttab() const;
93 
97  void set_in_etc_crypttab(bool in_etc_crypttab);
98 
102  const BlkDevice* get_blk_device() const;
103 
104  static std::vector<Encryption*> get_all(Devicegraph* devicegraph);
105  static std::vector<const Encryption*> get_all(const Devicegraph* devicegraph);
106 
107  public:
108 
109  class Impl;
110 
111  Impl& get_impl();
112  const Impl& get_impl() const;
113 
114  virtual Encryption* clone() const override;
115 
116  protected:
117 
118  Encryption(Impl* impl);
119 
120  };
121 
122 
123  bool is_encryption(const Device* device);
124 
131  Encryption* to_encryption(Device* device);
132 
136  const Encryption* to_encryption(const Device* device);
137 
138 }
139 
140 #endif
const std::vector< std::string > & get_crypt_options() const
Get options (fourth field) in /etc/crypttab.
bool is_in_etc_crypttab() const
Query whether the LUKS device is present (probed devicegraph) or will be present (staging devicegraph...
Encryption * to_encryption(Device *device)
Converts pointer to Device to pointer to Encryption.
void set_default_mount_by()
Set the mount-by method to the global default, see Storage::get_default_mount_by().
void set_in_etc_crypttab(bool in_etc_crypttab)
Set whether the LUKS device will be present in /etc/crypttab.
void set_crypt_options(const std::vector< std::string > &crypt_options)
Set options (fourth field) in /etc/crypttab.
void set_mount_by(MountByType mount_by)
Set the mount-by method.
An encryption layer on a blk device.
Definition: Encryption.h:45
The master container of the libstorage.
Definition: Devicegraph.h:153
An abstract Block Device.
Definition: BlkDevice.h:41
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
MountByType get_mount_by() const
Get the mount-by method.
The storage namespace.
Definition: Actiongraph.h:37
const BlkDevice * get_blk_device() const
Return underlying blk device.
MountByType
The key by which the mount program identifies a mountable.
Definition: Mountable.h:54