From 3cd23ecc90a1385accfd82e8b4bab3c7126b8cf5 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Mon, 24 May 2021 14:53:29 +0200 Subject: Remove some unnecessary code --- src/base32.zig | 20 +++++--------------- src/nkeys.zig | 3 +-- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'src') 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 { /// | 6 | 0b11000 | /// | 7 | 0b10000 | fn frontBits(self: *const Self) ?u5 { - // bit_off bitmask shl shr frontBits - // 0 0b11111000 3 0b11111 - // 1 0b01111100 2 0b11111 - // 2 0b00111110 1 0b11111 - // 3 0b00011111 0 0 0b11111 - // 4 0b00001111 1 0b11110 - // 5 0b00000111 2 0b11100 - // 6 0b00000011 3 0b11000 - // 7 0b00000001 4 0b10000 const index = self.index orelse return null; - const bitmask = @as(u8, 0b11111000) >> self.bit_off; - const bits = self.buffer[index] & bitmask; + 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)); } @@ -87,10 +77,10 @@ pub const Encoder = struct { /// | `bits` | `backBits` | /// |--------|------------| /// | 0 | 0b00000 | - /// | 1 | 0b10000 | - /// | 2 | 0b11000 | - /// | 3 | 0b11100 | - /// | 4 | 0b11100 | + /// | 1 | 0b00001 | + /// | 2 | 0b00011 | + /// | 3 | 0b00111 | + /// | 4 | 0b01110 | /// | 5 | 0b11101 | fn backBits(self: *const Self, bits: u3) u5 { 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 { defer decoded.wipe(); // gets copied var key_ty_prefix = decoded.prefix[0] & 0b11111000; - var entity_ty_prefix = (decoded.prefix[0] & 0b00000111) << 5 | ((decoded.prefix[1] & 0b11111000) >> 3); + var entity_ty_prefix = (decoded.prefix[0] << 5) | (decoded.prefix[1] >> 3); if (key_ty_prefix != @enumToInt(KeyTypePrefixByte.seed)) return error.InvalidSeed; @@ -328,7 +328,6 @@ const allowed_creds_section_chars_table: [256]bool = allowed: { var table = [_]bool{false} ** 256; const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.="; for (chars) |char| table[char] = true; - break :allowed table; }; -- cgit v1.2.3