{"action":"opened","issue":{"url":"https://api.github.com/repos/multiformats/rust-multihash/issues/25","repository_url":"https://api.github.com/repos/multiformats/rust-multihash","labels_url":"https://api.github.com/repos/multiformats/rust-multihash/issues/25/labels{/name}","comments_url":"https://api.github.com/repos/multiformats/rust-multihash/issues/25/comments","events_url":"https://api.github.com/repos/multiformats/rust-multihash/issues/25/events","html_url":"https://github.com/multiformats/rust-multihash/issues/25","id":294934920,"number":25,"title":"No way to `encode` a digest directly?","user":{"login":"leavehouse","id":31998645,"avatar_url":"https://avatars0.githubusercontent.com/u/31998645?v=4","gravatar_id":"","url":"https://api.github.com/users/leavehouse","html_url":"https://github.com/leavehouse","followers_url":"https://api.github.com/users/leavehouse/followers","following_url":"https://api.github.com/users/leavehouse/following{/other_user}","gists_url":"https://api.github.com/users/leavehouse/gists{/gist_id}","starred_url":"https://api.github.com/users/leavehouse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leavehouse/subscriptions","organizations_url":"https://api.github.com/users/leavehouse/orgs","repos_url":"https://api.github.com/users/leavehouse/repos","events_url":"https://api.github.com/users/leavehouse/events{/privacy}","received_events_url":"https://api.github.com/users/leavehouse/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-06T22:24:04Z","updated_at":"2018-02-06T22:24:04Z","closed_at":null,"author_association":"NONE","body":"# Problem\r\n\r\nIf you have a hash digest `digest: &[u8]` and you want to `encode` that into multihash bytes, you're out of luck if you're using `rust-multihash` currently. This is because `encode` expects un-hashed data as input. Instead, you must do something like this manually:\r\n\r\n```\r\n    let hash_alg = multihash::Hash::SHA1; \r\n    let mut mh = Vec::with_capacity(digest.len() + 2); \r\n    mh.push(hash_alg.code()); \r\n    mh.push(hash_alg.size()); \r\n    mh.extend_from_slice(digest); \r\n```\r\n\r\nIn contrast, `go-multihash`'s `Encode` function does not hash your data for you, so you can directly pass in a digest.\r\n\r\n# Potential solutions\r\n\r\nThis could be remedied with a new encoding function that expects a hash digest, maybe something named `encode_digest`? However, perhaps we should consider changing the way `encode` works. It would be a breaking change, but it would bring it in-line with how go-multihash works."}}
{"actor":{"display_login":"leavehouse"}}