authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-09 17:01:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-11 01:36:18+02:00
logfce6dbb8907c1bfc8da381632276cc3df8f783e3
treeb2d68a154276b5559218ccd4bbb69799ef103b9f
parente357134f0f02cbd458b59eaf8de3efa0cf473b35

std.crypto: argon2/scrypt: cleanup VerifyOptions


2 files changed, 6 insertions(+), 12 deletions(-)

lib/std/crypto/argon2.zig+2-5
...@@ -609,10 +609,8 @@ pub fn strHash(...@@ -609,10 +609,8 @@ pub fn strHash(
609}609}
610610
611/// Options for hash verification.611/// Options for hash verification.
612///
613/// Allocator is required for argon2.
614pub const VerifyOptions = struct {612pub const VerifyOptions = struct {
615 allocator: ?mem.Allocator,613 allocator: mem.Allocator,
616};614};
617615
618/// Verify that a previously computed hash is valid for a given password.616/// Verify that a previously computed hash is valid for a given password.
...@@ -622,8 +620,7 @@ pub fn strVerify(...@@ -622,8 +620,7 @@ pub fn strVerify(
622 options: VerifyOptions,620 options: VerifyOptions,
623 io: Io,621 io: Io,
624) Error!void {622) Error!void {
625 const allocator = options.allocator orelse return Error.AllocatorRequired;623 return PhcFormatHasher.verify(options.allocator, str, password, io);
626 return PhcFormatHasher.verify(allocator, str, password, io);
627}624}
628625
629test "argon2d" {626test "argon2d" {
lib/std/crypto/scrypt.zig+4-7
...@@ -566,10 +566,8 @@ pub fn strHashWithSalt(...@@ -566,10 +566,8 @@ pub fn strHashWithSalt(
566}566}
567567
568/// Options for hash verification.568/// Options for hash verification.
569///
570/// Allocator is required for scrypt.
571pub const VerifyOptions = struct {569pub const VerifyOptions = struct {
572 allocator: ?mem.Allocator,570 allocator: mem.Allocator,
573};571};
574572
575/// Verify that a previously computed hash is valid for a given password.573/// Verify that a previously computed hash is valid for a given password.
...@@ -578,11 +576,10 @@ pub fn strVerify(...@@ -578,11 +576,10 @@ pub fn strVerify(
578 password: []const u8,576 password: []const u8,
579 options: VerifyOptions,577 options: VerifyOptions,
580) Error!void {578) Error!void {
581 const allocator = options.allocator orelse return Error.AllocatorRequired;
582 if (mem.startsWith(u8, str, crypt_format.prefix)) {579 if (mem.startsWith(u8, str, crypt_format.prefix)) {
583 return CryptFormatHasher.verify(allocator, str, password);580 return CryptFormatHasher.verify(options.allocator, str, password);
584 } else {581 } else {
585 return PhcFormatHasher.verify(allocator, str, password);582 return PhcFormatHasher.verify(options.allocator, str, password);
586 }583 }
587}584}
588585
...@@ -693,7 +690,7 @@ test "strHash and strVerify" {...@@ -693,7 +690,7 @@ test "strHash and strVerify" {
693690
694 const password = "testpass";691 const password = "testpass";
695 const params = Params.interactive;692 const params = Params.interactive;
696 const verify_options = VerifyOptions{ .allocator = alloc };693 const verify_options: VerifyOptions = .{ .allocator = alloc };
697 var buf: [128]u8 = undefined;694 var buf: [128]u8 = undefined;
698695
699 {696 {