Skip to main content

RawContentId

Struct RawContentId 

Source
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

Source

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”.

Source

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.

Source

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).

Source

pub fn as_cid(&self) -> &Cid

Borrow the underlying IPLD Cid.

Source

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.

Source

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).

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

The full CID binary envelope (version + codec + multihash + digest).

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RawContentId

Source§

impl Debug for RawContentId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RawContentId

Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Multibase base32-lower (b…) — the canonical text form, the inverse of FromStr for that form.

Source§

impl Eq for RawContentId

Source§

impl From<RawContentId> for ClassifiedCid

Source§

fn from(id: RawContentId) -> Self

Converts to this type from the input type.
Source§

impl From<RawContentId> for Cid

Source§

fn from(id: RawContentId) -> Self

Converts to this type from the input type.
Source§

impl FromStr for RawContentId

Source§

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.

Source§

type Err = ContentError

The associated error which can be returned from parsing.
Source§

impl Hash for RawContentId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for RawContentId

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for RawContentId

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for RawContentId

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for RawContentId

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Same shape as ContentId: the base32-lower string in human-readable formats, the inner Cid (a dag-cbor tag-42 link) in binary/IPLD ones.

Source§

impl StructuralPartialEq for RawContentId

Source§

impl TryFrom<Cid<64>> for RawContentId

Source§

fn try_from(cid: Cid) -> Result<Self, Self::Error>

Wrap a Cid iff it is the raw profile; anything else — including a dag-cbor ContentId’s CID — is rejected with ContentError::InvalidCidProfile.

Source§

type Error = ContentError

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.