diff options
author | Rutger Broekhoff | 2021-05-26 20:07:44 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2021-05-26 20:07:44 +0200 |
commit | 1956639e8a5f4f120c2600544ca579c834f08f29 (patch) | |
tree | 10125b048831e71d51afbe2f68b8f00edad88722 /src/lib.zig | |
parent | b52b1caf6d668340ecd47baf7b994c9f090484fc (diff) | |
download | zig-nkeys-1956639e8a5f4f120c2600544ca579c834f08f29.tar.gz zig-nkeys-1956639e8a5f4f120c2600544ca579c834f08f29.zip |
Allow generating seeds with custom entropy
Diffstat (limited to 'src/lib.zig')
-rw-r--r-- | src/lib.zig | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib.zig b/src/lib.zig index 05922bd..23f0e05 100644 --- a/src/lib.zig +++ b/src/lib.zig | |||
@@ -116,6 +116,13 @@ pub const SeedKeyPair = struct { | |||
116 | return Self{ .role = role, .kp = try Ed25519.KeyPair.create(raw_seed) }; | 116 | return Self{ .role = role, .kp = try Ed25519.KeyPair.create(raw_seed) }; |
117 | } | 117 | } |
118 | 118 | ||
119 | pub fn generateWithCustomEntropy(role: Role, reader: anytype) !Self { | ||
120 | var raw_seed: [Ed25519.seed_length]u8 = undefined; | ||
121 | try reader.readNoEof(&raw_seed); | ||
122 | defer wipeBytes(&raw_seed); | ||
123 | return Self{ .role = role, .kp = try Ed25519.KeyPair.create(raw_seed) }; | ||
124 | } | ||
125 | |||
119 | pub fn fromTextSeed(text: *const text_seed) SeedDecodeError!Self { | 126 | pub fn fromTextSeed(text: *const text_seed) SeedDecodeError!Self { |
120 | var decoded = try decode(2, Ed25519.seed_length, text); | 127 | var decoded = try decode(2, Ed25519.seed_length, text); |
121 | defer decoded.wipe(); // gets copied | 128 | defer decoded.wipe(); // gets copied |
@@ -455,7 +462,7 @@ fn wipeBytes(bs: []u8) void { | |||
455 | for (bs) |*b| b.* = 0; | 462 | for (bs) |*b| b.* = 0; |
456 | } | 463 | } |
457 | 464 | ||
458 | test "reference all delcarations" { | 465 | test "reference all declarations" { |
459 | testing.refAllDecls(@This()); | 466 | testing.refAllDecls(@This()); |
460 | testing.refAllDecls(Role); | 467 | testing.refAllDecls(Role); |
461 | testing.refAllDecls(SeedKeyPair); | 468 | testing.refAllDecls(SeedKeyPair); |