diff options
author | Rutger Broekhoff | 2024-04-27 02:25:17 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2024-04-27 02:25:17 +0200 |
commit | 66e0e65fd17d50d857ce5e4f3e8d56b3a795845c (patch) | |
tree | f437a03e561074f43438e6ea0d07f55e150cdce7 | |
parent | a50016c7481b4c8613e03af136d93309c6b30400 (diff) | |
download | zig-nkeys-main.tar.gz zig-nkeys-main.zip |
-rw-r--r-- | build.zig | 16 | ||||
-rw-r--r-- | tool/znk.zig | 4 |
2 files changed, 8 insertions, 12 deletions
@@ -1,6 +1,6 @@ | |||
1 | const std = @import("std"); | 1 | const std = @import("std"); |
2 | 2 | ||
3 | pub fn build(b: *std.build.Builder) !void { | 3 | pub fn build(b: *std.Build) !void { |
4 | const target = b.standardTargetOptions(.{}); | 4 | const target = b.standardTargetOptions(.{}); |
5 | const optimize = b.standardOptimizeOption(.{}); | 5 | const optimize = b.standardOptimizeOption(.{}); |
6 | 6 | ||
@@ -14,15 +14,11 @@ pub fn build(b: *std.build.Builder) !void { | |||
14 | const test_step = b.step("test", "Run library tests"); | 14 | const test_step = b.step("test", "Run library tests"); |
15 | test_step.dependOn(&run_lib_tests.step); | 15 | test_step.dependOn(&run_lib_tests.step); |
16 | 16 | ||
17 | const znk_version = "0.2.1"; | 17 | const znk_version = "0.2.2"; |
18 | 18 | ||
19 | const znk_options = b.addOptions(); | 19 | const znk_options = b.addOptions(); |
20 | znk_options.addOption([]const u8, "version", znk_version); | 20 | znk_options.addOption([]const u8, "version", znk_version); |
21 | 21 | ||
22 | const nkeys_module = b.addModule("nkeys", .{ | ||
23 | .source_file = .{ .path = "src/main.zig" }, | ||
24 | }); | ||
25 | |||
26 | const lib = b.addStaticLibrary(.{ | 22 | const lib = b.addStaticLibrary(.{ |
27 | .name = "nkeys", | 23 | .name = "nkeys", |
28 | .root_source_file = .{ .path = "src/main.zig" }, | 24 | .root_source_file = .{ .path = "src/main.zig" }, |
@@ -37,8 +33,8 @@ pub fn build(b: *std.build.Builder) !void { | |||
37 | .target = target, | 33 | .target = target, |
38 | .optimize = optimize, | 34 | .optimize = optimize, |
39 | }); | 35 | }); |
40 | znk_tests.addModule("nkeys", nkeys_module); | 36 | znk_tests.root_module.addImport("nkeys", &lib.root_module); |
41 | znk_tests.addOptions("build_options", znk_options); | 37 | znk_tests.root_module.addOptions("build_options", znk_options); |
42 | const run_znk_tests = b.addRunArtifact(znk_tests); | 38 | const run_znk_tests = b.addRunArtifact(znk_tests); |
43 | 39 | ||
44 | const znk_test_step = b.step("test-znk", "Run znk tests"); | 40 | const znk_test_step = b.step("test-znk", "Run znk tests"); |
@@ -50,8 +46,8 @@ pub fn build(b: *std.build.Builder) !void { | |||
50 | .target = target, | 46 | .target = target, |
51 | .optimize = optimize, | 47 | .optimize = optimize, |
52 | }); | 48 | }); |
53 | znk.addModule("nkeys", nkeys_module); | 49 | znk.root_module.addImport("nkeys", &lib.root_module); |
54 | znk.addOptions("build_options", znk_options); | 50 | znk.root_module.addOptions("build_options", znk_options); |
55 | 51 | ||
56 | b.installArtifact(znk); | 52 | b.installArtifact(znk); |
57 | 53 | ||
diff --git a/tool/znk.zig b/tool/znk.zig index af8f757..c50edae 100644 --- a/tool/znk.zig +++ b/tool/znk.zig | |||
@@ -438,7 +438,7 @@ fn PrefixKeyGenerator(comptime EntropyReaderType: type) type { | |||
438 | fn generatePrivate(self: *Self) !void { | 438 | fn generatePrivate(self: *Self) !void { |
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(.seq_cst)) { |
442 | const 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 |
@@ -447,7 +447,7 @@ fn PrefixKeyGenerator(comptime EntropyReaderType: type) type { | |||
447 | 447 | ||
448 | var public_key = kp.publicKeyText(); | 448 | var public_key = kp.publicKeyText(); |
449 | if (mem.startsWith(u8, public_key[1..], self.prefix)) { | 449 | if (mem.startsWith(u8, public_key[1..], self.prefix)) { |
450 | if (self.done.swap(true, .SeqCst)) return; // another thread is already done | 450 | if (self.done.swap(true, .seq_cst)) return; // another thread is already done |
451 | 451 | ||
452 | info("{s}", .{kp.seedText()}); | 452 | info("{s}", .{kp.seedText()}); |
453 | info("{s}", .{public_key}); | 453 | info("{s}", .{public_key}); |