tiny.content.Identifier
Defined in tiny.content.
Carries the identity of content, and nothing else about it, so a caller compares identifiers to decide whether two byte strings are the same.
API (5)
Actions
Public operations.
eql: Reports whether two identifiers carry the same algorithm and the same digest, which is how a provider looks for an identifier among the ones it holds.fromBytes: Derives an identifier from the complete bytes by running the chosen hash over every byte and pairing the digest with the algorithm tag.matches: Checks bytes a provider staged or read by rehashing them with this identifier's algorithm and reporting whether the digests agree.
Fields and members
Public fields and members.
Source
Source: lib/content/src/model.zig:19
zig
/// Carries the identity of content, and nothing else about it, so a caller/// compares identifiers to decide whether two byte strings are the same. The/// struct holds two fields: the algorithm and its 32-byte digest, so it names/// no location, no provider, and no type.pub const Identifier = struct { algorithm: Algorithm, digest: [digest_bytes]u8, /// Derives an identifier from the complete bytes by running the chosen hash /// over every byte and pairing the digest with the algorithm tag. pub fn fromBytes(algorithm: Algorithm, bytes: []const u8) Identifier { var digest: [digest_bytes]u8 = undefined; switch (algorithm) { .blake3 => std.crypto.hash.Blake3.hash(bytes, &digest, .{}), .sha256 => std.crypto.hash.sha2.Sha256.hash(bytes, &digest, .{}), } return .{ .algorithm = algorithm, .digest = digest }; } /// Reports whether two identifiers carry the same algorithm and the same /// digest, which is how a provider looks for an identifier among the ones /// it holds. The check compares the digests in constant time, so the answer /// leaks nothing about where they first differ. pub fn eql(left: Identifier, right: Identifier) bool { const algorithm_matches = left.algorithm == right.algorithm; const digest_matches = std.crypto.timing_safe.eql( [digest_bytes]u8, left.digest, right.digest, ); return algorithm_matches and digest_matches; } /// Checks bytes a provider staged or read by rehashing them with this /// identifier's algorithm and reporting whether the digests agree. pub fn matches(self: Identifier, bytes: []const u8) bool { return self.eql(fromBytes(self.algorithm, bytes)); }};Source: lib/content/src/root.zig:30
zig
pub const Identifier = model.Identifier;Audit
| Definitions | 4 |
|---|---|
| Public names | 4 |
| Members | 2 |
| Version | 26.7.0 |
| Revision | daab053ee433 |