scrambler.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2023 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef SCRAMBLER_HPP
#define SCRAMBLER_HPP
#include "../my_config.h"
#include <string>
#include "infinint.hpp"
#include "generic_file.hpp"
#include "erreurs.hpp"
#include "secu_string.hpp"
namespace libdar
{
class scrambler : public generic_file
{
public:
scrambler(const secu_string & pass, generic_file & hidden_side);
scrambler(const scrambler & ref) = delete;
scrambler(scrambler && ref) noexcept = delete;
scrambler & operator = (const scrambler & ref) = delete;
scrambler & operator = (scrambler && ref) noexcept = delete;
~scrambler() { if(buffer != nullptr) delete [] buffer; };
virtual bool skippable(skippability direction, const infinint & amount) override { if(ref == nullptr) throw SRC_BUG; return ref->skippable(direction, amount); };
virtual bool skip(const infinint & pos) override { if(ref == nullptr) throw SRC_BUG; return ref->skip(pos); };
virtual bool skip_to_eof() override { if(ref == nullptr) throw SRC_BUG; return ref->skip_to_eof(); };
virtual bool skip_relative(S_I x) override { if(ref == nullptr) throw SRC_BUG; return ref->skip_relative(x); };
virtual bool truncatable(const infinint & pos) const override { if(ref == nullptr) throw SRC_BUG; return ref->truncatable(pos); };
virtual infinint get_position() const override { if(ref == nullptr) throw SRC_BUG; return ref->get_position(); };
protected:
virtual void inherited_read_ahead(const infinint & amount) override { if(ref == nullptr) throw SRC_BUG; ref->read_ahead(amount); };
virtual U_I inherited_read(char *a, U_I size) override;
virtual void inherited_write(const char *a, U_I size) override;
virtual void inherited_truncate(const infinint & pos) override { if(ref == nullptr) throw SRC_BUG; ref->truncate(pos); };
virtual void inherited_sync_write() override {}; // nothing to do
virtual void inherited_flush_read() override {}; // nothing to do
virtual void inherited_terminate() override {}; // nothing to do
private:
secu_string key;
U_I len;
generic_file *ref;
unsigned char *buffer;
U_I buf_size;
};
} // end of namespace
#endif
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:77
libdar::generic_file::truncate
virtual void truncate(const infinint &pos)
truncate file at the given offset
libdar::generic_file::read_ahead
void read_ahead(const infinint &amount)
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
libdar::scrambler
scrambler is a very weak encryption scheme
Definition: scrambler.hpp:46
libdar::scrambler::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::scrambler::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition: scrambler.hpp:56
libdar::scrambler::get_position
virtual infinint get_position() const override
get the current read/write position
Definition: scrambler.hpp:61
libdar::scrambler::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
Definition: scrambler.hpp:58
libdar::scrambler::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
tells the object that several calls to read() will follow to probably obtain at least the given amoun...
Definition: scrambler.hpp:64
libdar::scrambler::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition: scrambler.hpp:70
libdar::scrambler::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition: scrambler.hpp:68
libdar::scrambler::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition: scrambler.hpp:69
libdar::scrambler::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition: scrambler.hpp:60
libdar::scrambler::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition: scrambler.hpp:57
libdar::scrambler::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
Definition: scrambler.hpp:59
libdar::scrambler::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
Definition: scrambler.hpp:67
libdar::scrambler::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::secu_string
class secu_string
Definition: secu_string.hpp:54
erreurs.hpp
contains all the excetion class thrown by libdar
generic_file.hpp
class generic_file is defined here as well as class fichier
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
secu_string.hpp
this file contains the definition of secu_string class, a std::string like class but allocated in sec...