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...@@ -222,7 +222,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
222 return zigmod.Module{222 return zigmod.Module{
223 .alloc = gpa,223 .alloc = gpa,
224 .is_sys_lib = true,224 .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),
226 .name = d.path,226 .name = d.path,
227 .only_os = d.only_os,227 .only_os = d.only_os,
228 .except_os = d.except_os,228 .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...@@ -214,9 +214,9 @@ pub fn validate_hash(alloc: *std.mem.Allocator, input: string, file_path: string
214 const data = try file.reader().readAllAlloc(alloc, gb);214 const data = try file.reader().readAllAlloc(alloc, gb);
215 const expected = hash.string;215 const expected = hash.string;
216 const actual = switch (hash.id) {216 const actual = switch (hash.id) {
217 .blake3 => try do_hash(std.crypto.hash.Blake3, data),217 .blake3 => try do_hash(alloc, std.crypto.hash.Blake3, data),
218 .sha256 => try do_hash(std.crypto.hash.sha2.Sha256, data),218 .sha256 => try do_hash(alloc, std.crypto.hash.sha2.Sha256, data),
219 .sha512 => try do_hash(std.crypto.hash.sha2.Sha512, data),219 .sha512 => try do_hash(alloc, std.crypto.hash.sha2.Sha512, data),
220 };220 };
221 const result = std.mem.startsWith(u8, actual, expected);221 const result = std.mem.startsWith(u8, actual, expected);
222 if (!result) {222 if (!result) {
...@@ -225,12 +225,12 @@ pub fn validate_hash(alloc: *std.mem.Allocator, input: string, file_path: string...@@ -225,12 +225,12 @@ pub fn validate_hash(alloc: *std.mem.Allocator, input: string, file_path: string
225 return result;225 return result;
226}226}
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 {
229 const h = &algo.init(.{});229 const h = &algo.init(.{});
230 var out: [algo.digest_length]u8 = undefined;230 var out: [algo.digest_length]u8 = undefined;
231 h.update(data);231 h.update(data);
232 h.final(&out);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 return hex;234 return hex;
235}235}
236236