authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-04 10:39:03 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-04 10:39:03 -07:00
log3c223d19106b4bf5670659ebbd4351ab1113175a
tree50b9240d461e7fc9db59e9b8cc66c7f4f871bc6f
parent151e112a6a94b8bb0a8b3c3457d179d2c66ad478

do_hash has no need to take an Allocator


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

src/common.zig+1-1
......@@ -230,7 +230,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
230230 .system_lib, .framework => {
231231 return zigmod.Module{
232232 .type = d.type,
233 .id = try u.do_hash(options.alloc, std.crypto.hash.sha3.Shake(96), d.path),
233 .id = try u.do_hash(std.crypto.hash.sha3.Shake(96), d.path),
234234 .name = d.path,
235235 .only_os = d.only_os,
236236 .except_os = d.except_os,
src/util/funcs.zig+5-10
......@@ -132,9 +132,9 @@ pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string)
132132 const data = try file.reader().readAllAlloc(alloc, gb);
133133 const expected = hash.string;
134134 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),
138138 };
139139 const result = std.mem.startsWith(u8, actual, expected);
140140 if (!result) {
......@@ -143,13 +143,8 @@ pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string)
143143 return result;
144144}
145145
146pub 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].*;
146pub fn do_hash(comptime algo: type, data: string) ![algo.digest_length * 2]u8 {
147 return extras.to_hex(extras.hashBytes(algo, data));
153148}
154149
155150/// Returns the result of running `git rev-parse HEAD`