[][src]Enum iprs::cid::Cid

pub enum Cid {
    Zero(Multihash),
    One(BaseMulticodecMultihash),
}

Content Identifier.

Variants

Zero(Multihash)

Cid version ZERO. Actually this is legacy. In the distant future, we may remove this support after sha2 breaks.

Cid version ONE.

Implementations

impl Cid[src]

pub fn new_v0(data: &[u8]) -> Result<Cid>[src]

Create a new Cid in Version-0 format from data. Here data shall be encoded in Multihash specification using SHA2-256 cryptographic hash algorithm.

  • multibase, base58btc is implied.
  • multicodec, dag-pb is implied.
  • cid-version, cidv0 is implied.
  • multihash is SHA2_256 computed from data.

Refer to CIDv0 spec for details

pub fn new_v1(base: Base, codec: Multicodec, data: &[u8]) -> Result<Cid>[src]

Create a new Cid in Version-1 format from data.

cidv1 ::= multibase-prefix + multicodec-cidv1 + codec + multihash

  • base, describes base-encoding to be used for this Cid.
  • codec, describes multicodec-content-type of the data.
  • multihash, is SHA2_256 computed from data.

Refer to CIDv1 spec for details

pub fn into_v1(self) -> Self[src]

Transform into v1 addressing.

pub fn from_peer_id_v0(peer_id: PeerId) -> Self[src]

Create a Cid-v0 from peer-id.

pub fn from_peer_id_v1(base: Base, peer_id: PeerId) -> Self[src]

Create a Cid-v1 from peer-id. codec value is implied as LIBP2P_KEY.

pub fn from_text(text: &str) -> Result<Cid>[src]

Decode a base encoded CID, human readable text. CID format can either be in legacy (v0) format or CIDv1 format.

pub fn to_base_text(&self) -> Result<String>[src]

Encode in base format.

  • If value is a CIDv0 variant, encoded into legacy base58btc format.
  • If value is a CIDv1 variant, encoded using specified base format.

pub fn decode(bytes: &[u8]) -> Result<Cid>[src]

Decode a binary encoded CID. Refer to Self::encode method for details. Supports both legacy-format and CIDv1-format.

pub fn encode(&self) -> Result<Vec<u8>>[src]

Encode to binary format.

If value is a CIDv0 variant:

  • Encoded as binary multi-hash format. The resulting bytes start with [0x12, 0x20, ...]

If value is a CIDv1 variant:

  • CID-version byte
  • codec, unsigned_varint multicodec value, describing multicodec-content-type or format of the data being addressed
  • multihash, is SHA2-256 of data in Multihash format.

pub fn to_version(&self) -> Version[src]

Return CID version.

pub fn to_base(&self) -> Base[src]

Return the base encoding used for this CID.

pub fn to_content_type(&self) -> Multicodec[src]

Return the content type or format of the data being addressed.

pub fn to_multihash(&self) -> Multihash

Notable traits for Multihash

impl Write for Multihash
[src]

Return hash digest, typically encoded with SHA2-256, in which case it must be a 32-byte vector.

pub fn to_peer_id(&self) -> Option<PeerId>[src]

If CID is pointing to a peer-id, that is if the codec is LIBP2P_KEY, return the PeerId value.

Trait Implementations

impl Clone for Cid[src]

impl Debug for Cid[src]

impl Display for Cid[src]

impl Eq for Cid[src]

impl FromStr for Cid[src]

type Err = Error

The associated error which can be returned from parsing.

impl PartialEq<Cid> for Cid[src]

impl StructuralEq for Cid[src]

impl StructuralPartialEq for Cid[src]

Auto Trait Implementations

impl RefUnwindSafe for Cid

impl Send for Cid

impl Sync for Cid

impl Unpin for Cid

impl UnwindSafe for Cid

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,