mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
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:
@@ -1,5 +1,4 @@
|
||||
import re
|
||||
|
||||
from common.tools import check_compressed_pk_format
|
||||
from common.cryptographer import Cryptographer
|
||||
|
||||
|
||||
@@ -33,20 +32,6 @@ class Gatekeeper:
|
||||
self.default_slots = default_slots
|
||||
self.registered_users = {}
|
||||
|
||||
@staticmethod
|
||||
def check_user_pk(user_pk):
|
||||
"""
|
||||
Checks if a given value is a 33-byte hex encoded string.
|
||||
|
||||
Args:
|
||||
user_pk(:obj:`str`): the value to be checked.
|
||||
|
||||
Returns:
|
||||
:obj:`bool`: Whether or not the value matches the format.
|
||||
"""
|
||||
|
||||
return isinstance(user_pk, str) and re.match(r"^[0-9A-Fa-f]{66}$", user_pk) is not None
|
||||
|
||||
def add_update_user(self, user_pk):
|
||||
"""
|
||||
Adds a new user or updates the subscription of an existing one, by adding additional slots.
|
||||
@@ -58,7 +43,7 @@ class Gatekeeper:
|
||||
:obj:`int`: the number of available slots in the user subscription.
|
||||
"""
|
||||
|
||||
if not self.check_user_pk(user_pk):
|
||||
if not check_compressed_pk_format(user_pk):
|
||||
raise ValueError("provided public key does not match expected format (33-byte hex string)")
|
||||
|
||||
if user_pk not in self.registered_users:
|
||||
|
||||
Reference in New Issue
Block a user