authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:59:43 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:59:43 -07:00
logdd3c55d7db9340f09256a5f5515a86ecfcedb991
tree59df16b3a0d3fb62ec2fe44d3f191720f7123860
parent2ffb060cfc4052fd3345536913d6fe15b4826b54

remove global allocator from u.do_hash


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

src/common.zig+1-1
......@@ -222,7 +222,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
222222 return zigmod.Module{
223223 .alloc = gpa,
224224 .is_sys_lib = true,
225 .id = try u.do_hash(std.crypto.hash.sha3.Sha3_384, d.path),
225 .id = try u.do_hash(gpa, std.crypto.hash.sha3.Sha3_384, d.path),
226226 .name = d.path,
227227 .only_os = d.only_os,
228228 .except_os = d.except_os,
src/util/funcs.zig+5-5
......@@ -214,9 +214,9 @@ pub fn validate_hash(alloc: *std.mem.Allocator, input: string, file_path: string
214214 const data = try file.reader().readAllAlloc(alloc, gb);
215215 const expected = hash.string;
216216 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),
220220 };
221221 const result = std.mem.startsWith(u8, actual, expected);
222222 if (!result) {
......@@ -225,12 +225,12 @@ pub fn validate_hash(alloc: *std.mem.Allocator, input: string, file_path: string
225225 return result;
226226}
227227
228pub fn do_hash(comptime algo: type, data: string) !string {
228pub fn do_hash(alloc: *std.mem.Allocator, comptime algo: type, data: string) !string {
229229 const h = &algo.init(.{});
230230 var out: [algo.digest_length]u8 = undefined;
231231 h.update(data);
232232 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..])});
234234 return hex;
235235}
236236