Skip to main content

Module cid

Module cid 

Source
Expand description

Content identifiers, decoded rather than glanced at.

didbot_schema::format::cid already checks CID strings, and it deliberately does not decode: a client can write any CID into a record and this server dereferences none of them, so the lenient alphabet-and-length rule atproto specifies is the right check at that boundary. This type is for the other direction. To encode a link into DAG-CBOR you need the CID’s bytes, and to know that two links are the same link you need to compare them; neither is answerable from the string.

What atproto permits is a narrow slice of what a CID can be, and all of it is enforced here, because a value this crate cannot re-encode byte for byte is a value it must not accept:

  • version 1. CIDv0 is a valid IPFS identifier, is base58 with no multibase prefix at all, and is not permitted in atproto.
  • the multibase is base32, lowercase, unpadded — the b prefix. Another multibase would decode to the same bytes and print back differently.
  • the multihash is sha-256, 32 bytes.
  • the codec is DAG-CBOR or raw. Everything atproto links to is one or the other: a record or a blob.

Structs§

Cid
A content identifier, held as the bytes it hashes and prints from.
RawHasher
A raw-block CID computed over bytes that arrive a chunk at a time.

Enums§

CidError
Why a string or a byte sequence is not a CID this crate can use.

Constants§

BASE32_PREFIX 🔒
The multibase prefix for lowercase unpadded base32.
DAG_CBOR
The multicodec for DAG-CBOR, which is what a link to a record carries.
DIGEST_LENGTH 🔒
How long a sha-256 digest is.
RAW
The multicodec for raw bytes, which is what a link to a blob carries.
SHA2_256 🔒
The multihash code for sha-256.

Functions§

read_varint 🔒
Reads an unsigned LEB128 varint, advancing input past it.
write_varint 🔒
Appends an unsigned LEB128 varint, the multiformats encoding.