From 1956639e8a5f4f120c2600544ca579c834f08f29 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Wed, 26 May 2021 20:07:44 +0200 Subject: Allow generating seeds with custom entropy --- src/lib.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/lib.zig') 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 { return Self{ .role = role, .kp = try Ed25519.KeyPair.create(raw_seed) }; } + pub fn generateWithCustomEntropy(role: Role, reader: anytype) !Self { + var raw_seed: [Ed25519.seed_length]u8 = undefined; + try reader.readNoEof(&raw_seed); + defer wipeBytes(&raw_seed); + return Self{ .role = role, .kp = try Ed25519.KeyPair.create(raw_seed) }; + } + pub fn fromTextSeed(text: *const text_seed) SeedDecodeError!Self { var decoded = try decode(2, Ed25519.seed_length, text); defer decoded.wipe(); // gets copied @@ -455,7 +462,7 @@ fn wipeBytes(bs: []u8) void { for (bs) |*b| b.* = 0; } -test "reference all delcarations" { +test "reference all declarations" { testing.refAllDecls(@This()); testing.refAllDecls(Role); testing.refAllDecls(SeedKeyPair); -- cgit v1.2.3