Skip to content

Commit

Permalink
Remove move semantics from Authentication
Browse files Browse the repository at this point in the history
move semantics with a std::string introduce difficulty with secure
erasing because we have no guarantee that the moved-from object doesn't
still have the the credentials (because of small string optimization).

This removes the move ctor and assignment so that we always get secure
erasing on destruction without any weird SSO cases to worry about.
  • Loading branch information
jagerman committed Jul 18, 2024
1 parent 317763b commit cb7f4bf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 15 deletions.
13 changes: 0 additions & 13 deletions cpr/auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "cpr/util.h"

#include <string_view>
#include <utility>

namespace cpr {

Expand All @@ -13,18 +12,6 @@ Authentication::Authentication(std::string_view username, std::string_view passw
auth_string_ += password;
}

Authentication::Authentication(Authentication&& old) noexcept : auth_string_{std::move(old.auth_string_)}, auth_mode_{old.auth_mode_} {
old.auth_string_.resize(old.auth_string_.capacity());
}

Authentication& Authentication::operator=(Authentication&& old) noexcept {
auth_mode_ = old.auth_mode_;
util::secureStringClear(auth_string_);
auth_string_ = std::move(old.auth_string_);
old.auth_string_.resize(old.auth_string_.capacity());
return *this;
}

Authentication::~Authentication() noexcept {
util::secureStringClear(auth_string_);
}
Expand Down
2 changes: 0 additions & 2 deletions include/cpr/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ class Authentication {
public:
Authentication(std::string_view username, std::string_view password, AuthMode auth_mode);
Authentication(const Authentication& other) = default;
Authentication(Authentication&& old) noexcept;
~Authentication() noexcept;

Authentication& operator=(Authentication&& old) noexcept;
Authentication& operator=(const Authentication& other) = default;

const char* GetAuthString() const noexcept;
Expand Down

0 comments on commit cb7f4bf

Please sign in to comment.