-
Notifications
You must be signed in to change notification settings - Fork 1
/
PieceService.h
60 lines (48 loc) · 1.37 KB
/
PieceService.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
#ifndef __PIECESERVICE_H
#define __PIECESERVICE_H
#include <wx/wx.h>
#include <wx/filename.h>
#include <wx/file.h>
#include <wx/ffile.h>
#include <openssl/evp.h>
#include <vector>
#include <algorithm>
namespace RAIN
{
namespace BEnc
{
class Value;
class Dictionary;
};
class ManifestCreationFile;
class ManifestEntry;
class PieceCreationResult
{
public:
size_t pieces;
size_t pieceSize;
unsigned long long dataSize;
};
enum PieceUnpackingResult
{
PUR_MISSING_PIECES = -2,
PUR_BAD_MANIFEST,
PUR_OK = 0
};
class PieceService
{
public:
static PieceCreationResult Create(std::vector<ManifestCreationFile*> *files, BEnc::Dictionary *pieces);
static enum PieceUnpackingResult Unpack(ManifestEntry *manifest);
static bool HasAllPieces(ManifestEntry *manifest);
private:
/* used by Create() */
static size_t EncryptAndWritePiece(const unsigned char *key, const unsigned char *iv, const wxString& protocol, wxFFile *f, unsigned char *in, size_t inl);
static wxString OpenNextPiece(wxFFile *f);
static wxString SealPiece(const wxString& filename);
static wxString GetPieceFileName(const wxString& hexhash);
/* used by Unpack() */
static wxString DecryptPiece(const wxString& hash, const unsigned char *key, const unsigned char *iv, const wxString& protocol);
};
}
#endif //__PIECESERVICE_H