| ... | ... | @@ -214,9 +214,9 @@ pub fn validate_hash(alloc: *std.mem.Allocator, input: string, file_path: string |
| 214 | 214 | const data = try file.reader().readAllAlloc(alloc, gb); |
| 215 | 215 | const expected = hash.string; |
| 216 | 216 | const actual = switch (hash.id) { |
| 217 | | .blake3 => try do_hash(std.crypto.hash.Blake3, data), |
| 218 | | .sha256 => try do_hash(std.crypto.hash.sha2.Sha256, data), |
| 219 | | .sha512 => try do_hash(std.crypto.hash.sha2.Sha512, data), |
| 217 | .blake3 => try do_hash(alloc, std.crypto.hash.Blake3, data), |
| 218 | .sha256 => try do_hash(alloc, std.crypto.hash.sha2.Sha256, data), |
| 219 | .sha512 => try do_hash(alloc, std.crypto.hash.sha2.Sha512, data), |
| 220 | 220 | }; |
| 221 | 221 | const result = std.mem.startsWith(u8, actual, expected); |
| 222 | 222 | if (!result) { |
| ... | ... | @@ -225,12 +225,12 @@ pub fn validate_hash(alloc: *std.mem.Allocator, input: string, file_path: string |
| 225 | 225 | return result; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | | pub fn do_hash(comptime algo: type, data: string) !string { |
| 228 | pub fn do_hash(alloc: *std.mem.Allocator, comptime algo: type, data: string) !string { |
| 229 | 229 | const h = &algo.init(.{}); |
| 230 | 230 | var out: [algo.digest_length]u8 = undefined; |
| 231 | 231 | h.update(data); |
| 232 | 232 | h.final(&out); |
| 233 | | const hex = try std.fmt.allocPrint(gpa, "{x}", .{std.fmt.fmtSliceHexLower(out[0..])}); |
| 233 | const hex = try std.fmt.allocPrint(alloc, "{x}", .{std.fmt.fmtSliceHexLower(out[0..])}); |
| 234 | 234 | return hex; |
| 235 | 235 | } |
| 236 | 236 | |