crypt_prov fixed to prevent compiler-generated copy constructor creation

This commit is contained in:
Simon Rozman 2016-08-16 16:44:09 +02:00
parent dfbe66a826
commit 8a0799c2b7
2 changed files with 38 additions and 2 deletions

View File

@ -396,7 +396,7 @@ namespace winstd
/// ///
/// \param[inout] h A rvalue reference of another object /// \param[inout] h A rvalue reference of another object
/// ///
handle<handle_type>(_Inout_ handle<handle_type> &&h) inline handle<handle_type>(_Inout_ handle<handle_type> &&h)
{ {
// Transfer handle. // Transfer handle.
m_h = h.m_h; m_h = h.m_h;

View File

@ -610,12 +610,43 @@ namespace winstd
{ {
public: public:
/// ///
/// Releases the cryptographi context. /// Initializes a new class instance with the object handle set to NULL.
///
inline crypt_prov() : handle<HCRYPTPROV>() {}
///
/// 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<HCRYPTPROV>(h) {}
///
/// Move constructor
///
/// \param[inout] h A rvalue reference of another object
///
inline crypt_prov(_Inout_ crypt_prov &&h) : handle<HCRYPTPROV>(std::move(h)) {}
///
/// Releases the cryptographic context.
/// ///
/// \sa [CryptReleaseContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268.aspx) /// \sa [CryptReleaseContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268.aspx)
/// ///
virtual ~crypt_prov(); 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<handle_type>*)this = std::move(h);
return *this;
}
/// ///
/// Acquires the cryptographic context. /// Acquires the cryptographic context.
/// ///
@ -635,6 +666,11 @@ namespace winstd
return false; return false;
} }
private:
// This class is noncopyable.
crypt_prov(_In_ const crypt_prov &h);
crypt_prov& operator=(_In_ const crypt_prov &h);
protected: protected:
/// ///
/// Releases the cryptographic context. /// Releases the cryptographic context.