zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit fce6dbb8907c1bfc8da381632276cc3df8f783e3 (tree)
parent e357134f0f02cbd458b59eaf8de3efa0cf473b35
Author: Meghan Denny <hello@nektro.net>
Date:   Tue,  9 Jun 2026 17:01:54 -0700

std.crypto: argon2/scrypt: cleanup VerifyOptions

Diffstat:
Mlib/std/crypto/argon2.zig | 7++-----
Mlib/std/crypto/scrypt.zig | 11++++-------
2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/lib/std/crypto/argon2.zig b/lib/std/crypto/argon2.zig @@ -609,10 +609,8 @@ pub fn strHash( } /// Options for hash verification. -/// -/// Allocator is required for argon2. pub const VerifyOptions = struct { - allocator: ?mem.Allocator, + allocator: mem.Allocator, }; /// Verify that a previously computed hash is valid for a given password. @@ -622,8 +620,7 @@ pub fn strVerify( options: VerifyOptions, io: Io, ) Error!void { - const allocator = options.allocator orelse return Error.AllocatorRequired; - return PhcFormatHasher.verify(allocator, str, password, io); + return PhcFormatHasher.verify(options.allocator, str, password, io); } test "argon2d" { diff --git a/lib/std/crypto/scrypt.zig b/lib/std/crypto/scrypt.zig @@ -566,10 +566,8 @@ pub fn strHashWithSalt( } /// Options for hash verification. -/// -/// Allocator is required for scrypt. pub const VerifyOptions = struct { - allocator: ?mem.Allocator, + allocator: mem.Allocator, }; /// Verify that a previously computed hash is valid for a given password. @@ -578,11 +576,10 @@ pub fn strVerify( password: []const u8, options: VerifyOptions, ) Error!void { - const allocator = options.allocator orelse return Error.AllocatorRequired; if (mem.startsWith(u8, str, crypt_format.prefix)) { - return CryptFormatHasher.verify(allocator, str, password); + return CryptFormatHasher.verify(options.allocator, str, password); } else { - return PhcFormatHasher.verify(allocator, str, password); + return PhcFormatHasher.verify(options.allocator, str, password); } } @@ -693,7 +690,7 @@ test "strHash and strVerify" { const password = "testpass"; const params = Params.interactive; - const verify_options = VerifyOptions{ .allocator = alloc }; + const verify_options: VerifyOptions = .{ .allocator = alloc }; var buf: [128]u8 = undefined; {