aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2023-11-11 20:54:04 +0000
committerMartin Ashby <martin@ashbysoft.com>2023-11-11 20:54:04 +0000
commite51c15cc478b6c89e9100017eebfdf88aff95cca (patch)
tree3d7bc86dff0ebf06782309627f44c1152c2dd585
parente92459156c2f74de648566ca7acde3833de33425 (diff)
downloadzbt-e51c15cc478b6c89e9100017eebfdf88aff95cca.tar.gz
zbt-e51c15cc478b6c89e9100017eebfdf88aff95cca.tar.bz2
zbt-e51c15cc478b6c89e9100017eebfdf88aff95cca.tar.xz
zbt-e51c15cc478b6c89e9100017eebfdf88aff95cca.zip
Don't hex the hash
-rw-r--r--src/metainfo.zig10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/metainfo.zig b/src/metainfo.zig
index 31b14b7..29cc655 100644
--- a/src/metainfo.zig
+++ b/src/metainfo.zig
@@ -103,16 +103,14 @@ pub const Info = struct {
a.free(self.files);
}
- const info_hash_len = 40;
+ const info_hash_len = std.crypto.hash.Sha1.digest_length;
pub fn hash(self: Info, a: std.mem.Allocator) ![info_hash_len]u8 {
var b = try self.encode(a);
defer b.deinit(a);
var sha1 = std.crypto.hash.Sha1.init(.{});
var w = sha1.writer();
try b.bencode(w);
- var buf = [_]u8{0} ** info_hash_len;
- _ = std.fmt.bufPrint(&buf, "{}", .{std.fmt.fmtSliceHexLower(&sha1.finalResult())}) catch unreachable;
- return buf;
+ return sha1.finalResult();
}
};
@@ -162,5 +160,7 @@ test "info hash" {
var mi = try MetaInfo.parse(a, b);
defer mi.deinit(a);
const hash = try mi.info.hash(a);
- try std.testing.expectEqualStrings("d69f91e6b2ae4c542468d1073a71d4ea13879a7f", &hash);
+ var hash_hex = try std.fmt.allocPrint(a, "{s}", .{std.fmt.fmtSliceHexLower(&hash)});
+ defer a.free(hash_hex);
+ try std.testing.expectEqualStrings("d69f91e6b2ae4c542468d1073a71d4ea13879a7f", hash_hex);
}