erasureprotocol / erasure-protocol

Information wants to be expensive
https://erasure.world/
MIT License
164 stars 27 forks source link

[Post] MultiHashWraper #157

Closed thegostep closed 5 years ago

thegostep commented 5 years ago

Options:

thegostep commented 5 years ago

For the first 3 options, it would be worthwhile to perform input validation by checking the length of the bytes field

thegostep commented 5 years ago

Option 2:


    function _combineMultiHash(MultiHash memory multihash) internal pure returns (bytes memory) {
        return abi.encode(multihash.hashFunction, multihash.digestSize, multihash.hash);
    }

    function _splitMultiHash(bytes memory source) internal pure returns (MultiHash memory) {
        (uint8 hashFunction, uint8 digestSize, bytes32 hash) = abi.decode(source, (uint8,uint8,bytes32));
        return MultiHash(hash, hashFunction, digestSize);
    }
thegostep commented 5 years ago

For now, split using assembly and source length validation