aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.zig
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2023-12-04 20:09:47 +0100
committerLibravatar Rutger Broekhoff2023-12-04 20:09:47 +0100
commitab5af4606e0af3fdf24ab1d6640ab0577cc6dffd (patch)
tree8f5651cb47b7151dd45d0ae16974987039cf24d6 /src/main.zig
parent97028ba6f45587bafa66cf8596ba1f23ffadf619 (diff)
downloadzig-nkeys-ab5af4606e0af3fdf24ab1d6640ab0577cc6dffd.tar.gz
zig-nkeys-ab5af4606e0af3fdf24ab1d6640ab0577cc6dffd.zip
Fix CI
I am aware that changing these variables to be constants is not required for the next Zig release, but thought it would be nice to already have it done and clean in general.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/main.zig b/src/main.zig
index 18c86d1..a93c0ea 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -127,8 +127,8 @@ pub const SeedKeyPair = struct {
127 var decoded = try decode(2, Ed25519.KeyPair.seed_length, text); 127 var decoded = try decode(2, Ed25519.KeyPair.seed_length, text);
128 defer decoded.wipe(); // gets copied 128 defer decoded.wipe(); // gets copied
129 129
130 var key_ty_prefix = decoded.prefix[0] & 0b11111000; 130 const key_ty_prefix = decoded.prefix[0] & 0b11111000;
131 var role_prefix = (decoded.prefix[0] << 5) | (decoded.prefix[1] >> 3); 131 const role_prefix = (decoded.prefix[0] << 5) | (decoded.prefix[1] >> 3);
132 132
133 if (key_ty_prefix != prefix_byte_seed) 133 if (key_ty_prefix != prefix_byte_seed)
134 return error.InvalidSeed; 134 return error.InvalidSeed;
@@ -288,8 +288,8 @@ fn encode(
288 288
289 mem.copy(u8, &buf, prefix[0..]); 289 mem.copy(u8, &buf, prefix[0..]);
290 mem.copy(u8, buf[prefix_len..], data[0..]); 290 mem.copy(u8, buf[prefix_len..], data[0..]);
291 var off = prefix_len + data_len; 291 const off = prefix_len + data_len;
292 var checksum = crc16.make(buf[0..off]); 292 const checksum = crc16.make(buf[0..off]);
293 mem.writeIntLittle(u16, buf[buf.len - 2 .. buf.len], checksum); 293 mem.writeIntLittle(u16, buf[buf.len - 2 .. buf.len], checksum);
294 294
295 var text: encoded_key(prefix_len, data_len) = undefined; 295 var text: encoded_key(prefix_len, data_len) = undefined;
@@ -321,7 +321,7 @@ fn decode(
321 defer wipeBytes(&raw); 321 defer wipeBytes(&raw);
322 std.debug.assert((try base32.Decoder.decode(&raw, text[0..])).len == raw.len); 322 std.debug.assert((try base32.Decoder.decode(&raw, text[0..])).len == raw.len);
323 323
324 var checksum = mem.readIntLittle(u16, raw[raw.len - 2 .. raw.len]); 324 const checksum = mem.readIntLittle(u16, raw[raw.len - 2 .. raw.len]);
325 try crc16.validate(raw[0 .. raw.len - 2], checksum); 325 try crc16.validate(raw[0 .. raw.len - 2], checksum);
326 326
327 return DecodedNkey(prefix_len, data_len){ 327 return DecodedNkey(prefix_len, data_len){
@@ -336,7 +336,7 @@ pub fn isValidEncoding(text: []const u8) bool {
336 var dec = base32.Decoder.init(text); 336 var dec = base32.Decoder.init(text);
337 var crc_buf: [2]u8 = undefined; 337 var crc_buf: [2]u8 = undefined;
338 var crc_buf_len: u8 = 0; 338 var crc_buf_len: u8 = 0;
339 var expect_len: usize = base32.Decoder.calcSize(text.len); 339 const expect_len: usize = base32.Decoder.calcSize(text.len);
340 var wrote_n_total: usize = 0; 340 var wrote_n_total: usize = 0;
341 while (dec.next() catch return false) |b| { 341 while (dec.next() catch return false) |b| {
342 wrote_n_total += 1; 342 wrote_n_total += 1;
@@ -347,7 +347,7 @@ pub fn isValidEncoding(text: []const u8) bool {
347 } 347 }
348 std.debug.assert(wrote_n_total == expect_len); 348 std.debug.assert(wrote_n_total == expect_len);
349 if (crc_buf_len != 2) unreachable; 349 if (crc_buf_len != 2) unreachable;
350 var got_crc = mem.readIntLittle(u16, &crc_buf); 350 const got_crc = mem.readIntLittle(u16, &crc_buf);
351 return made_crc == got_crc; 351 return made_crc == got_crc;
352} 352}
353 353
@@ -725,6 +725,6 @@ test "parse decorated seed and JWT" {
725 got_kp = try parseDecoratedNkey(creds); 725 got_kp = try parseDecoratedNkey(creds);
726 try testing.expectEqualStrings(seed, &got_kp.seedText()); 726 try testing.expectEqualStrings(seed, &got_kp.seedText());
727 727
728 var got_jwt = parseDecoratedJwt(creds); 728 const got_jwt = parseDecoratedJwt(creds);
729 try testing.expectEqualStrings(jwt, got_jwt); 729 try testing.expectEqualStrings(jwt, got_jwt);
730} 730}