diff --git a/cdoc/CDoc.cpp b/cdoc/CDoc.cpp index 546df08..f86e694 100644 --- a/cdoc/CDoc.cpp +++ b/cdoc/CDoc.cpp @@ -200,7 +200,7 @@ libcdoc::CDocWriter::CDocWriter(int _version, DataConsumer *_dst, bool take_owne { }; -libcdoc::CDocWriter::~CDocWriter() +libcdoc::CDocWriter::~CDocWriter() noexcept { if (owned) delete(dst); } diff --git a/cdoc/CDoc.h b/cdoc/CDoc.h index 741b1e6..960f472 100644 --- a/cdoc/CDoc.h +++ b/cdoc/CDoc.h @@ -21,15 +21,15 @@ #include "Exports.h" +#include #include -#include namespace libcdoc { /** * @brief A typedef that indicates that integer value may contain libcdoc result code */ -typedef int64_t result_t; +using result_t = int64_t; enum { /** @@ -134,7 +134,7 @@ CDOC_EXPORT std::string getVersion(); /** * @brief Log-level enumeration to indicate severity of the log message. */ -enum LogLevel +enum LogLevel : uint8_t { /** * @brief Most critical level. Application is about to abort. diff --git a/cdoc/CDoc2Reader.cpp b/cdoc/CDoc2Reader.cpp index 23ab578..478e51a 100644 --- a/cdoc/CDoc2Reader.cpp +++ b/cdoc/CDoc2Reader.cpp @@ -20,6 +20,7 @@ #include "Certificate.h" #include "Configuration.h" +#include "Crypto.h" #include "CryptoBackend.h" #include "CDoc2.h" #include "KeyShares.h" @@ -400,7 +401,7 @@ CDoc2Reader::beginDecryption(const std::vector& fmk) return libcdoc::WRONG_ARGUMENTS; } if (!priv->_at_nonce) { - int result = priv->_src->seek(priv->_nonce_pos); + result_t result = priv->_src->seek(priv->_nonce_pos); if (result != libcdoc::OK) { setLastError(priv->_src->getLastErrorStr(result)); LOG_ERROR("{}", last_error); @@ -697,14 +698,3 @@ CDoc2Reader::isCDoc2File(libcdoc::DataSource *src) } return true; } - -bool -CDoc2Reader::isCDoc2File(const std::string& path) -{ - std::ifstream fb(path, std::ios_base::in | std::ios_base::binary); - char in[libcdoc::CDoc2::LABEL.size()]; - constexpr size_t len = libcdoc::CDoc2::LABEL.size(); - if (!fb.read(&in[0], len) || (fb.gcount() != len)) return false; - if (libcdoc::CDoc2::LABEL.compare(0, len, &in[0], len)) return false; - return true; -} diff --git a/cdoc/CDoc2Reader.h b/cdoc/CDoc2Reader.h index b0e012f..03ea3a9 100644 --- a/cdoc/CDoc2Reader.h +++ b/cdoc/CDoc2Reader.h @@ -27,24 +27,24 @@ class CDoc2Reader final: public libcdoc::CDocReader { public: ~CDoc2Reader() final; - const std::vector& getLocks() override final; - libcdoc::result_t getLockForCert(const std::vector& cert) override final; - libcdoc::result_t getFMK(std::vector& fmk, unsigned int lock_idx) override final; - libcdoc::result_t decrypt(const std::vector& fmk, libcdoc::MultiDataConsumer *consumer) override final; + const std::vector& getLocks() final; + libcdoc::result_t getLockForCert(const std::vector& cert) final; + libcdoc::result_t getFMK(std::vector& fmk, unsigned int lock_idx) final; + libcdoc::result_t decrypt(const std::vector& fmk, libcdoc::MultiDataConsumer *consumer) final; // Pull interface - libcdoc::result_t beginDecryption(const std::vector& fmk) override final; - libcdoc::result_t nextFile(std::string& name, int64_t& size) override final; - libcdoc::result_t readData(uint8_t *dst, size_t size) override final; - libcdoc::result_t finishDecryption() override final; + libcdoc::result_t beginDecryption(const std::vector& fmk) final; + libcdoc::result_t nextFile(std::string& name, int64_t& size) final; + libcdoc::result_t readData(uint8_t *dst, size_t size) final; + libcdoc::result_t finishDecryption() final; CDoc2Reader(libcdoc::DataSource *src, bool take_ownership = false); - static bool isCDoc2File(const std::string& path); static bool isCDoc2File(libcdoc::DataSource *src); private: - struct Private; + CDOC_DISABLE_MOVE_COPY(CDoc2Reader); + struct Private; std::unique_ptr priv; }; diff --git a/cdoc/CDocReader.h b/cdoc/CDocReader.h index c1fdf16..1aa578a 100644 --- a/cdoc/CDocReader.h +++ b/cdoc/CDocReader.h @@ -21,7 +21,7 @@ #include "CDoc.h" -#include +#include namespace libcdoc { @@ -39,7 +39,7 @@ struct NetworkBackend; */ class CDOC_EXPORT CDocReader { public: - virtual ~CDocReader() = default; + virtual ~CDocReader() noexcept = default; /** * @brief The container version (1 or 2) @@ -210,6 +210,9 @@ class CDOC_EXPORT CDocReader { Configuration *conf = nullptr; CryptoBackend *crypto = nullptr; NetworkBackend *network = nullptr; + +private: + CDOC_DISABLE_MOVE_COPY(CDocReader); }; } // namespace libcdoc diff --git a/cdoc/CDocWriter.h b/cdoc/CDocWriter.h index a259548..2622b53 100644 --- a/cdoc/CDocWriter.h +++ b/cdoc/CDocWriter.h @@ -21,7 +21,7 @@ #include "CDoc.h" -#include +#include namespace libcdoc { struct Configuration; @@ -38,7 +38,7 @@ namespace libcdoc { */ class CDOC_EXPORT CDocWriter { public: - virtual ~CDocWriter(); + virtual ~CDocWriter() noexcept; /** * @brief The container version (1 or 2) @@ -154,6 +154,7 @@ class CDOC_EXPORT CDocWriter { static CDocWriter *createWriter(int version, const std::string& path, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network); protected: explicit CDocWriter(int _version, DataConsumer *dst, bool take_ownership); + CDOC_DISABLE_MOVE_COPY(CDocWriter); void setLastError(const std::string& message) { last_error = message; } diff --git a/cdoc/CryptoBackend.h b/cdoc/CryptoBackend.h index 56e6447..bf63d5b 100644 --- a/cdoc/CryptoBackend.h +++ b/cdoc/CryptoBackend.h @@ -21,7 +21,7 @@ #include -#include +#include namespace libcdoc { diff --git a/cdoc/Io.h b/cdoc/Io.h index c6ca0a4..bd4dcbd 100644 --- a/cdoc/Io.h +++ b/cdoc/Io.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace libcdoc { diff --git a/cdoc/KeyShares.h b/cdoc/KeyShares.h index 1c6ad0d..219fc0a 100644 --- a/cdoc/KeyShares.h +++ b/cdoc/KeyShares.h @@ -19,13 +19,7 @@ #ifndef __KEYSHARES_H__ #define __KEYSHARES_H__ -#include #include -#include - -#include -#include -#include namespace libcdoc { diff --git a/cdoc/ZStream.h b/cdoc/ZStream.h index 1bc60f5..28b8ddb 100644 --- a/cdoc/ZStream.h +++ b/cdoc/ZStream.h @@ -19,7 +19,6 @@ #ifndef __ZSTREAM_H__ #define __ZSTREAM_H__ -#include "Crypto.h" #include "Io.h" #include @@ -75,7 +74,7 @@ struct ZConsumer : public DataConsumer { flush = Z_FINISH; write (nullptr, 0); deflateEnd(&_s); - if (_owned) return _dst->close(); + return _owned ? _dst->close() : OK; } }; diff --git a/vcpkg.json b/vcpkg.json index eb6a1b9..7d1d57b 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -21,7 +21,7 @@ "features": { "tests": { "description": "Build tests", "dependencies": ["boost-test"] } }, - "builtin-baseline": "425d0412a2c1d5f9a0071d77ccee88c96e0f70d0", + "builtin-baseline": "bc38a15b0bee8bc48a49ea267cc32fbb49aedfc4", "vcpkg-configuration": { "overlay-triplets": ["./vcpkg-triplets"], "registries": [