import struct


def parse_bip32_path(path):
    """
    parse derivation path as a array of unsigned 32bit ints, hardening specified as '
    :param path: path to parse
    :return: parsed path and depth tuple
    """
    result = b''
    elements = path.split('/')
    for pathElement in elements:
        element = pathElement.split('\'')
        # little endian! why Ledger used big endian and converted in main.c???
        if len(element) == 1:
            result = result + struct.pack("<I", int(element[0]))
        else:
            result = result + struct.pack("<I", 0x80000000 | int(element[0]))
    return result, len(elements)