forked from jetwhiz/encfs4win
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CipherFileIO.h
97 lines (75 loc) · 2.73 KB
/
CipherFileIO.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*****************************************************************************
* Author: Valient Gough <[email protected]>
*
*****************************************************************************
* Copyright (c) 2004, Valient Gough
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http:https://www.gnu.org/licenses/>.
*/
#ifndef _CipherFileIO_incl_
#define _CipherFileIO_incl_
#include <inttypes.h>
#include <memory>
#include <stdint.h>
#include <sys/types.h>
#include "BlockFileIO.h"
#include "CipherKey.h"
#include "FSConfig.h"
#include "FileUtils.h"
#include "Interface.h"
namespace encfs {
class Cipher;
class FileIO;
struct IORequest;
/*
Implement the FileIO interface encrypting data in blocks.
Uses BlockFileIO to handle the block scatter / gather issues.
*/
class CipherFileIO : public BlockFileIO {
public:
CipherFileIO(const std::shared_ptr<FileIO> &base, const FSConfigPtr &cfg);
virtual ~CipherFileIO();
virtual Interface getInterface() const;
virtual void setFileName(const char *fileName);
virtual const char *getFileName() const;
virtual bool setIV(uint64_t iv);
virtual int open(int flags);
virtual int getAttr(struct stat_st *stbuf) const;
virtual FUSE_OFF_T getSize() const;
virtual int truncate(FUSE_OFF_T size);
virtual bool isWritable() const;
private:
virtual ssize_t readOneBlock(const IORequest &req) const;
virtual bool writeOneBlock(const IORequest &req);
virtual void generateReverseHeader(unsigned char *data);
void initHeader();
bool writeHeader();
bool blockRead(unsigned char *buf, int size, uint64_t iv64) const;
bool streamRead(unsigned char *buf, int size, uint64_t iv64) const;
bool blockWrite(unsigned char *buf, int size, uint64_t iv64) const;
bool streamWrite(unsigned char *buf, int size, uint64_t iv64) const;
ssize_t read(const IORequest &req) const;
std::shared_ptr<FileIO> base;
FSConfigPtr fsConfig;
// if haveHeader is true, then we have a transparent file header which
// contains a 64 bit initialization vector.
bool haveHeader;
uint64_t externalIV;
uint64_t fileIV;
int lastFlags;
std::shared_ptr<Cipher> cipher;
CipherKey key;
};
} // namespace encfs
#endif