2014-12-11 10:50:15 +03:00
|
|
|
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
|
2014-10-10 13:50:55 +04:00
|
|
|
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
|
2013-07-18 21:33:25 +04:00
|
|
|
|
|
|
|
#include "backup_file.hh"
|
|
|
|
|
|
|
|
#include "encrypted_file.hh"
|
|
|
|
#include "encryption.hh"
|
|
|
|
#include "message.hh"
|
|
|
|
|
|
|
|
namespace BackupFile {
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
FileFormatVersion = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
void save( string const & fileName, EncryptionKey const & encryptionKey,
|
|
|
|
BackupInfo const & backupInfo )
|
|
|
|
{
|
|
|
|
EncryptedFile::OutputStream os( fileName.c_str(), encryptionKey,
|
|
|
|
Encryption::ZeroIv );
|
|
|
|
os.writeRandomIv();
|
|
|
|
|
|
|
|
FileHeader header;
|
|
|
|
header.set_version( FileFormatVersion );
|
|
|
|
Message::serialize( header, os );
|
|
|
|
|
|
|
|
Message::serialize( backupInfo, os );
|
|
|
|
os.writeAdler32();
|
|
|
|
}
|
|
|
|
|
|
|
|
void load( string const & fileName, EncryptionKey const & encryptionKey,
|
|
|
|
BackupInfo & backupInfo )
|
|
|
|
{
|
|
|
|
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( backupInfo, is );
|
|
|
|
is.checkAdler32();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|