diff options
author | Rutger Broekhoff | 2023-11-01 16:48:02 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2023-11-01 16:48:02 +0100 |
commit | e33788715ce08f9410290dcea9ca0ddb26692eed (patch) | |
tree | c64bce995bd38f89d855983caf929a98c5ffe825 /src/base32.zig | |
parent | 04252bac0d7a9383f943337366d6a6631ce44e91 (diff) | |
download | zig-nkeys-e33788715ce08f9410290dcea9ca0ddb26692eed.tar.gz zig-nkeys-e33788715ce08f9410290dcea9ca0ddb26692eed.zip |
Update for Zig 0.11.0
Diffstat (limited to 'src/base32.zig')
-rw-r--r-- | src/base32.zig | 14 |
1 files changed, 7 insertions, 7 deletions
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 { | |||
66 | fn frontBits(self: *const Self) ?u5 { | 66 | fn frontBits(self: *const Self) ?u5 { |
67 | const index = self.index orelse return null; | 67 | const index = self.index orelse return null; |
68 | const bits = self.buffer[index]; | 68 | const bits = self.buffer[index]; |
69 | if (self.bit_off >= 4) return @truncate(u5, bits << (self.bit_off - 3)); | 69 | if (self.bit_off >= 4) return @as(u5, @truncate(bits << (self.bit_off - 3))); |
70 | return @truncate(u5, bits >> (3 - self.bit_off)); | 70 | return @as(u5, @truncate(bits >> (3 - self.bit_off))); |
71 | } | 71 | } |
72 | 72 | ||
73 | /// Get the bits of `self.buffer[self.index]` with the maximum amount specified by the `bits` parameter, | 73 | /// 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 { | |||
85 | fn backBits(self: *const Self, bits: u3) u5 { | 85 | fn backBits(self: *const Self, bits: u3) u5 { |
86 | std.debug.assert(bits <= 5); | 86 | std.debug.assert(bits <= 5); |
87 | if (bits == 0 or self.index == null) return 0; | 87 | if (bits == 0 or self.index == null) return 0; |
88 | return @truncate(u5, self.buffer[self.index.?] >> (7 - bits + 1)); | 88 | return @as(u5, @truncate(self.buffer[self.index.?] >> (7 - bits + 1))); |
89 | } | 89 | } |
90 | 90 | ||
91 | /// Get the next 5-bit integer, read from `self.buffer`. | 91 | /// Get the next 5-bit integer, read from `self.buffer`. |
@@ -172,10 +172,10 @@ pub const Decoder = struct { | |||
172 | /// Get a character from the buffer. | 172 | /// Get a character from the buffer. |
173 | fn decodeChar(c: u8) DecodeError!u5 { | 173 | fn decodeChar(c: u8) DecodeError!u5 { |
174 | if (c >= 'A' and c <= 'Z') { | 174 | if (c >= 'A' and c <= 'Z') { |
175 | return @truncate(u5, c - @as(u8, 'A')); | 175 | return @as(u5, @truncate(c - @as(u8, 'A'))); |
176 | } else if (c >= '2' and c <= '9') { | 176 | } else if (c >= '2' and c <= '9') { |
177 | // '2' -> 26 | 177 | // '2' -> 26 |
178 | return @truncate(u5, c - @as(u8, '2') + 26); | 178 | return @as(u5, @truncate(c - @as(u8, '2') + 26)); |
179 | } else { | 179 | } else { |
180 | return error.CorruptInput; | 180 | return error.CorruptInput; |
181 | } | 181 | } |
@@ -200,7 +200,7 @@ pub const Decoder = struct { | |||
200 | // Calculate how many bits of the decoded remain when we've written part of it to the buffer. | 200 | // Calculate how many bits of the decoded remain when we've written part of it to the buffer. |
201 | const c_remaining_len = 5 - buf_write_len; | 201 | const c_remaining_len = 5 - buf_write_len; |
202 | // Write (the first) part of the decoded character to the buffer. | 202 | // Write (the first) part of the decoded character to the buffer. |
203 | self.buf |= (@as(u8, c) << 3) >> @truncate(u3, self.buf_len); | 203 | self.buf |= (@as(u8, c) << 3) >> @as(u3, @truncate(self.buf_len)); |
204 | self.buf_len += buf_write_len; | 204 | self.buf_len += buf_write_len; |
205 | if (self.buf_len == 8) { | 205 | if (self.buf_len == 8) { |
206 | // The buffer is full, we can return a byte. | 206 | // The buffer is full, we can return a byte. |
@@ -210,7 +210,7 @@ pub const Decoder = struct { | |||
210 | if (buf_write_len != 5) { | 210 | if (buf_write_len != 5) { |
211 | // We didn't write the entire decoded character to the buffer. | 211 | // We didn't write the entire decoded character to the buffer. |
212 | // Write the remaining part to the beginning of the buffer. | 212 | // Write the remaining part to the beginning of the buffer. |
213 | self.buf = @as(u8, c) << @truncate(u3, buf_write_len + 3); | 213 | self.buf = @as(u8, c) << @as(u3, @truncate(buf_write_len + 3)); |
214 | } | 214 | } |
215 | return ret; | 215 | return ret; |
216 | } | 216 | } |