1 /*
2  * Copyright (C) 2018 Rafael Ostertag
3  *
4  * This file is part of YAPET.
5  *
6  * YAPET is free software: you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation, either version 3 of the License, or (at your option) any later
9  * version.
10  *
11  * YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * YAPET.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Additional permission under GNU GPL version 3 section 7
20  *
21  * If you modify this program, or any covered work, by linking or combining it
22  * with the OpenSSL project's OpenSSL library (or a modified version of that
23  * library), containing parts covered by the terms of the OpenSSL or SSLeay
24  * licenses, Rafael Ostertag grants you additional permission to convey the
25  * resulting work.  Corresponding Source for a non-source form of such a
26  * combination shall include the source code for the parts of OpenSSL used as
27  * well as that of the covered work.
28  */
29 
30 #ifndef _YAPET10FILE_HH
31 #define _YAPET10FILE_HH
32 
33 #include <list>
34 
35 #include "rawfile.hh"
36 #include "yapetfile.hh"
37 
38 namespace yapet {
39 
40 /**
41  * YAPET 1.0 file.
42  */
43 class Yapet10File : public YapetFile {
44    private:
45     std::string recognitionStringAsString() const;
46 
47    public:
48     static constexpr std::uint8_t RECOGNITION_STRING[]{'Y', 'A', 'P', 'E',
49                                                        'T', '1', '.', '0'};
50     static constexpr int RECOGNITION_STRING_SIZE{8};
51 
52     Yapet10File(const std::string& filename, bool create = false,
53                 bool secure = true);
54 
55     Yapet10File(const Yapet10File&) = delete;
56     Yapet10File& operator=(const Yapet10File&) = delete;
57 
58     Yapet10File(Yapet10File&& other);
59     Yapet10File& operator=(Yapet10File&& other);
60 
61     virtual ~Yapet10File();
62 
63     virtual void open();
64 
65     virtual bool hasValidFormat();
66 
67     virtual SecureArray readIdentifier();
68 
69     /**
70      * This is a noop on YAPET 1.0 files
71      */
72     virtual SecureArray readUnencryptedMetaData();
73 
74     virtual SecureArray readHeader();
75 
76     virtual std::list<SecureArray> readPasswordRecords();
77 
78     virtual void writeIdentifier();
79 
80     /**
81      * This is a noop on YAPET 1.0 files
82      */
83     virtual void writeUnencryptedMetaData(const SecureArray&);
84 
85     virtual void writeHeader(const SecureArray& header);
86 
87     virtual void writePasswordRecords(const std::list<SecureArray>& passwords);
88 
89     virtual int recognitionStringSize() const;
90     virtual const uint8_t* recognitionString() const;
91 };
92 }  // namespace yapet
93 
94 #endif /* _YAPET10FILE_HH */
95