Files
bun.sh/src/sql/mysql/AuthMethod.zig
Ciro Spaciari 1085908386 fix(Bun.SQL) MYSQL fix old auth and auth switch + add lastInsertRowid and affectedRows (#22132)
### What does this PR do?

add `lastInsertRowid` (matching SQLite)
add `affectedRows`
fix `mysql_native_password` deprecated authentication
fix AuthSwitch
Fixes:
https://github.com/oven-sh/bun/issues/22178#issuecomment-3228716080
### How did you verify your code works?
tests

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-29 01:03:17 -07:00

38 lines
1.1 KiB
Zig

// MySQL authentication methods
pub const AuthMethod = enum {
mysql_native_password,
caching_sha2_password,
sha256_password,
pub fn scramble(this: AuthMethod, password: []const u8, auth_data: []const u8, buf: *[32]u8) ![]u8 {
if (password.len == 0) {
return &.{};
}
const len = scrambleLength(this);
switch (this) {
.mysql_native_password => @memcpy(buf[0..len], &try Auth.mysql_native_password.scramble(password, auth_data)),
.caching_sha2_password => @memcpy(buf[0..len], &try Auth.caching_sha2_password.scramble(password, auth_data)),
.sha256_password => @memcpy(buf[0..len], &try Auth.caching_sha2_password.scramble(password, auth_data)),
}
return buf[0..len];
}
pub fn scrambleLength(this: AuthMethod) usize {
return switch (this) {
.mysql_native_password => 20,
.caching_sha2_password => 32,
.sha256_password => 32,
};
}
const Map = bun.ComptimeEnumMap(AuthMethod);
pub const fromString = Map.get;
};
const Auth = @import("./protocol/Auth.zig");
const bun = @import("bun");