diff options
author | Rutger Broekhoff | 2021-05-25 16:01:43 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2021-05-25 16:02:42 +0200 |
commit | 9d03b59a409596d12c3ec7b49066e4eaf0f463e7 (patch) | |
tree | 4b694589fdfed913724e9afd7f131d39673dfd13 /src | |
parent | 6ab0780b0240bcb47f78d35904f57694a52976f0 (diff) | |
download | zig-nkeys-9d03b59a409596d12c3ec7b49066e4eaf0f463e7.tar.gz zig-nkeys-9d03b59a409596d12c3ec7b49066e4eaf0f463e7.zip |
snake_case for fields of tagged unions
Diffstat (limited to 'src')
-rw-r--r-- | src/znk.zig | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/znk.zig b/src/znk.zig index b088dc4..4ab3077 100644 --- a/src/znk.zig +++ b/src/znk.zig | |||
@@ -232,7 +232,7 @@ pub fn cmdSign(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !vo | |||
232 | fatal("could not read file to generate signature for", .{}); | 232 | fatal("could not read file to generate signature for", .{}); |
233 | }; | 233 | }; |
234 | var nkey = readKeyFile(arena, key.?) orelse fatal("could not find a valid key", .{}); | 234 | var nkey = readKeyFile(arena, key.?) orelse fatal("could not find a valid key", .{}); |
235 | if (nkey == .PublicKey) fatal("key was provided but is not a seed or private key", .{}); | 235 | if (nkey == .public_key) fatal("key was provided but is not a seed or private key", .{}); |
236 | defer nkey.wipe(); | 236 | defer nkey.wipe(); |
237 | 237 | ||
238 | const sig = nkey.sign(content) catch fatal("could not generate signature", .{}); | 238 | const sig = nkey.sign(content) catch fatal("could not generate signature", .{}); |
@@ -424,15 +424,15 @@ fn toUpper(allocator: *Allocator, slice: []const u8) ![]u8 { | |||
424 | pub const Nkey = union(enum) { | 424 | pub const Nkey = union(enum) { |
425 | const Self = @This(); | 425 | const Self = @This(); |
426 | 426 | ||
427 | SeedKeyPair: nkeys.SeedKeyPair, | 427 | seed_key_pair: nkeys.SeedKeyPair, |
428 | PublicKey: nkeys.PublicKey, | 428 | public_key: nkeys.PublicKey, |
429 | PrivateKey: nkeys.PrivateKey, | 429 | private_key: nkeys.PrivateKey, |
430 | 430 | ||
431 | pub fn wipe(self: *Self) void { | 431 | pub fn wipe(self: *Self) void { |
432 | switch (self.*) { | 432 | switch (self.*) { |
433 | .SeedKeyPair => |*kp| kp.wipe(), | 433 | .seed_key_pair => |*kp| kp.wipe(), |
434 | .PublicKey => |*pk| pk.wipe(), | 434 | .public_key => |*pk| pk.wipe(), |
435 | .PrivateKey => |*pk| pk.wipe(), | 435 | .private_key => |*pk| pk.wipe(), |
436 | } | 436 | } |
437 | } | 437 | } |
438 | 438 | ||
@@ -442,9 +442,9 @@ pub const Nkey = union(enum) { | |||
442 | sig: [std.crypto.sign.Ed25519.signature_length]u8, | 442 | sig: [std.crypto.sign.Ed25519.signature_length]u8, |
443 | ) !void { | 443 | ) !void { |
444 | return switch (self.*) { | 444 | return switch (self.*) { |
445 | .SeedKeyPair => |*kp| try kp.verify(msg, sig), | 445 | .seed_key_pair => |*kp| try kp.verify(msg, sig), |
446 | .PublicKey => |*pk| try pk.verify(msg, sig), | 446 | .public_key => |*pk| try pk.verify(msg, sig), |
447 | .PrivateKey => |*pk| try pk.verify(msg, sig), | 447 | .private_key => |*pk| try pk.verify(msg, sig), |
448 | }; | 448 | }; |
449 | } | 449 | } |
450 | 450 | ||
@@ -453,9 +453,9 @@ pub const Nkey = union(enum) { | |||
453 | msg: []const u8, | 453 | msg: []const u8, |
454 | ) ![std.crypto.sign.Ed25519.signature_length]u8 { | 454 | ) ![std.crypto.sign.Ed25519.signature_length]u8 { |
455 | return switch (self.*) { | 455 | return switch (self.*) { |
456 | .SeedKeyPair => |*kp| try kp.sign(msg), | 456 | .seed_key_pair => |*kp| try kp.sign(msg), |
457 | .PrivateKey => |*pk| try pk.sign(msg), | 457 | .private_key => |*pk| try pk.sign(msg), |
458 | .PublicKey => return error.CantSign, | 458 | .public_key => return error.CantSign, |
459 | }; | 459 | }; |
460 | } | 460 | } |
461 | 461 | ||
@@ -465,17 +465,17 @@ pub const Nkey = union(enum) { | |||
465 | 'S' => { | 465 | 'S' => { |
466 | // It's a seed. | 466 | // It's a seed. |
467 | if (text.len != nkeys.text_seed_len) return error.InvalidSeed; | 467 | if (text.len != nkeys.text_seed_len) return error.InvalidSeed; |
468 | return Self{ .SeedKeyPair = try nkeys.SeedKeyPair.fromTextSeed(text[0..nkeys.text_seed_len]) }; | 468 | return Self{ .seed_key_pair = try nkeys.SeedKeyPair.fromTextSeed(text[0..nkeys.text_seed_len]) }; |
469 | }, | 469 | }, |
470 | 'P' => { | 470 | 'P' => { |
471 | // It's a private key. | 471 | // It's a private key. |
472 | if (text.len != nkeys.text_private_len) return error.InvalidPrivateKey; | 472 | if (text.len != nkeys.text_private_len) return error.InvalidPrivateKey; |
473 | return Self{ .PrivateKey = try nkeys.PrivateKey.fromTextPrivateKey(text[0..nkeys.text_private_len]) }; | 473 | return Self{ .private_key = try nkeys.PrivateKey.fromTextPrivateKey(text[0..nkeys.text_private_len]) }; |
474 | }, | 474 | }, |
475 | else => { | 475 | else => { |
476 | // It should be a public key. | 476 | // It should be a public key. |
477 | if (text.len != nkeys.text_public_len) return error.InvalidEncoding; | 477 | if (text.len != nkeys.text_public_len) return error.InvalidEncoding; |
478 | return Self{ .PublicKey = try nkeys.PublicKey.fromTextPublicKey(text[0..nkeys.text_public_len]) }; | 478 | return Self{ .public_key = try nkeys.PublicKey.fromTextPublicKey(text[0..nkeys.text_public_len]) }; |
479 | }, | 479 | }, |
480 | } | 480 | } |
481 | } | 481 | } |