From 03ad790a33a0826a70c1d719e31dd216fd6c4e5d Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Sun, 23 Feb 2020 12:12:27 +0100
Subject: [PATCH] [mod] crypto: Import to-level 're' lib for clarity

- 're.' is not too long
---
 silkaj/auth.py         | 12 ++++++------
 silkaj/crypto_tools.py | 10 +++++-----
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/silkaj/auth.py b/silkaj/auth.py
index befedf54..5d55bb4a 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 58845e41..af8726f5 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(
-- 
GitLab