aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--.github/workflows/main.yml2
-rw-r--r--build.zig.zon2
-rw-r--r--src/main.zig16
-rw-r--r--tool/znk.zig12
4 files changed, 16 insertions, 16 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 544d23a..b752627 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -12,7 +12,7 @@ jobs:
12 runs-on: ubuntu-latest 12 runs-on: ubuntu-latest
13 steps: 13 steps:
14 - name: Install the latest Zig version 14 - name: Install the latest Zig version
15 run: sudo snap install zig --classic --edge 15 run: sudo snap install zig --classic
16 16
17 - uses: actions/checkout@v2 17 - uses: actions/checkout@v2
18 18
diff --git a/build.zig.zon b/build.zig.zon
index 098744d..d922fdd 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,5 +1,5 @@
1.{ 1.{
2 .name = "zig-nkeys", 2 .name = "zig-nkeys",
3 .version = "0.5.0", 3 .version = "0.5.1",
4 .paths = .{"."}, 4 .paths = .{"."},
5} 5}
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}
diff --git a/tool/znk.zig b/tool/znk.zig
index 554f191..fb2412f 100644
--- a/tool/znk.zig
+++ b/tool/znk.zig
@@ -166,7 +166,7 @@ pub fn cmdGen(arena: Allocator, args: []const []const u8) !void {
166 fatal("failed to generate key", .{}); 166 fatal("failed to generate key", .{});
167 }; 167 };
168 } else { 168 } else {
169 var gen_result = res: { 169 const gen_result = res: {
170 if (entropy) |e| { 170 if (entropy) |e| {
171 break :res nkeys.SeedKeyPair.generateWithCustomEntropy(role.?, e.reader()); 171 break :res nkeys.SeedKeyPair.generateWithCustomEntropy(role.?, e.reader());
172 } else { 172 } else {
@@ -266,7 +266,7 @@ pub fn cmdSign(arena: Allocator, args: []const []const u8) !void {
266 defer nkey.wipe(); 266 defer nkey.wipe();
267 267
268 const sig = nkey.sign(content) catch fatal("could not generate signature", .{}); 268 const sig = nkey.sign(content) catch fatal("could not generate signature", .{});
269 var encoded_sig = try arena.alloc(u8, std.base64.standard.Encoder.calcSize(std.crypto.sign.Ed25519.Signature.encoded_length)); 269 const encoded_sig = try arena.alloc(u8, std.base64.standard.Encoder.calcSize(std.crypto.sign.Ed25519.Signature.encoded_length));
270 _ = std.base64.standard.Encoder.encode(encoded_sig, &sig.toBytes()); 270 _ = std.base64.standard.Encoder.encode(encoded_sig, &sig.toBytes());
271 try stdout.writeAll(encoded_sig); 271 try stdout.writeAll(encoded_sig);
272 try stdout.writeAll("\n"); 272 try stdout.writeAll("\n");
@@ -439,7 +439,7 @@ fn PrefixKeyGenerator(comptime EntropyReaderType: type) type {
439 var rr = RandomReader.init(&std.crypto.random); 439 var rr = RandomReader.init(&std.crypto.random);
440 var brr = io.BufferedReader(1024 * 4096, @TypeOf(rr.reader())){ .unbuffered_reader = rr.reader() }; 440 var brr = io.BufferedReader(1024 * 4096, @TypeOf(rr.reader())){ .unbuffered_reader = rr.reader() };
441 while (!self.done.load(.SeqCst)) { 441 while (!self.done.load(.SeqCst)) {
442 var gen_result = if (self.entropy) |entropy| 442 const gen_result = if (self.entropy) |entropy|
443 nkeys.SeedKeyPair.generateWithCustomEntropy(self.role, entropy) 443 nkeys.SeedKeyPair.generateWithCustomEntropy(self.role, entropy)
444 else 444 else
445 nkeys.SeedKeyPair.generateWithCustomEntropy(self.role, brr.reader()); 445 nkeys.SeedKeyPair.generateWithCustomEntropy(self.role, brr.reader());
@@ -463,8 +463,8 @@ fn PrefixKeyGenerator(comptime EntropyReaderType: type) type {
463 } 463 }
464 } else struct { 464 } else struct {
465 pub fn generate(self: *Self) !void { 465 pub fn generate(self: *Self) !void {
466 var cpu_count = try std.Thread.getCpuCount(); 466 const cpu_count = try std.Thread.getCpuCount();
467 var threads = try self.allocator.alloc(std.Thread, cpu_count * 4); 467 const threads = try self.allocator.alloc(std.Thread, cpu_count * 4);
468 defer self.allocator.free(threads); 468 defer self.allocator.free(threads);
469 for (threads) |*thread| thread.* = try std.Thread.spawn(.{}, Self.generatePrivate, .{self}); 469 for (threads) |*thread| thread.* = try std.Thread.spawn(.{}, Self.generatePrivate, .{self});
470 for (threads) |thread| thread.join(); 470 for (threads) |thread| thread.join();
@@ -540,7 +540,7 @@ pub const Nkey = union(enum) {
540}; 540};
541 541
542pub fn readKeyFile(allocator: Allocator, file: fs.File) ?Nkey { 542pub fn readKeyFile(allocator: Allocator, file: fs.File) ?Nkey {
543 var bytes = file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch fatal("could not read key file", .{}); 543 const bytes = file.readToEndAlloc(allocator, std.math.maxInt(usize)) catch fatal("could not read key file", .{});
544 defer { 544 defer {
545 for (bytes) |*b| b.* = 0; 545 for (bytes) |*b| b.* = 0;
546 allocator.free(bytes); 546 allocator.free(bytes);