diff --git a/silkaj/auth.py b/silkaj/auth.py index befedf544166220f39b2f20e4cb62c5d7199d502..5d55bb4a6877f5a2453f7a2b06bfa60284c70205 100644 --- a/silkaj/auth.py +++ b/silkaj/auth.py @@ -15,11 +15,11 @@ You should have received a copy of the GNU Affero General Public License along with Silkaj. If not, see <https://www.gnu.org/licenses/>. """ +import re from silkaj.tools import message_exit from click import command, option, pass_context, confirm from getpass import getpass from pathlib import Path -from re import compile, search, MULTILINE from duniterpy.key import SigningKey from duniterpy.key.scrypt_params import ScryptParams @@ -72,16 +72,16 @@ def auth_by_auth_file(ctx): message_exit('Error: the file "' + file + '" does not exist') filetxt = authfile.open("r").read() # regex for seed (hexadecimal) - regex_seed = compile("^[0-9a-fA-F]{64}$") + regex_seed = re.compile("^[0-9a-fA-F]{64}$") # two regural expressions for the PubSec format - regex_pubkey = compile("pub: ([1-9A-HJ-NP-Za-km-z]{43,44})", MULTILINE) - regex_signkey = compile("sec: ([1-9A-HJ-NP-Za-km-z]{87,90})", MULTILINE) + regex_pubkey = re.compile("pub: ([1-9A-HJ-NP-Za-km-z]{43,44})", re.MULTILINE) + regex_signkey = re.compile("sec: ([1-9A-HJ-NP-Za-km-z]{87,90})", re.MULTILINE) # Seed format - if search(regex_seed, filetxt): + if re.search(regex_seed, filetxt): return SigningKey.from_seedhex_file(file) # PubSec format - elif search(regex_pubkey, filetxt) and search(regex_signkey, filetxt): + elif re.search(regex_pubkey, filetxt) and re.search(regex_signkey, filetxt): return SigningKey.from_pubsec_file(file) else: message_exit("Error: the format of the file is invalid") diff --git a/silkaj/crypto_tools.py b/silkaj/crypto_tools.py index 58845e41a8bf3d6ce69b5e65e32912a6a36a0ab4..af8726f5e413f7f98303f96c773378f85928da78 100644 --- a/silkaj/crypto_tools.py +++ b/silkaj/crypto_tools.py @@ -15,8 +15,8 @@ You should have received a copy of the GNU Affero General Public License along with Silkaj. If not, see <https://www.gnu.org/licenses/>. """ +import re from nacl import encoding, hash -from re import compile, search def check_public_key(pubkey, display_error): @@ -25,13 +25,13 @@ def check_public_key(pubkey, display_error): Check pubkey checksum which could be append after the pubkey If check pass: return pubkey """ - regex = compile("^[1-9A-HJ-NP-Za-km-z]{43,44}$") - regex_checksum = compile( + regex = re.compile("^[1-9A-HJ-NP-Za-km-z]{43,44}$") + regex_checksum = re.compile( "^[1-9A-HJ-NP-Za-km-z]{43,44}" + "![1-9A-HJ-NP-Za-km-z]{3}$" ) - if search(regex, pubkey): + if re.search(regex, pubkey): return pubkey - elif search(regex_checksum, pubkey): + elif re.search(regex_checksum, pubkey): pubkey, checksum = pubkey.split("!") pubkey_byte = b58_decode(pubkey) checksum_calculed = b58_encode(