How to use the imgtool.image.VerifyResult function in imgtool

To help you get started, we’ve selected a few imgtool examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JuulLabs-OSS / mcuboot / scripts / imgtool / main.py View on Github external
def verify(key, imgfile):
    key = load_key(key) if key else None
    ret, version = image.Image.verify(imgfile, key)
    if ret == image.VerifyResult.OK:
        print("Image was correctly validated")
        print("Image version: {}.{}.{}+{}".format(*version))
        return
    elif ret == image.VerifyResult.INVALID_MAGIC:
        print("Invalid image magic; is this an MCUboot image?")
    elif ret == image.VerifyResult.INVALID_TLV_INFO_MAGIC:
        print("Invalid TLV info magic; is this an MCUboot image?")
    elif ret == image.VerifyResult.INVALID_HASH:
        print("Image has an invalid sha256 digest")
    elif ret == image.VerifyResult.INVALID_SIGNATURE:
        print("No signature found for the given key")
    else:
        print("Unknown return code: {}".format(ret))
    sys.exit(1)
github NordicPlayground / fw-nrfconnect-nrf / scripts / hid_configurator / configurator_core.py View on Github external
def is_dfu_image_correct(dfu_image):
    if not os.path.isfile(dfu_image):
        print('DFU image file does not exists')
        return False

    img_length = os.stat(dfu_image).st_size

    if img_length <= 0:
        print('DFU image is empty')
        return False

    print('DFU image size: {} bytes'.format(img_length))

    res, _ = img.Image.verify(dfu_image, None)

    if res != img.VerifyResult.OK:
        print('DFU image is invalid')
        return False

    return True