aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2021-09-20 11:57:39 +0200
committerLibravatar Rutger Broekhoff2021-09-20 11:57:39 +0200
commit29fb00a1c3a60d4faca2fb29ae56b73362baa917 (patch)
tree5542426d762402fb5beb66da3ae8c2bc42d80d89
parent1148e92a6a84d5fa65e4e8ef18328fcb4f16664d (diff)
downloadzig-nkeys-0.3.1.tar.gz
zig-nkeys-0.3.1.zip
Make compatible with Zig master0.3.1
-rw-r--r--build.zig11
-rw-r--r--gyro.zzz2
-rw-r--r--src/main.zig8
-rw-r--r--tool/znk.zig10
4 files changed, 17 insertions, 14 deletions
diff --git a/build.zig b/build.zig
index 6758252..412408b 100644
--- a/build.zig
+++ b/build.zig
@@ -4,7 +4,7 @@ pub fn build(b: *std.build.Builder) !void {
4 const mode = b.standardReleaseOptions(); 4 const mode = b.standardReleaseOptions();
5 const target = b.standardTargetOptions(.{}); 5 const target = b.standardTargetOptions(.{});
6 6
7 var lib_tests = b.addTest("src/main.zig"); 7 const lib_tests = b.addTest("src/main.zig");
8 lib_tests.setBuildMode(mode); 8 lib_tests.setBuildMode(mode);
9 9
10 const test_step = b.step("test", "Run library tests"); 10 const test_step = b.step("test", "Run library tests");
@@ -12,10 +12,13 @@ pub fn build(b: *std.build.Builder) !void {
12 12
13 const znk_version = "0.2.1"; 13 const znk_version = "0.2.1";
14 14
15 var znk_tests = b.addTest("tool/znk.zig"); 15 const znk_options = b.addOptions();
16 znk_options.addOption([]const u8, "version", znk_version);
17
18 const znk_tests = b.addTest("tool/znk.zig");
16 znk_tests.setBuildMode(mode); 19 znk_tests.setBuildMode(mode);
17 znk_tests.addPackagePath("nkeys", "src/main.zig"); 20 znk_tests.addPackagePath("nkeys", "src/main.zig");
18 znk_tests.addBuildOption([]const u8, "version", znk_version); 21 znk_tests.addOptions("build_options", znk_options);
19 22
20 const znk_test_step = b.step("test-znk", "Run znk tests"); 23 const znk_test_step = b.step("test-znk", "Run znk tests");
21 znk_test_step.dependOn(&znk_tests.step); 24 znk_test_step.dependOn(&znk_tests.step);
@@ -24,7 +27,7 @@ pub fn build(b: *std.build.Builder) !void {
24 znk.setBuildMode(mode); 27 znk.setBuildMode(mode);
25 znk.setTarget(target); 28 znk.setTarget(target);
26 znk.addPackagePath("nkeys", "src/main.zig"); 29 znk.addPackagePath("nkeys", "src/main.zig");
27 znk.addBuildOption([]const u8, "version", znk_version); 30 znk.addOptions("build_options", znk_options);
28 31
29 const znk_install = b.addInstallArtifact(znk); 32 const znk_install = b.addInstallArtifact(znk);
30 33
diff --git a/gyro.zzz b/gyro.zzz
index d1533d3..da457a6 100644
--- a/gyro.zzz
+++ b/gyro.zzz
@@ -1,6 +1,6 @@
1pkgs: 1pkgs:
2 nkeys: 2 nkeys:
3 version: 0.3.0 3 version: 0.3.1
4 description: "NKeys support for Zig" 4 description: "NKeys support for Zig"
5 license: Apache-2.0 5 license: Apache-2.0
6 source_url: "https://github.com/rutgerbrf/zig-nkeys" 6 source_url: "https://github.com/rutgerbrf/zig-nkeys"
diff --git a/src/main.zig b/src/main.zig
index a299afe..3206f45 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -390,7 +390,7 @@ pub fn areKeySectionContentsValid(contents: []const u8) bool {
390 return true; 390 return true;
391} 391}
392 392
393pub fn findKeySection(line_it: *std.mem.SplitIterator) ?[]const u8 { 393pub fn findKeySection(line_it: *std.mem.SplitIterator(u8)) ?[]const u8 {
394 while (true) { 394 while (true) {
395 const opening_line = line_it.next() orelse return null; 395 const opening_line = line_it.next() orelse return null;
396 if (!isKeySectionBarrier(opening_line, true)) continue; 396 if (!isKeySectionBarrier(opening_line, true)) continue;
@@ -406,12 +406,12 @@ pub fn findKeySection(line_it: *std.mem.SplitIterator) ?[]const u8 {
406} 406}
407 407
408pub fn parseDecoratedJwt(contents: []const u8) []const u8 { 408pub fn parseDecoratedJwt(contents: []const u8) []const u8 {
409 var line_it = mem.split(contents, "\n"); 409 var line_it = mem.split(u8, contents, "\n");
410 return findKeySection(&line_it) orelse return contents; 410 return findKeySection(&line_it) orelse return contents;
411} 411}
412 412
413pub fn parseDecoratedNkey(contents: []const u8) NoNkeySeedFoundError!SeedKeyPair { 413pub fn parseDecoratedNkey(contents: []const u8) NoNkeySeedFoundError!SeedKeyPair {
414 var line_it = mem.split(contents, "\n"); 414 var line_it = mem.split(u8, contents, "\n");
415 var seed: ?[]const u8 = null; 415 var seed: ?[]const u8 = null;
416 if (findKeySection(&line_it) != null) 416 if (findKeySection(&line_it) != null)
417 seed = findKeySection(&line_it); 417 seed = findKeySection(&line_it);
@@ -439,7 +439,7 @@ fn isValidCredsNkey(text: []const u8) bool {
439} 439}
440 440
441fn findNkey(text: []const u8) ?[]const u8 { 441fn findNkey(text: []const u8) ?[]const u8 {
442 var line_it = std.mem.split(text, "\n"); 442 var line_it = std.mem.split(u8, text, "\n");
443 while (line_it.next()) |line| { 443 while (line_it.next()) |line| {
444 for (line) |c, i| { 444 for (line) |c, i| {
445 if (!ascii.isSpace(c)) { 445 if (!ascii.isSpace(c)) {
diff --git a/tool/znk.zig b/tool/znk.zig
index 0a4b764..ff5540e 100644
--- a/tool/znk.zig
+++ b/tool/znk.zig
@@ -443,11 +443,11 @@ fn PrefixKeyGenerator(comptime EntropyReaderType: type) type {
443 } 443 }
444 } else struct { 444 } else struct {
445 pub fn generate(self: *Self) !void { 445 pub fn generate(self: *Self) !void {
446 var cpu_count = try std.Thread.cpuCount(); 446 var cpu_count = try std.Thread.getCpuCount();
447 var threads = try self.allocator.alloc(*std.Thread, cpu_count); 447 var threads = try self.allocator.alloc(std.Thread, cpu_count);
448 defer self.allocator.free(threads); 448 defer self.allocator.free(threads);
449 for (threads) |*thread| thread.* = try std.Thread.spawn(Self.generatePrivate, self); 449 for (threads) |*thread| thread.* = try std.Thread.spawn(.{}, Self.generatePrivate, .{ self });
450 for (threads) |thread| thread.wait(); 450 for (threads) |thread| thread.join();
451 } 451 }
452 }; 452 };
453 }; 453 };
@@ -526,7 +526,7 @@ pub fn readKeyFile(allocator: *Allocator, file: fs.File) ?Nkey {
526 allocator.free(bytes); 526 allocator.free(bytes);
527 } 527 }
528 528
529 var iterator = mem.split(bytes, "\n"); 529 var iterator = mem.split(u8, bytes, "\n");
530 while (iterator.next()) |line| { 530 while (iterator.next()) |line| {
531 if (nkeys.isValidEncoding(line) and line.len == nkeys.text_seed_len) { 531 if (nkeys.isValidEncoding(line) and line.len == nkeys.text_seed_len) {
532 var k = Nkey.fromText(line) catch continue; 532 var k = Nkey.fromText(line) catch continue;