pub struct RawContentId(/* private fields */);Expand description
The identity of an opaque byte string: a CIDv1 whose codec is raw
(0x55) and whose multihash is BLAKE3-256 (0x1e) over the bytes.
See the module docs for the two-profile picture and why the codec
is part of the identity. Construct with
from_content (hash bytes you hold) or
from_blake3_digest (wrap a digest you already
have, no re-hash); parse with FromStr / from_bytes /
TryFrom<Cid>.
Implementations§
Source§impl RawContentId
impl RawContentId
Sourcepub fn from_content(content: &[u8]) -> Self
pub fn from_content(content: &[u8]) -> Self
The identity of content: CIDv1(raw, BLAKE3(content)).
This is the door for bytes you hold. There is no canonicalization step
and nothing to get wrong: the bytes are the content, so the id names
exactly what was hashed. (Contrast ContentId::from_canonical_bytes,
whose “MUST be canonical dag-cbor” precondition exists because a
dag-cbor id names a value, not the bytes.)
Named from_content rather than from_bytes on purpose: across both
profiles from_bytes/to_bytes always mean the CID binary envelope
(the presentation contract), never “hash these bytes”.
Sourcepub fn from_blake3_digest(digest: [u8; 32]) -> Self
pub fn from_blake3_digest(digest: [u8; 32]) -> Self
Wrap a precomputed 32-byte BLAKE3 digest of some content as a
RawContentId, with no re-hash.
This is the honest home of the “no-rehash bridge”: a system that already
hashed content with BLAKE3 (kyln-lore revision signatures, a bare
blake3::hash, a blake3:<hex> digest) gets a byte-identical
RawContentId by wrapping — and the raw codec tells the truth about
what was hashed (opaque bytes). This replaces the deprecated
ContentId::from_blake3_content_digest, which stamped dag-cbor on a
digest it could not know came from dag-cbor.
The digest must really be BLAKE3 over the content you mean. This
function cannot check that; a wrong digest mints an id that names
nothing anyone hashed. Verify against real bytes with
verify when you can.
§Panics
Does not panic: a 32-byte digest always fits the multihash’s 64-byte capacity.
Sourcepub fn verify(&self, content: &[u8]) -> bool
pub fn verify(&self, content: &[u8]) -> bool
true iff content hashes to this id.
Infallible: a mismatch is false, never an error (the same contract as
ContentAddressable::verify).
Sourcepub fn digest_bytes(&self) -> [u8; 32]
pub fn digest_bytes(&self) -> [u8; 32]
The raw 32-byte BLAKE3 digest, copied out of the multihash. Total: every ingress path validated the profile.
Sourcepub fn digest_hex(&self) -> String
pub fn digest_hex(&self) -> String
Lowercase hex of the raw 32-byte digest: 64 chars, no prefix, no
envelope — the “bare-digest-hex” presentation form. Note that this is
identical for RawContentId(x) and ContentId(x) when the digests
match; it is a digest accessor, not an identity, and must never be
compared as one (law 6).
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
The full CID binary envelope (version + codec + multihash + digest).
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, ContentError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, ContentError>
Parse an id from its CID binary form, accepting only the raw profile.
§Errors
ContentError::InvalidCid if the bytes are not a CID at all;
ContentError::InvalidCidProfile if they are a CID of any other profile
(including a dag-cbor ContentId).
Trait Implementations§
Source§impl Clone for RawContentId
impl Clone for RawContentId
impl Copy for RawContentId
Source§impl Debug for RawContentId
impl Debug for RawContentId
Source§impl<'de> Deserialize<'de> for RawContentId
impl<'de> Deserialize<'de> for RawContentId
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Inverse of Serialize; a link of any other profile is rejected at the
boundary, never later in an accessor.
Source§impl Display for RawContentId
impl Display for RawContentId
impl Eq for RawContentId
Source§impl From<RawContentId> for ClassifiedCid
impl From<RawContentId> for ClassifiedCid
Source§fn from(id: RawContentId) -> Self
fn from(id: RawContentId) -> Self
Source§impl From<RawContentId> for Cid
impl From<RawContentId> for Cid
Source§fn from(id: RawContentId) -> Self
fn from(id: RawContentId) -> Self
Source§impl FromStr for RawContentId
impl FromStr for RawContentId
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parse a multibase CID string, accepting only the raw profile. As with
ContentId, base32-lower is the contract; other multibases are a
convenience of the inner parser, not a promise. Legacy dialects (kyln
envelope-hex, blake3:<hex>, bare digest hex) are deliberately not
accepted here — they live behind the explicit legacy adapters.