GithubHelp home page GithubHelp logo

Comments (4)

bochaco avatar bochaco commented on June 17, 2024

I just tried to start using this crate and was having issues when decoding a CID, and I just figured the problem is exactly this, the multihash::encode is hashing my string rather than just prefixing it with hash-code and length, which I thought is what multihash specs defines, at least that's what I understood and saw happening with other implementations like JS that I've been using before, and I looked at Go impl which does the same, i.e. only encoding and no hashing.

from rust-multihash.

dignifiedquire avatar dignifiedquire commented on June 17, 2024

I think you are right, having the hashing functions in here makes life much harder than necessary. I think having the following in this crate makes more sense

/// Owned hash.
pub struct Multihash(Hash, Vec<u8>);

/// Referenced version, more similar to what we have currently
pub struct MultihashRef<'a>(Hash, &'a [u8]);

With an api like this

use multihash::{Multihash, MultihashRef, HashTyp};

let hash: Vec<u8> = blake2b("hello world").into();
let mh = Multihash::new(HashTyp::Blake2b, hash).expect("invalid hash size");
let mh_ref = multihash::MultihashRef::new(HashTyp::Blake2b, &hash).expect("invalid hash size");

// Concats the code for the multihash prefix with the actual hash bytes
let mh_bytes: Vec<u8> = mh.to_vec();

from rust-multihash.

dignifiedquire avatar dignifiedquire commented on June 17, 2024

Thinking about it some more, most of the code in #30 is good, as the new Multihash and MultihashRef in there are mostly working like what I described above. I think a future step is just splitting the encoding functionality either into its own crate or behind a feature flag.

from rust-multihash.

vmx avatar vmx commented on June 17, 2024

With the introduction of multihash:wrap() the create can do both, hashing and multihash encoding.

If it turns out to be a problem, we could split it into two crates. But for now I'll keep it a single one, hence closing this issue.

from rust-multihash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.