diff options
author | Rutger Broekhoff | 2021-05-22 21:19:53 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2021-05-22 21:19:53 +0200 |
commit | 07ac8dc00e7676d7845a881970c259679b0c5d23 (patch) | |
tree | b2ea799f35eab953d083472ea435ca101e7f321f /src/base32.zig | |
parent | 4716921ce42b5153b5c60edf3638e1592f72f743 (diff) | |
download | zig-nkeys-07ac8dc00e7676d7845a881970c259679b0c5d23.tar.gz zig-nkeys-07ac8dc00e7676d7845a881970c259679b0c5d23.zip |
Clean up
`NKey` has been replaced with `Nkey` in all Zig source files,
even though this capitalization is technically incorrect.
The standard library also uses 'strict' camel/PascalCase everywhere,
meaning that abbreviations like CRC, AES and GUID are spelled like
Crc, Aes and Guid respectively.
`var` has been replaced with `const` where applicable.
Also, the `Key` type has been moved from src/nkeys.zig
to src/znk.zig for now - it's still a little bit lacking and might
not need to be included in the library.
Diffstat (limited to 'src/base32.zig')
-rw-r--r-- | src/base32.zig | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/base32.zig b/src/base32.zig index d8adfd5..d612e7a 100644 --- a/src/base32.zig +++ b/src/base32.zig | |||
@@ -182,16 +182,14 @@ pub const Decoder = struct { | |||
182 | 182 | ||
183 | /// Get a character from the buffer. | 183 | /// Get a character from the buffer. |
184 | fn decodeChar(c: u8) DecodeError!u5 { | 184 | fn decodeChar(c: u8) DecodeError!u5 { |
185 | var value: u5 = 0; | ||
186 | if (c >= 'A' and c <= 'Z') { | 185 | if (c >= 'A' and c <= 'Z') { |
187 | value = @truncate(u5, c - @as(u8, 'A')); | 186 | return @truncate(u5, c - @as(u8, 'A')); |
188 | } else if (c >= '2' and c <= '9') { | 187 | } else if (c >= '2' and c <= '9') { |
189 | // '2' -> 26 | 188 | // '2' -> 26 |
190 | value = @truncate(u5, c - @as(u8, '2') + 26); | 189 | return @truncate(u5, c - @as(u8, '2') + 26); |
191 | } else { | 190 | } else { |
192 | return error.CorruptInputError; | 191 | return error.CorruptInputError; |
193 | } | 192 | } |
194 | return value; | ||
195 | } | 193 | } |
196 | 194 | ||
197 | /// Get the next 5-bit decoded character, read from `self.buffer`. | 195 | /// Get the next 5-bit decoded character, read from `self.buffer`. |
@@ -248,12 +246,12 @@ test { | |||
248 | const decoded = "this is a test"; | 246 | const decoded = "this is a test"; |
249 | 247 | ||
250 | var decode_buf: [Decoder.calcSize(encoded.len)]u8 = undefined; | 248 | var decode_buf: [Decoder.calcSize(encoded.len)]u8 = undefined; |
251 | var decode_res = try Decoder.decode(&decode_buf, encoded); | 249 | const decode_res = try Decoder.decode(&decode_buf, encoded); |
252 | 250 | ||
253 | try testing.expectEqualStrings(decoded, decode_res); | 251 | try testing.expectEqualStrings(decoded, decode_res); |
254 | 252 | ||
255 | var encode_buf: [Encoder.calcSize(decoded.len)]u8 = undefined; | 253 | var encode_buf: [Encoder.calcSize(decoded.len)]u8 = undefined; |
256 | var encode_res = Encoder.encode(&encode_buf, decoded); | 254 | const encode_res = Encoder.encode(&encode_buf, decoded); |
257 | 255 | ||
258 | try testing.expectEqualStrings(encoded, encode_res); | 256 | try testing.expectEqualStrings(encoded, encode_res); |
259 | } | 257 | } |
@@ -263,12 +261,12 @@ test { | |||
263 | const decoded = &[_]u8{ 0x93, 0x40, 0x7f, 0x90, 0xfd, 0xbf, 0x1f, 0xd8, 0xe9, 0x9a, 0x89, 0x8b, 0xb5, 0xd4, 0x0b, 0xf3, 0x62, 0x54, 0x5d, 0x6d, 0xd1, 0x3d, 0xf7, 0x78, 0xad, 0x8d, 0x21, 0xc4, 0x8a, 0x01, 0x7a, 0xfd, 0xc3, 0x10, 0x2f, 0x5e }; | 261 | const decoded = &[_]u8{ 0x93, 0x40, 0x7f, 0x90, 0xfd, 0xbf, 0x1f, 0xd8, 0xe9, 0x9a, 0x89, 0x8b, 0xb5, 0xd4, 0x0b, 0xf3, 0x62, 0x54, 0x5d, 0x6d, 0xd1, 0x3d, 0xf7, 0x78, 0xad, 0x8d, 0x21, 0xc4, 0x8a, 0x01, 0x7a, 0xfd, 0xc3, 0x10, 0x2f, 0x5e }; |
264 | 262 | ||
265 | var decode_buf: [Decoder.calcSize(encoded.len)]u8 = undefined; | 263 | var decode_buf: [Decoder.calcSize(encoded.len)]u8 = undefined; |
266 | var decode_res = try Decoder.decode(&decode_buf, encoded); | 264 | const decode_res = try Decoder.decode(&decode_buf, encoded); |
267 | 265 | ||
268 | try testing.expectEqualSlices(u8, decoded, decode_res); | 266 | try testing.expectEqualSlices(u8, decoded, decode_res); |
269 | 267 | ||
270 | var encode_buf: [Encoder.calcSize(decoded.len)]u8 = undefined; | 268 | var encode_buf: [Encoder.calcSize(decoded.len)]u8 = undefined; |
271 | var encode_res = Encoder.encode(&encode_buf, decoded); | 269 | const encode_res = Encoder.encode(&encode_buf, decoded); |
272 | 270 | ||
273 | try testing.expectEqualSlices(u8, encoded, encode_res); | 271 | try testing.expectEqualSlices(u8, encoded, encode_res); |
274 | } | 272 | } |