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...@@ -230,7 +230,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
230 .system_lib, .framework => {230 .system_lib, .framework => {
231 return zigmod.Module{231 return zigmod.Module{
232 .type = d.type,232 .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),
234 .name = d.path,234 .name = d.path,
235 .only_os = d.only_os,235 .only_os = d.only_os,
236 .except_os = d.except_os,236 .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)...@@ -132,9 +132,9 @@ pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string)
132 const data = try file.reader().readAllAlloc(alloc, gb);132 const data = try file.reader().readAllAlloc(alloc, gb);
133 const expected = hash.string;133 const expected = hash.string;
134 const actual = switch (hash.id) {134 const actual = switch (hash.id) {
135 .blake3 => &try do_hash(alloc, std.crypto.hash.Blake3, data),135 .blake3 => &try do_hash(std.crypto.hash.Blake3, data),
136 .sha256 => &try do_hash(alloc, std.crypto.hash.sha2.Sha256, data),136 .sha256 => &try do_hash(std.crypto.hash.sha2.Sha256, data),
137 .sha512 => &try do_hash(alloc, std.crypto.hash.sha2.Sha512, data),137 .sha512 => &try do_hash(std.crypto.hash.sha2.Sha512, data),
138 };138 };
139 const result = std.mem.startsWith(u8, actual, expected);139 const result = std.mem.startsWith(u8, actual, expected);
140 if (!result) {140 if (!result) {
...@@ -143,13 +143,8 @@ pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string)...@@ -143,13 +143,8 @@ pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string)
143 return result;143 return result;
144}144}
145145
146pub fn do_hash(alloc: std.mem.Allocator, comptime algo: type, data: string) ![algo.digest_length * 2]u8 {146pub fn do_hash(comptime algo: type, data: string) ![algo.digest_length * 2]u8 {
147 var h = algo.init(.{});147 return extras.to_hex(extras.hashBytes(algo, data));
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].*;
153}148}
154149
155/// Returns the result of running `git rev-parse HEAD`150/// Returns the result of running `git rev-parse HEAD`