Moves (and renames) check_user_pk to common so cli can use it too. Fixes the regex so it only accepts {02, 03} as prefix

This commit is contained in:
Sergi Delgado Segura
2020-03-30 12:44:48 +02:00
parent e924b57efc
commit 33966e59e1
2 changed files with 16 additions and 18 deletions

View File

@@ -1,10 +1,23 @@
import re
import os
import logging
from pathlib import Path
from common.constants import LOCATOR_LEN_HEX
def check_compressed_pk_format(compressed_pk):
"""
Checks if a given value is a 33-byte hex encoded string.
Args:
compressed_pk(:obj:`str`): the value to be checked.
Returns:
:obj:`bool`: Whether or not the value matches the format.
"""
return isinstance(compressed_pk, str) and re.match(r"^0[2-3][0-9A-Fa-f]{64}$", compressed_pk) is not None
def check_sha256_hex_format(value):
"""
Checks if a given value is a 32-byte hex encoded string.