mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-26 15:30:18 +00:00
refactor(main): Reduce complexity of main function
This will make it easier for us to maintain and understand the main function. Also deleting duplicated code Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com>
This commit is contained in:
parent
8d1a000378
commit
87ff1808a2
@ -58,6 +58,27 @@ def spin(until=None, msg="", timeout=None):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_keys(args: argparse.Namespace, identity) -> None:
|
||||||
|
"""Get public or/and private keys"""
|
||||||
|
|
||||||
|
if args.base64:
|
||||||
|
RNS.log("Public Key : " + base64.urlsafe_b64encode(identity.get_public_key()).decode("utf-8"))
|
||||||
|
elif args.base32:
|
||||||
|
RNS.log("Public Key : " + base64.b32encode(identity.get_public_key()).decode("utf-8"))
|
||||||
|
else:
|
||||||
|
RNS.log("Public Key : " + RNS.hexrep(identity.get_public_key(), delimit=False))
|
||||||
|
if identity.prv:
|
||||||
|
if args.print_private:
|
||||||
|
if args.base64:
|
||||||
|
RNS.log("Private Key : " + base64.urlsafe_b64encode(identity.get_private_key()).decode("utf-8"))
|
||||||
|
elif args.base32:
|
||||||
|
RNS.log("Private Key : " + base64.b32encode(identity.get_private_key()).decode("utf-8"))
|
||||||
|
else:
|
||||||
|
RNS.log("Private Key : " + RNS.hexrep(identity.get_private_key(), delimit=False))
|
||||||
|
else:
|
||||||
|
RNS.log("Private Key : Hidden")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
parser = argparse.ArgumentParser(description="Reticulum Identity & Encryption Utility")
|
parser = argparse.ArgumentParser(description="Reticulum Identity & Encryption Utility")
|
||||||
@ -131,22 +152,8 @@ def main():
|
|||||||
exit(42)
|
exit(42)
|
||||||
|
|
||||||
RNS.log("Identity imported")
|
RNS.log("Identity imported")
|
||||||
if args.base64:
|
|
||||||
RNS.log("Public Key : "+base64.urlsafe_b64encode(identity.get_public_key()).decode("utf-8"))
|
get_keys(args, identity)
|
||||||
elif args.base32:
|
|
||||||
RNS.log("Public Key : "+base64.b32encode(identity.get_public_key()).decode("utf-8"))
|
|
||||||
else:
|
|
||||||
RNS.log("Public Key : "+RNS.hexrep(identity.get_public_key(), delimit=False))
|
|
||||||
if identity.prv:
|
|
||||||
if args.print_private:
|
|
||||||
if args.base64:
|
|
||||||
RNS.log("Private Key : "+base64.urlsafe_b64encode(identity.get_private_key()).decode("utf-8"))
|
|
||||||
elif args.base32:
|
|
||||||
RNS.log("Private Key : "+base64.b32encode(identity.get_private_key()).decode("utf-8"))
|
|
||||||
else:
|
|
||||||
RNS.log("Private Key : "+RNS.hexrep(identity.get_private_key(), delimit=False))
|
|
||||||
else:
|
|
||||||
RNS.log("Private Key : Hidden")
|
|
||||||
|
|
||||||
if args.write:
|
if args.write:
|
||||||
try:
|
try:
|
||||||
@ -298,22 +305,7 @@ def main():
|
|||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
if args.print_identity:
|
if args.print_identity:
|
||||||
if args.base64:
|
get_keys(args, identity)
|
||||||
RNS.log("Public Key : "+base64.urlsafe_b64encode(identity.get_public_key()).decode("utf-8"))
|
|
||||||
elif args.base32:
|
|
||||||
RNS.log("Public Key : "+base64.b32encode(identity.get_public_key()).decode("utf-8"))
|
|
||||||
else:
|
|
||||||
RNS.log("Public Key : "+RNS.hexrep(identity.get_public_key(), delimit=False))
|
|
||||||
if identity.prv:
|
|
||||||
if args.print_private:
|
|
||||||
if args.base64:
|
|
||||||
RNS.log("Private Key : "+base64.urlsafe_b64encode(identity.get_private_key()).decode("utf-8"))
|
|
||||||
elif args.base32:
|
|
||||||
RNS.log("Private Key : "+base64.b32encode(identity.get_private_key()).decode("utf-8"))
|
|
||||||
else:
|
|
||||||
RNS.log("Private Key : "+RNS.hexrep(identity.get_private_key(), delimit=False))
|
|
||||||
else:
|
|
||||||
RNS.log("Private Key : Hidden")
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
if args.export:
|
if args.export:
|
||||||
|
Loading…
Reference in New Issue
Block a user