Skip to content
Snippets Groups Projects

#273 : 0.7.4 regexp

Merged #273 : 0.7.4 regexp
2 unresolved threads
Merged matograine requested to merge 0.7.4-regexp into 0.7_poetry_ci_cd
2 unresolved threads
Files
4
+ 14
6
@@ -19,7 +19,7 @@ from silkaj.tools import message_exit
@@ -19,7 +19,7 @@ from silkaj.tools import message_exit
from click import command, option, pass_context, confirm
from click import command, option, pass_context, confirm
from getpass import getpass
from getpass import getpass
from pathlib import Path
from pathlib import Path
from re import compile, search
from re import compile, search, MULTILINE
from duniterpy.key import SigningKey
from duniterpy.key import SigningKey
from duniterpy.key.scrypt_params import ScryptParams
from duniterpy.key.scrypt_params import ScryptParams
@@ -60,20 +60,28 @@ def generate_auth_file(file):
@@ -60,20 +60,28 @@ def generate_auth_file(file):
@pass_context
@pass_context
def auth_by_auth_file(ctx):
def auth_by_auth_file(ctx):
 
"""
 
Uses an auth file to generate key.
 
Authfile can be either:
 
* Seed in hexadecimal encoding
 
* PubSec format with public and private key in base58 encoding.
 
"""
file = ctx.obj["AUTH_FILE_PATH"]
file = ctx.obj["AUTH_FILE_PATH"]
authfile = Path(file)
authfile = Path(file)
if not authfile.is_file():
if not authfile.is_file():
message_exit('Error: the file "' + file + '" does not exist')
message_exit('Error: the file "' + file + '" does not exist')
filetxt = authfile.open("r").read()
filetxt = authfile.open("r").read()
 
# regex for seed (hexadecimal)
regex_seed = compile("^[0-9a-fA-F]{64}$")
regex_seed = compile("^[0-9a-fA-F]{64}$")
regex_gannonce = compile(
# two RE for PubSec format
"^pub: [1-9A-HJ-NP-Za-km-z]{43,44}\nsec: [1-9A-HJ-NP-Za-km-z]{88,90}.*$"
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)
 
# Seed Format
# Seed Format
if search(regex_seed, filetxt):
if search(regex_seed, filetxt):
return SigningKey.from_seedhex_file(file)
return SigningKey.from_seedhex_file(file)
# gannonce.duniter.org Format
# PubSec format
elif search(regex_gannonce, filetxt):
elif search(regex_pubkey, filetxt) and search(regex_signkey, filetxt):
return SigningKey.from_pubsec_file(file)
return SigningKey.from_pubsec_file(file)
else:
else:
message_exit("Error: the format of the file is invalid")
message_exit("Error: the format of the file is invalid")
Loading