Remove MySQLBytesRequest. Add MySQLAuthSwitchRequest.

This commit is contained in:
Xie Han
2023-02-06 19:32:50 +08:00
parent 1a144f3bc0
commit 89ffe576ad
2 changed files with 58 additions and 10 deletions
+34
View File
@@ -434,6 +434,40 @@ int MySQLAuthResponse::decode_packet(const unsigned char *buf, size_t buflen)
}
}
int MySQLAuthSwitchRequest::encode(struct iovec vectors[], int max)
{
if (auth_plugin_name_ == "mysql_clear_password")
{
buf_ = password_;
buf_.push_back('\0');
}
else if (auth_plugin_name_ == "mysql_native_password")
{
std::string seed = std::string((const char *)challenge_, 20);
std::string first = __sha1_str(password_);
std::string second = __sha1_str(seed + __sha1_str(first));
buf_.clear();
for (int i = 0; i < 20; i++)
buf_.push_back(first[i] ^ second[i]);
}
else if (auth_plugin_name_ == "sha256_password")
{
// TODO
}
else if (auth_plugin_name_ == "caching_sha2_password")
{
// TODO
}
else
{
errno = EINVAL;
return -1;
}
return this->MySQLMessage::encode(vectors, max);
}
void MySQLResponse::set_ok_packet()
{
uint16_t zero16 = 0;