From 8a0799c2b75ebb783a6b777121e1e9ddc89a5549 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 16 Aug 2016 16:44:09 +0200 Subject: [PATCH] crypt_prov fixed to prevent compiler-generated copy constructor creation --- include/WinStd/Common.h | 2 +- include/WinStd/Crypt.h | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index 007b9310..61e9e454 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -396,7 +396,7 @@ namespace winstd /// /// \param[inout] h A rvalue reference of another object /// - handle(_Inout_ handle &&h) + inline handle(_Inout_ handle &&h) { // Transfer handle. m_h = h.m_h; diff --git a/include/WinStd/Crypt.h b/include/WinStd/Crypt.h index 217f20b7..cff9eb8b 100644 --- a/include/WinStd/Crypt.h +++ b/include/WinStd/Crypt.h @@ -610,12 +610,43 @@ namespace winstd { public: /// - /// Releases the cryptographi context. + /// Initializes a new class instance with the object handle set to NULL. + /// + inline crypt_prov() : handle() {} + + /// + /// Initializes a new class instance with an already available object handle. + /// + /// \param[in] h Initial object handle value + /// + inline crypt_prov(_In_opt_ handle_type h) : handle(h) {} + + /// + /// Move constructor + /// + /// \param[inout] h A rvalue reference of another object + /// + inline crypt_prov(_Inout_ crypt_prov &&h) : handle(std::move(h)) {} + + /// + /// Releases the cryptographic context. /// /// \sa [CryptReleaseContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268.aspx) /// virtual ~crypt_prov(); + /// + /// Move assignment + /// + /// \param[inout] h A rvalue reference of another object + /// + crypt_prov& operator=(_Inout_ crypt_prov &&h) + { + if (this != std::addressof(h)) + *(handle*)this = std::move(h); + return *this; + } + /// /// Acquires the cryptographic context. /// @@ -635,6 +666,11 @@ namespace winstd return false; } + private: + // This class is noncopyable. + crypt_prov(_In_ const crypt_prov &h); + crypt_prov& operator=(_In_ const crypt_prov &h); + protected: /// /// Releases the cryptographic context.