| ... | ... | @@ -132,9 +132,9 @@ pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string) |
| 132 | 132 | const data = try file.reader().readAllAlloc(alloc, gb); |
| 133 | 133 | const expected = hash.string; |
| 134 | 134 | const actual = switch (hash.id) { |
| 135 | | .blake3 => &try do_hash(alloc, std.crypto.hash.Blake3, data), |
| 136 | | .sha256 => &try do_hash(alloc, std.crypto.hash.sha2.Sha256, data), |
| 137 | | .sha512 => &try do_hash(alloc, std.crypto.hash.sha2.Sha512, data), |
| 135 | .blake3 => &try do_hash(std.crypto.hash.Blake3, data), |
| 136 | .sha256 => &try do_hash(std.crypto.hash.sha2.Sha256, data), |
| 137 | .sha512 => &try do_hash(std.crypto.hash.sha2.Sha512, data), |
| 138 | 138 | }; |
| 139 | 139 | const result = std.mem.startsWith(u8, actual, expected); |
| 140 | 140 | if (!result) { |
| ... | ... | @@ -143,13 +143,8 @@ pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string) |
| 143 | 143 | return result; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | | pub fn do_hash(alloc: std.mem.Allocator, comptime algo: type, data: string) ![algo.digest_length * 2]u8 { |
| 147 | | var h = algo.init(.{}); |
| 148 | | var out: [algo.digest_length]u8 = undefined; |
| 149 | | h.update(data); |
| 150 | | h.final(&out); |
| 151 | | const hex = try std.fmt.allocPrint(alloc, "{x}", .{std.fmt.fmtSliceHexLower(out[0..])}); |
| 152 | | return hex[0 .. algo.digest_length * 2].*; |
| 146 | pub fn do_hash(comptime algo: type, data: string) ![algo.digest_length * 2]u8 { |
| 147 | return extras.to_hex(extras.hashBytes(algo, data)); |
| 153 | 148 | } |
| 154 | 149 | |
| 155 | 150 | /// Returns the result of running `git rev-parse HEAD` |