diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/base32.zig | 20 | ||||
| -rw-r--r-- | src/nkeys.zig | 3 |
2 files changed, 6 insertions, 17 deletions
diff --git a/src/base32.zig b/src/base32.zig index d612e7a..749c313 100644 --- a/src/base32.zig +++ b/src/base32.zig | |||
| @@ -64,18 +64,8 @@ pub const Encoder = struct { | |||
| 64 | /// | 6 | 0b11000 | | 64 | /// | 6 | 0b11000 | |
| 65 | /// | 7 | 0b10000 | | 65 | /// | 7 | 0b10000 | |
| 66 | fn frontBits(self: *const Self) ?u5 { | 66 | fn frontBits(self: *const Self) ?u5 { |
| 67 | // bit_off bitmask shl shr frontBits | ||
| 68 | // 0 0b11111000 3 0b11111 | ||
| 69 | // 1 0b01111100 2 0b11111 | ||
| 70 | // 2 0b00111110 1 0b11111 | ||
| 71 | // 3 0b00011111 0 0 0b11111 | ||
| 72 | // 4 0b00001111 1 0b11110 | ||
| 73 | // 5 0b00000111 2 0b11100 | ||
| 74 | // 6 0b00000011 3 0b11000 | ||
| 75 | // 7 0b00000001 4 0b10000 | ||
| 76 | const index = self.index orelse return null; | 67 | const index = self.index orelse return null; |
| 77 | const bitmask = @as(u8, 0b11111000) >> self.bit_off; | 68 | const bits = self.buffer[index]; |
| 78 | const bits = self.buffer[index] & bitmask; | ||
| 79 | if (self.bit_off >= 4) return @truncate(u5, bits << (self.bit_off - 3)); | 69 | if (self.bit_off >= 4) return @truncate(u5, bits << (self.bit_off - 3)); |
| 80 | return @truncate(u5, bits >> (3 - self.bit_off)); | 70 | return @truncate(u5, bits >> (3 - self.bit_off)); |
| 81 | } | 71 | } |
| @@ -87,10 +77,10 @@ pub const Encoder = struct { | |||
| 87 | /// | `bits` | `backBits` | | 77 | /// | `bits` | `backBits` | |
| 88 | /// |--------|------------| | 78 | /// |--------|------------| |
| 89 | /// | 0 | 0b00000 | | 79 | /// | 0 | 0b00000 | |
| 90 | /// | 1 | 0b10000 | | 80 | /// | 1 | 0b00001 | |
| 91 | /// | 2 | 0b11000 | | 81 | /// | 2 | 0b00011 | |
| 92 | /// | 3 | 0b11100 | | 82 | /// | 3 | 0b00111 | |
| 93 | /// | 4 | 0b11100 | | 83 | /// | 4 | 0b01110 | |
| 94 | /// | 5 | 0b11101 | | 84 | /// | 5 | 0b11101 | |
| 95 | fn backBits(self: *const Self, bits: u3) u5 { | 85 | fn backBits(self: *const Self, bits: u3) u5 { |
| 96 | std.debug.assert(bits <= 5); | 86 | std.debug.assert(bits <= 5); |
diff --git a/src/nkeys.zig b/src/nkeys.zig index 3a6c2db..e3d9ef9 100644 --- a/src/nkeys.zig +++ b/src/nkeys.zig | |||
| @@ -274,7 +274,7 @@ pub fn decodeSeed(text: *const text_seed) SeedDecodeError!DecodedSeed { | |||
| 274 | defer decoded.wipe(); // gets copied | 274 | defer decoded.wipe(); // gets copied |
| 275 | 275 | ||
| 276 | var key_ty_prefix = decoded.prefix[0] & 0b11111000; | 276 | var key_ty_prefix = decoded.prefix[0] & 0b11111000; |
| 277 | var entity_ty_prefix = (decoded.prefix[0] & 0b00000111) << 5 | ((decoded.prefix[1] & 0b11111000) >> 3); | 277 | var entity_ty_prefix = (decoded.prefix[0] << 5) | (decoded.prefix[1] >> 3); |
| 278 | 278 | ||
| 279 | if (key_ty_prefix != @enumToInt(KeyTypePrefixByte.seed)) | 279 | if (key_ty_prefix != @enumToInt(KeyTypePrefixByte.seed)) |
| 280 | return error.InvalidSeed; | 280 | return error.InvalidSeed; |
| @@ -328,7 +328,6 @@ const allowed_creds_section_chars_table: [256]bool = allowed: { | |||
| 328 | var table = [_]bool{false} ** 256; | 328 | var table = [_]bool{false} ** 256; |
| 329 | const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.="; | 329 | const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.="; |
| 330 | for (chars) |char| table[char] = true; | 330 | for (chars) |char| table[char] = true; |
| 331 | |||
| 332 | break :allowed table; | 331 | break :allowed table; |
| 333 | }; | 332 | }; |
| 334 | 333 | ||