From 536cb31525440af7fdd64b2c577cc2d531af8312 Mon Sep 17 00:00:00 2001 From: Fu Zi Xiang Date: Tue, 21 Nov 2023 22:54:23 +0800 Subject: [PATCH] feat: update zig --- .github/workflows/integrations.yml | 2 +- src/auth.zig | 15 +++++++-------- src/helper.zig | 4 ++-- src/protocol/packet.zig | 2 +- src/protocol/prepared_statements.zig | 6 +++--- src/protocol/text_command.zig | 4 ++-- src/stream_buffered.zig | 4 ++-- src/utils.zig | 2 +- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/.github/workflows/integrations.yml b/.github/workflows/integrations.yml index fb65467..3123522 100644 --- a/.github/workflows/integrations.yml +++ b/.github/workflows/integrations.yml @@ -20,7 +20,7 @@ jobs: - name: install zig run: | - ZIG_VERSION=0.12.0-dev.1647+325e0f5f0 + ZIG_VERSION=0.12.0-dev.1664+8ca4a5240 wget https://ziglang.org/builds/zig-linux-x86_64-$ZIG_VERSION.tar.xz tar xf zig-linux-x86_64-$ZIG_VERSION.tar.xz mv zig-linux-x86_64-$ZIG_VERSION $HOME/zig-build diff --git a/src/auth.zig b/src/auth.zig index 1535351..01721fd 100644 --- a/src/auth.zig +++ b/src/auth.zig @@ -57,7 +57,7 @@ pub fn decodePublicKey(encoded_bytes: []const u8, allocator: std.mem.Allocator) break :blk std.mem.trim(u8, encoded_bytes[base64_start..base64_end], " \t\r\n"); }; - var dest = try allocator.alloc(u8, try base64.calcSizeUpperBound(base64_encoded.len)); + const dest = try allocator.alloc(u8, try base64.calcSizeUpperBound(base64_encoded.len)); decoded_pk.allocated = dest; errdefer allocator.free(decoded_pk.allocated); @@ -176,7 +176,7 @@ test "scrambleSHA256Password" { // https://mariadb.com/kb/en/sha256_password-plugin/#rsa-encrypted-password // RSA encrypted value of XOR(password, seed) using server public key (RSA_PKCS1_OAEP_PADDING). pub fn encryptPassword(allocator: std.mem.Allocator, password: []const u8, auth_data: *const [20]u8, pk: *const PublicKey) ![]const u8 { - var plain = blk: { + const plain = blk: { var plain = try allocator.alloc(u8, password.len + 1); @memcpy(plain.ptr, password); plain[plain.len - 1] = 0; @@ -206,8 +206,8 @@ fn rsaEncryptOAEP(allocator: std.mem.Allocator, msg: []const u8, pk: *const Publ var em = try allocator.alloc(u8, k); defer allocator.free(em); @memset(em, 0); - var seed = em[1 .. 1 + digest_len]; - var db = em[1 + digest_len ..]; + const seed = em[1 .. 1 + digest_len]; + const db = em[1 + digest_len ..]; @memcpy(db[0..lHash.len], &lHash); db[db.len - msg.len - 1] = 1; @@ -230,7 +230,7 @@ fn encryptMsg(allocator: std.mem.Allocator, msg: []const u8, pk: *const PublicKe const m = try Fe.fromBytes(pk.*.n, msg, .big); const e = try pk.n.powPublic(m, pk.e); - var res = try allocator.alloc(u8, msg.len); + const res = try allocator.alloc(u8, msg.len); try e.toBytes(res, .big); return res; } @@ -259,8 +259,7 @@ fn mgf1XOR(dest: []u8, init_hash: *const Sha1, seed: []const u8) void { // incCounter increments a four byte, big-endian counter. fn incCounter(c: *[4]u8) void { inline for (&.{ 3, 2, 1, 0 }) |i| { - const res = @addWithOverflow(c[i], 1); - c[i] = res[0]; - if (res[1] == 0) return; // no overflow, so we're done + c[i], const overflow_bit = @addWithOverflow(c[i], 1); + if (overflow_bit == 0) return; // no overflow, so we're done } } diff --git a/src/helper.zig b/src/helper.zig index e0e543f..934c011 100644 --- a/src/helper.zig +++ b/src/helper.zig @@ -129,7 +129,7 @@ inline fn binResIsNull(null_bitmap: []const u8, col_idx: usize) bool { } test "binResIsNull" { - var tests = .{ + const tests = .{ .{ .null_bitmap = &.{0b00000100}, .col_idx = 0, @@ -178,7 +178,7 @@ pub fn ResultSetIter(comptime ResultRowType: type) type { pub fn collect(iter: *const ResultSetIter(TextResultRow), allocator: std.mem.Allocator) !TableTexts { var row_acc = std.ArrayList(TextResultRow).init(allocator); while (try iter.next(allocator)) |row| { - var new_row_ptr = try row_acc.addOne(); + const new_row_ptr = try row_acc.addOne(); new_row_ptr.* = row; } diff --git a/src/protocol/packet.zig b/src/protocol/packet.zig index 033b37f..67dcb2f 100644 --- a/src/protocol/packet.zig +++ b/src/protocol/packet.zig @@ -21,7 +21,7 @@ pub const Packet = struct { packet.payload_length = try readUInt24(sbr); packet.sequence_id = try readUInt8(sbr); packet.payload = blk: { - var payload = try allocator.alloc(u8, @as(usize, packet.payload_length)); + const payload = try allocator.alloc(u8, @as(usize, packet.payload_length)); try sbr.read(payload); break :blk payload; }; diff --git a/src/protocol/prepared_statements.zig b/src/protocol/prepared_statements.zig index 75dd307..bb68b98 100644 --- a/src/protocol/prepared_statements.zig +++ b/src/protocol/prepared_statements.zig @@ -201,9 +201,9 @@ fn nullBinaryParam() BinaryParam { } test "writeNullBitmap" { - var nn = nonNullBinaryParam(); - var n = nullBinaryParam(); - var tests = .{ + const nn = nonNullBinaryParam(); + const n = nullBinaryParam(); + const tests = .{ .{ .params = &.{nn}, .attributes = &.{nn}, diff --git a/src/protocol/text_command.zig b/src/protocol/text_command.zig index da82d64..4c33868 100644 --- a/src/protocol/text_command.zig +++ b/src/protocol/text_command.zig @@ -75,7 +75,7 @@ pub fn nullBits(params: []const ?QueryParam) u8 { } test "writeNullBitmap - 1" { - var params: []const ?QueryParam = &.{ + const params: []const ?QueryParam = &.{ null, .{ .type_and_flag = .{ 0, 0 }, @@ -98,7 +98,7 @@ test "writeNullBitmap - 1" { } test "writeNullBitmap - 2" { - var params: []const ?QueryParam = &.{ + const params: []const ?QueryParam = &.{ null, null, null, null, null, null, null, null, null, null, null, null, diff --git a/src/stream_buffered.zig b/src/stream_buffered.zig index dae60d1..ab5bce3 100644 --- a/src/stream_buffered.zig +++ b/src/stream_buffered.zig @@ -123,8 +123,8 @@ pub fn writer(stream: std.net.Stream) Writer { fn copy(dest: []u8, src: []const u8) usize { const amount_copied = @min(dest.len, src.len); - var final_dest = dest[0..amount_copied]; - var final_src = src[0..amount_copied]; + const final_dest = dest[0..amount_copied]; + const final_src = src[0..amount_copied]; @memcpy(final_dest, final_src); return amount_copied; } diff --git a/src/utils.zig b/src/utils.zig index 102dc04..60279c1 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -12,7 +12,7 @@ pub fn FixedBytes(comptime max: usize) type { pub fn set(self: *FixedBytes(max), src: []const u8) void { std.debug.assert(src.len <= max); - var dest = self.buf[0..src.len]; + const dest = self.buf[0..src.len]; @memcpy(dest, src); self.len = src.len; }