Skip to content

packets: replace repeated if/else if by switch #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,23 +486,24 @@ func (mc *mysqlConn) readResultOK() ([]byte, error) {
plugin := string(data[1:pluginEndIndex])
cipher := data[pluginEndIndex+1 : len(data)-1]

if plugin == "mysql_old_password" {
switch plugin {
case "mysql_old_password":
// using old_passwords
return cipher, ErrOldPassword
} else if plugin == "mysql_clear_password" {
case "mysql_clear_password":
// using clear text password
return cipher, ErrCleartextPassword
} else if plugin == "mysql_native_password" {
case "mysql_native_password":
// using mysql default authentication method
return cipher, ErrNativePassword
} else {
default:
return cipher, ErrUnknownPlugin
}
} else {
// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::OldAuthSwitchRequest
return nil, ErrOldPassword
}

// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::OldAuthSwitchRequest
return nil, ErrOldPassword

default: // Error otherwise
return nil, mc.handleErrorPacket(data)
}
Expand Down