modernize: =default, pass by value

This commit is contained in:
Valient Gough 2017-08-03 22:18:25 -07:00
parent 169101c80b
commit 71e2bcc84d
No known key found for this signature in database
GPG Key ID: 33C65E29813C14DF
27 changed files with 84 additions and 94 deletions

View File

@ -22,6 +22,7 @@
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <utility>
#include "Cipher.h" #include "Cipher.h"
#include "CipherKey.h" #include "CipherKey.h"
@ -94,20 +95,19 @@ Interface BlockNameIO::CurrentInterface(bool caseInsensitive) {
return Interface("nameio/block", 4, 0, 2); return Interface("nameio/block", 4, 0, 2);
} }
BlockNameIO::BlockNameIO(const Interface &iface, BlockNameIO::BlockNameIO(const Interface &iface, std::shared_ptr<Cipher> cipher,
const std::shared_ptr<Cipher> &cipher, CipherKey key, int blockSize,
const CipherKey &key, int blockSize,
bool caseInsensitiveEncoding) bool caseInsensitiveEncoding)
: _interface(iface.current()), : _interface(iface.current()),
_bs(blockSize), _bs(blockSize),
_cipher(cipher), _cipher(std::move(cipher)),
_key(key), _key(std::move(key)),
_caseInsensitive(caseInsensitiveEncoding) { _caseInsensitive(caseInsensitiveEncoding) {
// just to be safe.. // just to be safe..
rAssert(blockSize < 128); rAssert(blockSize < 128);
} }
BlockNameIO::~BlockNameIO() {} BlockNameIO::~BlockNameIO() = default;
Interface BlockNameIO::interface() const { Interface BlockNameIO::interface() const {
return CurrentInterface(_caseInsensitive); return CurrentInterface(_caseInsensitive);

View File

@ -41,8 +41,8 @@ class BlockNameIO : public NameIO {
public: public:
static Interface CurrentInterface(bool caseInsensitive = false); static Interface CurrentInterface(bool caseInsensitive = false);
BlockNameIO(const Interface &iface, const std::shared_ptr<Cipher> &cipher, BlockNameIO(const Interface &iface, std::shared_ptr<Cipher> cipher,
const CipherKey &key, int blockSize, CipherKey key, int blockSize,
bool caseInsensitiveEncoding = false); bool caseInsensitiveEncoding = false);
virtual ~BlockNameIO(); virtual ~BlockNameIO();

View File

@ -148,9 +148,9 @@ std::shared_ptr<Cipher> Cipher::New(const Interface &iface, int keyLen) {
return result; return result;
} }
Cipher::Cipher() {} Cipher::Cipher() = default;
Cipher::~Cipher() {} Cipher::~Cipher() = default;
unsigned int Cipher::MAC_32(const unsigned char *src, int len, unsigned int Cipher::MAC_32(const unsigned char *src, int len,
const CipherKey &key, uint64_t *chainedIV) const { const CipherKey &key, uint64_t *chainedIV) const {

View File

@ -28,6 +28,7 @@
#include <memory> #include <memory>
#include <openssl/sha.h> #include <openssl/sha.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <utility>
#include "BlockFileIO.h" #include "BlockFileIO.h"
#include "Cipher.h" #include "Cipher.h"
@ -47,10 +48,10 @@ static Interface CipherFileIO_iface("FileIO/Cipher", 2, 0, 1);
const int HEADER_SIZE = 8; // 64 bit initialization vector.. const int HEADER_SIZE = 8; // 64 bit initialization vector..
CipherFileIO::CipherFileIO(const std::shared_ptr<FileIO> &_base, CipherFileIO::CipherFileIO(std::shared_ptr<FileIO> _base,
const FSConfigPtr &cfg) const FSConfigPtr &cfg)
: BlockFileIO(cfg->config->blockSize, cfg), : BlockFileIO(cfg->config->blockSize, cfg),
base(_base), base(std::move(_base)),
haveHeader(cfg->config->uniqueIV), haveHeader(cfg->config->uniqueIV),
externalIV(0), externalIV(0),
fileIV(0), fileIV(0),
@ -63,7 +64,7 @@ CipherFileIO::CipherFileIO(const std::shared_ptr<FileIO> &_base,
<< "FS block size must be multiple of cipher block size"; << "FS block size must be multiple of cipher block size";
} }
CipherFileIO::~CipherFileIO() {} CipherFileIO::~CipherFileIO() = default;
Interface CipherFileIO::interface() const { return CipherFileIO_iface; } Interface CipherFileIO::interface() const { return CipherFileIO_iface; }

View File

@ -45,7 +45,7 @@ struct IORequest;
*/ */
class CipherFileIO : public BlockFileIO { class CipherFileIO : public BlockFileIO {
public: public:
CipherFileIO(const std::shared_ptr<FileIO> &base, const FSConfigPtr &cfg); CipherFileIO(std::shared_ptr<FileIO> base, const FSConfigPtr &cfg);
virtual ~CipherFileIO(); virtual ~CipherFileIO();
virtual Interface interface() const; virtual Interface interface() const;

View File

@ -22,8 +22,8 @@
namespace encfs { namespace encfs {
AbstractCipherKey::AbstractCipherKey() {} AbstractCipherKey::AbstractCipherKey() = default;
AbstractCipherKey::~AbstractCipherKey() {} AbstractCipherKey::~AbstractCipherKey() = default;
} // namespace encfs } // namespace encfs

View File

@ -33,9 +33,9 @@ using namespace std;
namespace encfs { namespace encfs {
ConfigReader::ConfigReader() {} ConfigReader::ConfigReader() = default;
ConfigReader::~ConfigReader() {} ConfigReader::~ConfigReader() = default;
// read the entire file into a ConfigVar instance and then use that to decode // read the entire file into a ConfigVar instance and then use that to decode
// into mapped variables. // into mapped variables.

View File

@ -21,14 +21,14 @@
#ifndef _Context_incl_ #ifndef _Context_incl_
#define _Context_incl_ #define _Context_incl_
#include <list>
#include <algorithm> #include <algorithm>
#include <atomic>
#include <list>
#include <memory> #include <memory>
#include <pthread.h> #include <pthread.h>
#include <set> #include <set>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <atomic>
#include "encfs.h" #include "encfs.h"
@ -85,8 +85,7 @@ class EncFS_Context {
* us. * us.
*/ */
typedef std::unordered_map<std::string, typedef std::unordered_map<std::string, std::list<std::shared_ptr<FileNode>>>
std::list<std::shared_ptr<FileNode>>>
FileMap; FileMap;
mutable pthread_mutex_t contextMutex; mutable pthread_mutex_t contextMutex;

View File

@ -37,6 +37,7 @@
#include "internal/easylogging++.h" #include "internal/easylogging++.h"
#include <cstring> #include <cstring>
#include <utility>
#include "Context.h" #include "Context.h"
#include "Error.h" #include "Error.h"
@ -51,20 +52,13 @@ class DirDeleter {
void operator()(DIR *d) { ::closedir(d); } void operator()(DIR *d) { ::closedir(d); }
}; };
DirTraverse::DirTraverse(const std::shared_ptr<DIR> &_dirPtr, uint64_t _iv, DirTraverse::DirTraverse(std::shared_ptr<DIR> _dirPtr, uint64_t _iv,
const std::shared_ptr<NameIO> &_naming) std::shared_ptr<NameIO> _naming)
: dir(_dirPtr), iv(_iv), naming(_naming) {} : dir(std::move(_dirPtr)), iv(_iv), naming(std::move(_naming)) {}
DirTraverse::DirTraverse(const DirTraverse &src) DirTraverse::DirTraverse(const DirTraverse &src) = default;
: dir(src.dir), iv(src.iv), naming(src.naming) {}
DirTraverse &DirTraverse::operator=(const DirTraverse &src) { DirTraverse &DirTraverse::operator=(const DirTraverse &src) = default;
dir = src.dir;
iv = src.iv;
naming = src.naming;
return *this;
}
DirTraverse::~DirTraverse() { DirTraverse::~DirTraverse() {
dir.reset(); dir.reset();
@ -143,13 +137,12 @@ class RenameOp {
list<RenameEl>::const_iterator last; list<RenameEl>::const_iterator last;
public: public:
RenameOp(DirNode *_dn, const std::shared_ptr<list<RenameEl> > &_renameList) RenameOp(DirNode *_dn, std::shared_ptr<list<RenameEl> > _renameList)
: dn(_dn), renameList(_renameList) { : dn(_dn), renameList(std::move(_renameList)) {
last = renameList->begin(); last = renameList->begin();
} }
RenameOp(const RenameOp &src) RenameOp(const RenameOp &src) = default;
: dn(src.dn), renameList(src.renameList), last(src.last) {}
~RenameOp(); ~RenameOp();
@ -252,7 +245,7 @@ DirNode::DirNode(EncFS_Context *_ctx, const string &sourceDir,
naming = fsConfig->nameCoding; naming = fsConfig->nameCoding;
} }
DirNode::~DirNode() {} DirNode::~DirNode() = default;
bool DirNode::hasDirectoryNameDependency() const { bool DirNode::hasDirectoryNameDependency() const {
return naming ? naming->getChainedNameIV() : false; return naming ? naming->getChainedNameIV() : false;

View File

@ -48,8 +48,8 @@ struct RenameEl;
class DirTraverse { class DirTraverse {
public: public:
DirTraverse(const std::shared_ptr<DIR> &dirPtr, uint64_t iv, DirTraverse(std::shared_ptr<DIR> dirPtr, uint64_t iv,
const std::shared_ptr<NameIO> &naming); std::shared_ptr<NameIO> naming);
DirTraverse(const DirTraverse &src); DirTraverse(const DirTraverse &src);
~DirTraverse(); ~DirTraverse();

View File

@ -22,9 +22,9 @@
namespace encfs { namespace encfs {
FileIO::FileIO() {} FileIO::FileIO() = default;
FileIO::~FileIO() {} FileIO::~FileIO() = default;
int FileIO::blockSize() const { return 1; } int FileIO::blockSize() const { return 1; }

View File

@ -21,13 +21,13 @@
#ifndef _FileNode_incl_ #ifndef _FileNode_incl_
#define _FileNode_incl_ #define _FileNode_incl_
#include <atomic>
#include <inttypes.h> #include <inttypes.h>
#include <memory> #include <memory>
#include <pthread.h> #include <pthread.h>
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <sys/types.h> #include <sys/types.h>
#include <atomic>
#include "CipherKey.h" #include "CipherKey.h"
#include "FSConfig.h" #include "FSConfig.h"

View File

@ -119,9 +119,9 @@ struct ConfigInfo {
{".encfs", Config_Prehistoric, nullptr, nullptr, nullptr, 0, 0}, {".encfs", Config_Prehistoric, nullptr, nullptr, nullptr, 0, 0},
{nullptr, Config_None, nullptr, nullptr, nullptr, 0, 0}}; {nullptr, Config_None, nullptr, nullptr, nullptr, 0, 0}};
EncFS_Root::EncFS_Root() {} EncFS_Root::EncFS_Root() = default;
EncFS_Root::~EncFS_Root() {} EncFS_Root::~EncFS_Root() = default;
bool fileExists(const char *fileName) { bool fileExists(const char *fileName) {
struct stat buf; struct stat buf;

View File

@ -20,6 +20,8 @@
#include "Interface.h" #include "Interface.h"
#include <utility>
#include "ConfigVar.h" #include "ConfigVar.h"
#include "Error.h" #include "Error.h"
@ -28,25 +30,19 @@ namespace encfs {
Interface::Interface(const char *name_, int Current, int Revision, int Age) Interface::Interface(const char *name_, int Current, int Revision, int Age)
: _name(name_), _current(Current), _revision(Revision), _age(Age) {} : _name(name_), _current(Current), _revision(Revision), _age(Age) {}
Interface::Interface(const std::string &name_, int Current, int Revision, Interface::Interface(std::string name_, int Current, int Revision, int Age)
int Age) : _name(std::move(name_)),
: _name(name_), _current(Current), _revision(Revision), _age(Age) {} _current(Current),
_revision(Revision),
_age(Age) {}
Interface::Interface(const Interface &src) Interface::Interface(const Interface &src)
: _name(src._name),
_current(src._current), = default;
_revision(src._revision),
_age(src._age) {}
Interface::Interface() : _current(0), _revision(0), _age(0) {} Interface::Interface() : _current(0), _revision(0), _age(0) {}
Interface &Interface::operator=(const Interface &src) { Interface &Interface::operator=(const Interface &src) = default;
_name = src._name;
_current = src._current;
_revision = src._revision;
_age = src._age;
return *this;
}
const std::string &Interface::name() const { return _name; } const std::string &Interface::name() const { return _name; }

View File

@ -37,7 +37,7 @@ class Interface {
are implemented. are implemented.
*/ */
Interface(const char *name, int Current, int Revision, int Age); Interface(const char *name, int Current, int Revision, int Age);
Interface(const std::string &name, int Current, int Revision, int Age); Interface(std::string name, int Current, int Revision, int Age);
Interface(const Interface &src); Interface(const Interface &src);
Interface(); Interface();

View File

@ -24,6 +24,7 @@
#include <cinttypes> #include <cinttypes>
#include <cstring> #include <cstring>
#include <sys/stat.h> #include <sys/stat.h>
#include <utility>
#include "BlockFileIO.h" #include "BlockFileIO.h"
#include "Cipher.h" #include "Cipher.h"
@ -56,10 +57,9 @@ int dataBlockSize(const FSConfigPtr &cfg) {
cfg->config->blockMACRandBytes; cfg->config->blockMACRandBytes;
} }
MACFileIO::MACFileIO(const std::shared_ptr<FileIO> &_base, MACFileIO::MACFileIO(std::shared_ptr<FileIO> _base, const FSConfigPtr &cfg)
const FSConfigPtr &cfg)
: BlockFileIO(dataBlockSize(cfg), cfg), : BlockFileIO(dataBlockSize(cfg), cfg),
base(_base), base(std::move(_base)),
cipher(cfg->cipher), cipher(cfg->cipher),
key(cfg->key), key(cfg->key),
macBytes(cfg->config->blockMACBytes), macBytes(cfg->config->blockMACBytes),
@ -72,7 +72,7 @@ MACFileIO::MACFileIO(const std::shared_ptr<FileIO> &_base,
<< ", randBytes = " << cfg->config->blockMACRandBytes; << ", randBytes = " << cfg->config->blockMACRandBytes;
} }
MACFileIO::~MACFileIO() {} MACFileIO::~MACFileIO() = default;
Interface MACFileIO::interface() const { return MACFileIO_iface; } Interface MACFileIO::interface() const { return MACFileIO_iface; }

View File

@ -44,7 +44,7 @@ class MACFileIO : public BlockFileIO {
result in a warning message from encfs -- the garbled data will still result in a warning message from encfs -- the garbled data will still
be made available.. be made available..
*/ */
MACFileIO(const std::shared_ptr<FileIO> &base, const FSConfigPtr &cfg); MACFileIO(std::shared_ptr<FileIO> base, const FSConfigPtr &cfg);
MACFileIO(); MACFileIO();
virtual ~MACFileIO(); virtual ~MACFileIO();

View File

@ -127,7 +127,7 @@ std::shared_ptr<NameIO> NameIO::New(const Interface &iface,
NameIO::NameIO() : chainedNameIV(false), reverseEncryption(false) {} NameIO::NameIO() : chainedNameIV(false), reverseEncryption(false) {}
NameIO::~NameIO() {} NameIO::~NameIO() = default;
void NameIO::setChainedNameIV(bool enable) { chainedNameIV = enable; } void NameIO::setChainedNameIV(bool enable) { chainedNameIV = enable; }

View File

@ -49,24 +49,24 @@ static bool NullCipher_registered = Cipher::Register(
class NullKey : public AbstractCipherKey { class NullKey : public AbstractCipherKey {
public: public:
NullKey() {} NullKey() = default;
virtual ~NullKey() {} virtual ~NullKey() = default;
}; };
class NullDestructor { class NullDestructor {
public: public:
NullDestructor() {} NullDestructor() = default;
NullDestructor(const NullDestructor &) {} NullDestructor(const NullDestructor &) = default;
~NullDestructor() {} ~NullDestructor() = default;
NullDestructor &operator=(const NullDestructor &) { return *this; } NullDestructor &operator=(const NullDestructor &) = default;
void operator()(NullKey *&) {} void operator()(NullKey *&) {}
}; };
std::shared_ptr<AbstractCipherKey> gNullKey(new NullKey(), NullDestructor()); std::shared_ptr<AbstractCipherKey> gNullKey(new NullKey(), NullDestructor());
NullCipher::NullCipher(const Interface &iface_) { this->iface = iface_; } NullCipher::NullCipher(const Interface &iface_) { this->iface = iface_; }
NullCipher::~NullCipher() {} NullCipher::~NullCipher() = default;
Interface NullCipher::interface() const { return iface; } Interface NullCipher::interface() const { return iface; }

View File

@ -41,9 +41,9 @@ static Interface NNIOIface("nameio/null", 1, 0, 0);
static bool NullNameIO_registered = static bool NullNameIO_registered =
NameIO::Register("Null", "No encryption of filenames", NNIOIface, NewNNIO); NameIO::Register("Null", "No encryption of filenames", NNIOIface, NewNNIO);
NullNameIO::NullNameIO() {} NullNameIO::NullNameIO() = default;
NullNameIO::~NullNameIO() {} NullNameIO::~NullNameIO() = default;
Interface NullNameIO::interface() const { return NNIOIface; } Interface NullNameIO::interface() const { return NNIOIface; }

View File

@ -28,6 +28,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <utility>
#include "Error.h" #include "Error.h"
#include "FileIO.h" #include "FileIO.h"
@ -53,8 +54,8 @@ inline void swap(int &x, int &y) {
RawFileIO::RawFileIO() RawFileIO::RawFileIO()
: knownSize(false), fileSize(0), fd(-1), oldfd(-1), canWrite(false) {} : knownSize(false), fileSize(0), fd(-1), oldfd(-1), canWrite(false) {}
RawFileIO::RawFileIO(const std::string &fileName) RawFileIO::RawFileIO(std::string fileName)
: name(fileName), : name(std::move(fileName)),
knownSize(false), knownSize(false),
fileSize(0), fileSize(0),
fd(-1), fd(-1),

View File

@ -32,7 +32,7 @@ namespace encfs {
class RawFileIO : public FileIO { class RawFileIO : public FileIO {
public: public:
RawFileIO(); RawFileIO();
RawFileIO(const std::string &fileName); RawFileIO(std::string fileName);
virtual ~RawFileIO(); virtual ~RawFileIO();
virtual Interface interface() const; virtual Interface interface() const;

View File

@ -342,7 +342,7 @@ SSL_Cipher::SSL_Cipher(const Interface &iface_, const Interface &realIface_,
} }
} }
SSL_Cipher::~SSL_Cipher() {} SSL_Cipher::~SSL_Cipher() = default;
Interface SSL_Cipher::interface() const { return realIface; } Interface SSL_Cipher::interface() const { return realIface; }

View File

@ -30,8 +30,7 @@
#define HMAC_CTX_reset HMAC_CTX_cleanup #define HMAC_CTX_reset HMAC_CTX_cleanup
// Missing methods (based on 1.1.0 versions) // Missing methods (based on 1.1.0 versions)
HMAC_CTX *HMAC_CTX_new(void) HMAC_CTX *HMAC_CTX_new(void) {
{
HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_malloc(sizeof(HMAC_CTX)); HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_malloc(sizeof(HMAC_CTX));
if (ctx != NULL) { if (ctx != NULL) {
memset(ctx, 0, sizeof(HMAC_CTX)); memset(ctx, 0, sizeof(HMAC_CTX));
@ -40,8 +39,7 @@ HMAC_CTX *HMAC_CTX_new(void)
return ctx; return ctx;
} }
void HMAC_CTX_free(HMAC_CTX *ctx) void HMAC_CTX_free(HMAC_CTX *ctx) {
{
if (ctx != NULL) { if (ctx != NULL) {
HMAC_CTX_cleanup(ctx); HMAC_CTX_cleanup(ctx);
OPENSSL_free(ctx); OPENSSL_free(ctx);

View File

@ -22,6 +22,7 @@
#include "internal/easylogging++.h" #include "internal/easylogging++.h"
#include <cstring> #include <cstring>
#include <utility>
#include "Cipher.h" #include "Cipher.h"
#include "CipherKey.h" #include "CipherKey.h"
@ -72,11 +73,12 @@ Interface StreamNameIO::CurrentInterface() {
} }
StreamNameIO::StreamNameIO(const Interface &iface, StreamNameIO::StreamNameIO(const Interface &iface,
const std::shared_ptr<Cipher> &cipher, std::shared_ptr<Cipher> cipher, CipherKey key)
const CipherKey &key) : _interface(iface.current()),
: _interface(iface.current()), _cipher(cipher), _key(key) {} _cipher(std::move(cipher)),
_key(std::move(key)) {}
StreamNameIO::~StreamNameIO() {} StreamNameIO::~StreamNameIO() = default;
Interface StreamNameIO::interface() const { return CurrentInterface(); } Interface StreamNameIO::interface() const { return CurrentInterface(); }

View File

@ -36,8 +36,8 @@ class StreamNameIO : public NameIO {
public: public:
static Interface CurrentInterface(); static Interface CurrentInterface();
StreamNameIO(const Interface &iface, const std::shared_ptr<Cipher> &cipher, StreamNameIO(const Interface &iface, std::shared_ptr<Cipher> cipher,
const CipherKey &key); CipherKey key);
virtual ~StreamNameIO(); virtual ~StreamNameIO();
virtual Interface interface() const; virtual Interface interface() const;

View File

@ -34,7 +34,7 @@
namespace encfs { namespace encfs {
XmlValue::~XmlValue() {} XmlValue::~XmlValue() = default;
XmlValuePtr XmlValue::operator[](const char *path) const { return find(path); } XmlValuePtr XmlValue::operator[](const char *path) const { return find(path); }
@ -139,7 +139,7 @@ class XmlNode : virtual public XmlValue {
XmlNode(const tinyxml2::XMLElement *element_) XmlNode(const tinyxml2::XMLElement *element_)
: XmlValue(safeValueForNode(element_)), element(element_) {} : XmlValue(safeValueForNode(element_)), element(element_) {}
virtual ~XmlNode() {} virtual ~XmlNode() = default;
virtual XmlValuePtr find(const char *name) const { virtual XmlValuePtr find(const char *name) const {
if (name[0] == '@') { if (name[0] == '@') {
@ -164,7 +164,7 @@ struct XmlReader::XmlReaderData {
XmlReader::XmlReader() : pd(new XmlReaderData()) {} XmlReader::XmlReader() : pd(new XmlReaderData()) {}
XmlReader::~XmlReader() {} XmlReader::~XmlReader() = default;
bool XmlReader::load(const char *fileName) { bool XmlReader::load(const char *fileName) {
pd->doc.reset(new tinyxml2::XMLDocument()); pd->doc.reset(new tinyxml2::XMLDocument());