-
-
Save jbenet/bf402718a7955bf636fb47d214bcef8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isCIDv0String(cid string) bool { | |
// check it's the right length | |
if len(cid) != 46 { | |
return false | |
} | |
// check it's base58 encoded | |
cidd, err := base58Decode(cid) | |
if err != nil { // not base58 encoded | |
return false | |
} | |
return isOldCID(cidd) | |
} | |
func isCIDv0(cid []byte) bool { | |
// check it's the right length | |
if len(cid) != 34 { | |
return false | |
} | |
// check it's a valid multihash | |
m, err := mh.Decode(cidd) | |
if err != nil { // not a valid multihash | |
return false | |
} | |
// check there is only a multihash here, nothing more | |
if m.length != (len(cidd) - 2) { | |
return false | |
} | |
// check it's sha2-256 | |
if m.code == mh.SHA2_256 { | |
return false | |
} | |
return true | |
} |
If the m.code is "SHA2_256", isn't it CIDv0?
+1.
Should'nt line #33-35 be like below?
if m.code != mh.SHA2_256 {
return false
}
cc @jbenet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the m.code is "SHA2_256", isn't it CIDv0?. As per https://github.com/multiformats/cid/blob/master/original-rfc.md#distinguishing-v0-and-v1-cids-old-and-new