Skip to content

Commit

Permalink
Fix SRI hash generation returning garbage data (#93)
Browse files Browse the repository at this point in the history
* Fix missing free breaking SRI hash gen

Also removes that trailing whitespace which my text editor wants gone

* Heap-allocate array for SRI hash slice

* Remove redundant free of memory managed by arena

While harmless, it's not necessary, and other builtins also do not manually free.
  • Loading branch information
Shardion authored Nov 28, 2024
1 parent cb96d92 commit 6892707
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/context/Asset.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ pub const Builtins = struct {
pub const description =
\\Returns a link to the asset.
\\
\\Calling `link` on an asset will cause it to be installed
\\Calling `link` on an asset will cause it to be installed
\\under the same relative path into the output directory.
\\
\\ `content/post/bar.jpg` -> `zig-out/post/bar.jpg`
\\ `assets/foo/bar/baz.jpg` -> `zig-out/foo/bar/baz.jpg`
\\
\\Build assets will be installed under the path defined in
\\Build assets will be installed under the path defined in
\\your `build.zig`.
;
pub const examples =
Expand Down Expand Up @@ -137,14 +137,16 @@ pub const Builtins = struct {
};

const sha384 = std.crypto.hash.sha2.Sha384;
var hashed_data: [std.crypto.hash.sha2.Sha384.digest_length]u8 = undefined;
const base64 = std.base64.standard.Encoder;

var hashed_data: [sha384.digest_length]u8 = undefined;
sha384.hash(data, &hashed_data, .{});

const base64 = std.base64.standard.Encoder;
var hashed_encoded_data: [base64.calcSize(hashed_data.len)]u8 = undefined;
_ = base64.encode(&hashed_encoded_data, &hashed_data);

return Value.from(gpa, @as([]u8, "sha384-" ++ hashed_encoded_data));
const result: []u8 = try gpa.dupe(u8, "sha384-" ++ hashed_encoded_data);
return Value.from(gpa, result);
}
};

Expand Down

0 comments on commit 6892707

Please sign in to comment.