Hash functions now accept an option set
- This avoids having multiple `init()` functions for every combination of optional parameters - The API is consistent across all hash functions - New options can be added later without breaking existing applications. For example, this is going to come in handy if we implement parallelization for BLAKE2 and BLAKE3. - We don't have a mix of snake_case and camelCase functions any more, at least in the public crypto API Support for BLAKE2 salt and personalization (more commonly called context) parameters have been implemented by the way to illustrate this.
This commit is contained in:
@@ -56,7 +56,7 @@ pub const CacheHash = struct {
|
||||
pub fn init(allocator: *Allocator, dir: fs.Dir, manifest_dir_path: []const u8) !CacheHash {
|
||||
return CacheHash{
|
||||
.allocator = allocator,
|
||||
.blake3 = Blake3.init(),
|
||||
.blake3 = Blake3.init(.{}),
|
||||
.manifest_dir = try dir.makeOpenPath(manifest_dir_path, .{}),
|
||||
.manifest_file = null,
|
||||
.manifest_dirty = false,
|
||||
@@ -137,7 +137,7 @@ pub const CacheHash = struct {
|
||||
|
||||
base64_encoder.encode(self.b64_digest[0..], &bin_digest);
|
||||
|
||||
self.blake3 = Blake3.init();
|
||||
self.blake3 = Blake3.init(.{});
|
||||
self.blake3.update(&bin_digest);
|
||||
|
||||
const manifest_file_path = try fmt.allocPrint(self.allocator, "{}.txt", .{self.b64_digest});
|
||||
@@ -256,7 +256,7 @@ pub const CacheHash = struct {
|
||||
// cache miss
|
||||
// keep the manifest file open
|
||||
// reset the hash
|
||||
self.blake3 = Blake3.init();
|
||||
self.blake3 = Blake3.init(.{});
|
||||
self.blake3.update(&bin_digest);
|
||||
|
||||
// Remove files not in the initial hash
|
||||
@@ -304,7 +304,7 @@ pub const CacheHash = struct {
|
||||
|
||||
// Hash while reading from disk, to keep the contents in the cpu cache while
|
||||
// doing hashing.
|
||||
var blake3 = Blake3.init();
|
||||
var blake3 = Blake3.init(.{});
|
||||
var off: usize = 0;
|
||||
while (true) {
|
||||
// give me everything you've got, captain
|
||||
@@ -434,7 +434,7 @@ pub const CacheHash = struct {
|
||||
};
|
||||
|
||||
fn hashFile(file: fs.File, bin_digest: []u8) !void {
|
||||
var blake3 = Blake3.init();
|
||||
var blake3 = Blake3.init(.{});
|
||||
var buf: [1024]u8 = undefined;
|
||||
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user