summaryrefslogtreecommitdiff
path: root/tools/libdol2asm/sha1.py
blob: 44fddaf202e2e431b9e313b04b8ae8f636c4435c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import hashlib

class SHA1MatchException(Exception):
    ...


def sha1_check(path, data, expected):
    """
    Check if the SHA1 checksum of the 'data' is equal to the 'expected' checksum.
    If the checksum does not match, an exception is raised.
    """

    sha1 = hashlib.sha1()
    sha1.update(data)

    current = sha1.hexdigest().upper()
    if current != expected:
        raise SHA1MatchException(f"SHA1 checksum is not matching for '{path}'.\n'{current}'\n'{expected}'")