From e33788715ce08f9410290dcea9ca0ddb26692eed Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Wed, 1 Nov 2023 16:48:02 +0100 Subject: Update for Zig 0.11.0 --- src/base32.zig | 14 +++++++------- src/crc16.zig | 4 ++-- src/main.zig | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/base32.zig b/src/base32.zig index 4e79a73..bce6254 100644 --- a/src/base32.zig +++ b/src/base32.zig @@ -66,8 +66,8 @@ pub const Encoder = struct { fn frontBits(self: *const Self) ?u5 { const index = self.index orelse return null; const bits = self.buffer[index]; - if (self.bit_off >= 4) return @truncate(u5, bits << (self.bit_off - 3)); - return @truncate(u5, bits >> (3 - self.bit_off)); + if (self.bit_off >= 4) return @as(u5, @truncate(bits << (self.bit_off - 3))); + return @as(u5, @truncate(bits >> (3 - self.bit_off))); } /// Get the bits of `self.buffer[self.index]` with the maximum amount specified by the `bits` parameter, @@ -85,7 +85,7 @@ pub const Encoder = struct { fn backBits(self: *const Self, bits: u3) u5 { std.debug.assert(bits <= 5); if (bits == 0 or self.index == null) return 0; - return @truncate(u5, self.buffer[self.index.?] >> (7 - bits + 1)); + return @as(u5, @truncate(self.buffer[self.index.?] >> (7 - bits + 1))); } /// Get the next 5-bit integer, read from `self.buffer`. @@ -172,10 +172,10 @@ pub const Decoder = struct { /// Get a character from the buffer. fn decodeChar(c: u8) DecodeError!u5 { if (c >= 'A' and c <= 'Z') { - return @truncate(u5, c - @as(u8, 'A')); + return @as(u5, @truncate(c - @as(u8, 'A'))); } else if (c >= '2' and c <= '9') { // '2' -> 26 - return @truncate(u5, c - @as(u8, '2') + 26); + return @as(u5, @truncate(c - @as(u8, '2') + 26)); } else { return error.CorruptInput; } @@ -200,7 +200,7 @@ pub const Decoder = struct { // Calculate how many bits of the decoded remain when we've written part of it to the buffer. const c_remaining_len = 5 - buf_write_len; // Write (the first) part of the decoded character to the buffer. - self.buf |= (@as(u8, c) << 3) >> @truncate(u3, self.buf_len); + self.buf |= (@as(u8, c) << 3) >> @as(u3, @truncate(self.buf_len)); self.buf_len += buf_write_len; if (self.buf_len == 8) { // The buffer is full, we can return a byte. @@ -210,7 +210,7 @@ pub const Decoder = struct { if (buf_write_len != 5) { // We didn't write the entire decoded character to the buffer. // Write the remaining part to the beginning of the buffer. - self.buf = @as(u8, c) << @truncate(u3, buf_write_len + 3); + self.buf = @as(u8, c) << @as(u3, @truncate(buf_write_len + 3)); } return ret; } diff --git a/src/crc16.zig b/src/crc16.zig index 3ea5a15..1257ea2 100644 --- a/src/crc16.zig +++ b/src/crc16.zig @@ -7,7 +7,7 @@ const crc16tab: [256]u16 = tab: { const poly: u32 = 0x1021; var table: [256]u16 = undefined; - for (table) |*crc, i| { + for (&table, 0..) |*crc, i| { crc.* = @as(u16, i) << 8; var j = 0; while (j < 8) : (j += 1) { @@ -25,7 +25,7 @@ const crc16tab: [256]u16 = tab: { pub fn update(crc: u16, with_data: []const u8) u16 { var new_crc = crc; for (with_data) |b| { - new_crc = (new_crc << 8) ^ crc16tab[@truncate(u8, new_crc >> 8) ^ b]; + new_crc = (new_crc << 8) ^ crc16tab[@as(u8, @truncate(new_crc >> 8)) ^ b]; } return new_crc; } diff --git a/src/main.zig b/src/main.zig index 6f68295..18c86d1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -393,7 +393,7 @@ pub fn areKeySectionContentsValid(contents: []const u8) bool { return true; } -pub fn findKeySection(line_it: *std.mem.SplitIterator(u8)) ?[]const u8 { +pub fn findKeySection(line_it: *std.mem.SplitIterator(u8, .scalar)) ?[]const u8 { while (true) { const opening_line = line_it.next() orelse return null; if (!isKeySectionBarrier(opening_line, true)) continue; @@ -409,12 +409,12 @@ pub fn findKeySection(line_it: *std.mem.SplitIterator(u8)) ?[]const u8 { } pub fn parseDecoratedJwt(contents: []const u8) []const u8 { - var line_it = mem.split(u8, contents, "\n"); + var line_it = mem.splitScalar(u8, contents, '\n'); return findKeySection(&line_it) orelse return contents; } pub fn parseDecoratedNkey(contents: []const u8) NoNkeySeedFoundError!SeedKeyPair { - var line_it = mem.split(u8, contents, "\n"); + var line_it = mem.splitScalar(u8, contents, '\n'); var seed: ?[]const u8 = null; if (findKeySection(&line_it) != null) seed = findKeySection(&line_it); @@ -444,8 +444,8 @@ fn isValidCredsNkey(text: []const u8) bool { fn findNkey(text: []const u8) ?[]const u8 { var line_it = std.mem.split(u8, text, "\n"); while (line_it.next()) |line| { - for (line) |c, i| { - if (!ascii.isSpace(c)) { + for (line, 0..) |c, i| { + if (!ascii.isWhitespace(c)) { if (isValidCredsNkey(line[i..])) return line[i..]; break; } @@ -554,7 +554,7 @@ test "different key types" { test "validation" { const roles = @typeInfo(Role).Enum.fields; - inline for (roles) |field, i| { + inline for (roles, 0..) |field, i| { const role = @field(Role, field.name); const next_role = next: { const next_field_i = if (i == roles.len - 1) 0 else i + 1; -- cgit v1.2.3