forked from zbackup/zbackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage_info_file.cc
89 lines (71 loc) · 2.36 KB
/
storage_info_file.cc
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
// Copyright (c) 2012-2014 Konstantin Isakov <[email protected]> and ZBackup contributors, see CONTRIBUTORS
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
#include <stddef.h>
#include "encrypted_file.hh"
#include "message.hh"
#include "storage_info_file.hh"
#include "debug.hh"
namespace StorageInfoFile {
enum
{
FileFormatVersion = 1
};
void save( string const & fileName, StorageInfo const & storageInfo )
{
dPrintf( "Saving storage info...\n" );
EncryptedFile::OutputStream os( fileName.c_str(), EncryptionKey::noKey(),
NULL );
FileHeader header;
header.set_version( FileFormatVersion );
Message::serialize( header, os );
Message::serialize( storageInfo, os );
os.writeAdler32();
}
void load( string const & fileName, StorageInfo & storageInfo )
{
dPrintf( "Loading storage info...\n" );
EncryptedFile::InputStream is( fileName.c_str(), EncryptionKey::noKey(),
NULL );
FileHeader header;
Message::parse( header, is );
if ( header.version() != FileFormatVersion )
throw exUnsupportedVersion();
Message::parse( storageInfo, is );
is.checkAdler32();
}
}
namespace ExtendedStorageInfoFile {
enum
{
FileFormatVersion = 1
};
void save( string const & fileName, EncryptionKey const & encryptionKey,
ExtendedStorageInfo const & extendedStorageInfo )
{
dPrintf( "Saving extended storage info, hasKey: %s\n",
encryptionKey.hasKey() ? "true" : "false" );
EncryptedFile::OutputStream os( fileName.c_str(), encryptionKey,
Encryption::ZeroIv );
os.writeRandomIv();
FileHeader header;
header.set_version( FileFormatVersion );
Message::serialize( header, os );
Message::serialize( extendedStorageInfo, os );
os.writeAdler32();
}
void load( string const & fileName, EncryptionKey const & encryptionKey,
ExtendedStorageInfo & extendedStorageInfo )
{
dPrintf( "Loading extended storage info, hasKey: %s\n",
encryptionKey.hasKey() ? "true" : "false" );
EncryptedFile::InputStream is( fileName.c_str(), encryptionKey,
Encryption::ZeroIv );
is.consumeRandomIv();
FileHeader header;
Message::parse( header, is );
if ( header.version() != FileFormatVersion )
throw exUnsupportedVersion();
Message::parse( extendedStorageInfo, is );
is.checkAdler32();
}
}