Skip to main content

Module manifest

Module manifest 

Source
Expand description

Content manifests as macula 12’s macula_manifest builds them, byte for byte: fixed-size chunks (256 KiB by default), SHA-384 hashes, a 50-byte content id <<2, Codec, SHA-384>> (tag 2 names SHA-384, D24; codec 0x55 a raw block, 0x56 a manifest), and a Merkle fold that pairs an odd last hash with itself.

A manifest’s name has two encodings that must not be confused: its content id hashes the name as CBOR text, while the wire form a manifest travels in carries it as a byte string.

Structs§

ChunkInfo
One chunk of a manifest.
Manifest
A chunked content’s manifest. name is bytes, as the wire carries it, and hash_algorithm the wire’s own text: a manifest read from a peer may name anything, and verify_mcid refuses what is not a UTF-8 name and sha384.

Enums§

ManifestError
Why a manifest was refused.

Constants§

DEFAULT_CHUNK_SIZE
256 KiB, macula_manifest’s default chunk size.
HASH_SIZE
A SHA-384 digest’s length.
SHA384
The one hash algorithm a manifest names.

Functions§

block_mcid
The content id of a single block: <<2, 0x55, SHA-384(data)>>.
check_chunk_hashes
Checks that m’s chunk hashes make its root hash. The root hash is part of the content id and the chunk hashes are not, so after verify_mcid this is what ties each chunk, fetched by its hash, to the content id.
check_whole
Checks that m’s chunks describe its content whole, cut as create cuts it: a positive chunk size, ceil(size / chunk size) chunks, which is its chunk count, chunk i at offset i × chunk size and chunk size long but for the last, which holds what is left, between 1 and chunk size bytes.
chunk_mcid
The content id chunk index is stored and fetched under: the block id of its bytes, which a sharer derives from the manifest alone.
create
Splits data into chunks of chunk_size bytes and builds its manifest, created now; returns it with the chunks in order.
create_at
create with the manifest’s creation time given, in unix seconds.
from_wire
A manifest read from its wire form, as macula_manifest’s from_wire/1 reads it. One that names another hash algorithm than sha384 (as text or bytes), whose chunks do not describe its content whole, or holding a number outside its field, is refused. Nothing is allocated from the size or count it claims: only the chunks it lists are read.
mcid_for
The content id the manifest’s canonical fields describe: its name, size, chunk size and count, hash algorithm and root hash. Its creation time and chunk list are not part of it.
mcid_is_chunked
Whether a content id names a manifest (chunked content) rather than a single block, read from its codec byte.
to_wire
The manifest as it travels: the name as a byte string.
verify
Checks reassembled data against m: its size, then a root hash over data cut the same way.
verify_mcid
Whether m describes mcid, as macula_manifest’s verify_mcid/2 checks: a UTF-8 name, sha384, and the content id its canonical fields recompute to. The manifest’s own mcid field is not consulted.

Type Aliases§

Hash
A SHA-384 digest.
Mcid
A content id: <<Tag:8, Codec:8, Hash:48/binary>>.