1 /*
2     SPDX-FileCopyrightText: 2010 Volker Lanz <vl@fidra.de>
3     SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
4     SPDX-FileCopyrightText: 2016-2018 Andrius Štikonas <andrius@stikonas.eu>
5     SPDX-FileCopyrightText: 2018 Huzaifa Faruqui <huzaifafaruqui@gmail.com>
6 
7     SPDX-License-Identifier: GPL-3.0-or-later
8 */
9 
10 #ifndef KPMCORE_COPYSOURCESHRED_H
11 #define KPMCORE_COPYSOURCESHRED_H
12 
13 #include "core/copysource.h"
14 
15 #include <QFile>
16 
17 class CopyTarget;
18 class QString;
19 
20 /** A source for securely overwriting a partition (shredding).
21 
22     Represents a source of data (random or zeros) to copy from. Used to securely overwrite data on disk.
23 
24     @author Volker Lanz <vl@fidra.de>
25 */
26 class CopySourceShred : public CopySource
27 {
28 public:
29     CopySourceShred(qint64 size, bool randomShred);
30 
31 public:
32     bool open() override;
33     qint64 length() const override;
34 
overlaps(const CopyTarget &)35     bool overlaps(const CopyTarget&) const override {
36         return false;    /**< @return false for shred source */
37     }
firstByte()38     qint64 firstByte() const override {
39         return 0;    /**< @return 0 for shred source */
40     }
lastByte()41     qint64 lastByte() const override {
42         return length();    /**< @return equal to length for shred source. @see length() */
43     }
path()44     QString path() const override {
45         return m_SourceFile.fileName();
46     }
47 
48 protected:
sourceFile()49     QFile& sourceFile() {
50         return m_SourceFile;
51     }
sourceFile()52     const QFile& sourceFile() const {
53         return m_SourceFile;
54     }
size()55     qint64 size() const {
56         return m_Size;
57     }
58 
59 private:
60     qint64 m_Size;
61     QFile m_SourceFile;
62 };
63 
64 #endif
65