{"action":"created","issue":{"url":"https://api.github.com/repos/jbenet/multihash/issues/16","labels_url":"https://api.github.com/repos/jbenet/multihash/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/jbenet/multihash/issues/16/comments","events_url":"https://api.github.com/repos/jbenet/multihash/issues/16/events","html_url":"https://github.com/jbenet/multihash/issues/16","id":111928068,"number":16,"title":"RFC: How should a digest_size > hash function's output be handled?","user":{"login":"moreati","id":174450,"avatar_url":"https://avatars.githubusercontent.com/u/174450?v=3","gravatar_id":"","url":"https://api.github.com/users/moreati","html_url":"https://github.com/moreati","followers_url":"https://api.github.com/users/moreati/followers","following_url":"https://api.github.com/users/moreati/following{/other_user}","gists_url":"https://api.github.com/users/moreati/gists{/gist_id}","starred_url":"https://api.github.com/users/moreati/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moreati/subscriptions","organizations_url":"https://api.github.com/users/moreati/orgs","repos_url":"https://api.github.com/users/moreati/repos","events_url":"https://api.github.com/users/moreati/events{/privacy}","received_events_url":"https://api.github.com/users/moreati/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-10-16T23:14:37Z","updated_at":"2015-11-20T10:14:01Z","closed_at":null,"body":"How should a multihash implementation handle a call where the digest is longer than the specified output of that hash function? E.g. (pseudocode) \r\n\r\n```javascript\r\n// The provided digest is 26 bytes long,\r\n// but SHA1 can't produce a digest longer than 20 bytes\r\nmh = multihash.encode(digest='abcdefghijklmnopqrstuvwxyz', code=Codes['sha1'])\r\n```\r\n\r\nConversely, is the following multihash valid? (hex encoded, spaces added for legibility)\r\n\r\n    11 1a 6162636465666768696a6b6c6d6e6f707172737475767778797a\r\n\r\nThe code field declares the hash function is SHA-1 (0x11). The length field declares the digest is 26 bytes long, and the received digest field *is* 26 bytes long. However SHA-1 can't produce 26-byte digest.\r\n\r\nWhen a multihash library is called to encode/decode such an input it could:\r\n\r\na. Signal an error, and stop encoding/decoding?\r\nb. Set the length field to len(digest), then continue with processing?\r\nc. Truncate the digest field, before continuing with processing?\r\n\r\nThe behaviour is currently unspecified, i.e. implementations can do whatever they want. AFAICT go-multihash does b. I'd like to propose that a. as a required behaviour for standards conforming implementations.\r\n\r\nWhat do you think? Have I missed a specification document? Would you prefer I sent this to a mailing list (e.g. ipfs-users)?"},"comment":{"url":"https://api.github.com/repos/jbenet/multihash/issues/comments/158347925","html_url":"https://github.com/jbenet/multihash/issues/16#issuecomment-158347925","issue_url":"https://api.github.com/repos/jbenet/multihash/issues/16","id":158347925,"user":{"login":"candeira","id":91694,"avatar_url":"https://avatars.githubusercontent.com/u/91694?v=3","gravatar_id":"","url":"https://api.github.com/users/candeira","html_url":"https://github.com/candeira","followers_url":"https://api.github.com/users/candeira/followers","following_url":"https://api.github.com/users/candeira/following{/other_user}","gists_url":"https://api.github.com/users/candeira/gists{/gist_id}","starred_url":"https://api.github.com/users/candeira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/candeira/subscriptions","organizations_url":"https://api.github.com/users/candeira/orgs","repos_url":"https://api.github.com/users/candeira/repos","events_url":"https://api.github.com/users/candeira/events{/privacy}","received_events_url":"https://api.github.com/users/candeira/received_events","type":"User","site_admin":false},"created_at":"2015-11-20T10:14:01Z","updated_at":"2015-11-20T10:14:01Z","body":"@jbenet But you can only do that when you have the blob (in this case, \"foobar\"), so it's useless for, for instance, doing Kademlia comparisons when looking for the content corresponding to a sha1 multihash."}}