library Bytes32Library {
    /**
     * Converts a bytes32 data structure into a bytes array.
     *
     * @param  data       Piece of data encoded as bytes32
     * @return bytes
     */
    function bytes32ToBytes(bytes32 data)
        internal
        pure
        returns (bytes memory)
    {
        uint256 i = 0;
        while (i < 32 && uint256(bytes32(data[i])) != 0) {
            ++i;
        }
        bytes memory result = new bytes(i);
        i = 0;
        while (i < 32 && data[i] != 0) {
            result[i] = data[i];
            ++i;
        }
        return result;
    }

    /**
     * Converts a piece of data encoded as bytes32 into a string.
     *
     * @param  data       Piece of data encoded as bytes32
     * @return string
     */
    function bytes32ToString(bytes32 data)
        internal
        pure
        returns (string memory)
    {
        bytes memory intermediate = bytes32ToBytes(data);
        return string(abi.encodePacked(intermediate));
    }
}
function bytes32ToBytes(bytes32 data)
        internal
        pure
        returns (bytes memory)
    {
        uint256 i = 0;
        while (i < 32 && uint256(bytes32(data[i])) != 0) {
            ++i;
        }
        bytes memory result = new bytes(i);
        i = 0;
        while (i < 32 && data[i] != 0) {
            result[i] = data[i];
            ++i;
        }
        return result;
    }
/**
 * Converts a bytes32 data structure into a bytes array.
 *
 * @param  data       Piece of data encoded as bytes32
 * @return bytes
 */