-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils.py
More file actions
45 lines (35 loc) · 1.27 KB
/
utils.py
File metadata and controls
45 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from pathlib import Path
from typing import List
import re
from secp256k1 import PublicKey
ROOT_SCREENSHOT_PATH = Path(__file__).parent.resolve()
# Check if a signature of a given message is valid
def check_signature_validity(public_key: bytes, signature: bytes, sighash: bytes) -> bool:
pkey = PublicKey(public_key, True)
return pkey.schnorr_verify(sighash, signature, None, True)
def verify_version(version: str) -> None:
"""Verify the app version, based on defines in Makefile
Args:
Version (str): Version to be checked
"""
vers_dict = {}
vers_str = ""
lines = _read_makefile()
version_re = re.compile(r"^APPVERSION_(?P<part>\w)\s?=\s?(?P<val>\d*)", re.I)
for line in lines:
info = version_re.match(line)
if info:
dinfo = info.groupdict()
vers_dict[dinfo["part"]] = dinfo["val"]
try:
vers_str = f"{vers_dict['M']}.{vers_dict['N']}.{vers_dict['P']}"
except KeyError:
pass
assert version == vers_str
def _read_makefile() -> List[str]:
"""Read lines from the parent Makefile """
parent = Path(__file__).parent.parent.resolve()
makefile = f"{parent}/Makefile"
with open(makefile, "r", encoding="utf-8") as f_p:
lines = f_p.readlines()
return lines