Skip to content

Commit

Permalink
feat: update zig
Browse files Browse the repository at this point in the history
  • Loading branch information
speed2exe committed Nov 21, 2023
1 parent 93dbce1 commit 536cb31
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions src/auth.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions src/helper.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/packet.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
6 changes: 3 additions & 3 deletions src/protocol/prepared_statements.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/text_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/stream_buffered.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 536cb31

Please sign in to comment.