Skip to content
Snippets Groups Projects
Commit cf522e26 authored by Moul's avatar Moul
Browse files

[mod] #160: Define functions in examples

The function names are based on the files' names
Pylint: Use unused variables
Allow to pass files path in f() prompt as arg
- Reduce usage message
- Add missing exits
parent d0d74e92
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ ENCRYPTED_MESSAGE_FILENAME = "/tmp/duniter_encrypted_message.bin" ...@@ -23,7 +23,7 @@ ENCRYPTED_MESSAGE_FILENAME = "/tmp/duniter_encrypted_message.bin"
################################################ ################################################
if __name__ == "__main__": def save_binary_encrypted_message():
# Ask public key of the recipient # Ask public key of the recipient
pubkeyBase58 = input("Enter public key of the message recipient: ") pubkeyBase58 = input("Enter public key of the message recipient: ")
...@@ -39,3 +39,6 @@ if __name__ == "__main__": ...@@ -39,3 +39,6 @@ if __name__ == "__main__":
file_handler.write(encrypted_message) file_handler.write(encrypted_message)
print("Encrypted message saved in file ./{0}".format(ENCRYPTED_MESSAGE_FILENAME)) print("Encrypted message saved in file ./{0}".format(ENCRYPTED_MESSAGE_FILENAME))
if __name__ == "__main__":
save_binary_encrypted_message()
...@@ -27,7 +27,7 @@ SIGNED_MESSAGE_FILENAME = "/tmp/duniter_signed_message.bin" ...@@ -27,7 +27,7 @@ SIGNED_MESSAGE_FILENAME = "/tmp/duniter_signed_message.bin"
################################################ ################################################
if __name__ == "__main__": def save_binary_signed_message():
# prompt hidden user entry # prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ") salt = getpass.getpass("Enter your passphrase (salt): ")
...@@ -50,9 +50,14 @@ if __name__ == "__main__": ...@@ -50,9 +50,14 @@ if __name__ == "__main__":
veri = libnacl.sign.Verifier(key.hex_vk()) veri = libnacl.sign.Verifier(key.hex_vk())
# Verify the message! # Verify the message!
verified = veri.verify(signed_message) verified = veri.verify(signed_message)
print(f"Message verified: {verified}")
# save signed message in a file # save signed message in a file
with open(SIGNED_MESSAGE_FILENAME, "wb") as file_handler: with open(SIGNED_MESSAGE_FILENAME, "wb") as file_handler:
file_handler.write(signed_message) file_handler.write(signed_message)
print("Signed message saved in file ./{0}".format(SIGNED_MESSAGE_FILENAME)) print("Signed message saved in file ./{0}".format(SIGNED_MESSAGE_FILENAME))
if __name__ == "__main__":
save_binary_signed_message()
...@@ -28,7 +28,7 @@ CLEARTEXT_AA_MESSAGE_PATH = "/tmp/duniter_cleartext_aa_message.txt" ...@@ -28,7 +28,7 @@ CLEARTEXT_AA_MESSAGE_PATH = "/tmp/duniter_cleartext_aa_message.txt"
################################################ ################################################
if __name__ == "__main__": def save_cleartext_ascii_armor_message():
# prompt hidden user entry # prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ") salt = getpass.getpass("Enter your passphrase (salt): ")
...@@ -59,3 +59,6 @@ if __name__ == "__main__": ...@@ -59,3 +59,6 @@ if __name__ == "__main__":
CLEARTEXT_AA_MESSAGE_PATH CLEARTEXT_AA_MESSAGE_PATH
) )
) )
if __name__ == "__main__":
save_cleartext_ascii_armor_message()
...@@ -26,7 +26,7 @@ ENCRYPTED_AA_MESSAGE_PATH = "/tmp/duniter_aa_encrypted_message.txt" ...@@ -26,7 +26,7 @@ ENCRYPTED_AA_MESSAGE_PATH = "/tmp/duniter_aa_encrypted_message.txt"
################################################ ################################################
if __name__ == "__main__": def save_encrypted_ascii_armor_message():
# Ask public key of the recipient # Ask public key of the recipient
pubkeyBase58 = input("Enter public key of the message recipient: ") pubkeyBase58 = input("Enter public key of the message recipient: ")
...@@ -63,3 +63,6 @@ if __name__ == "__main__": ...@@ -63,3 +63,6 @@ if __name__ == "__main__":
ENCRYPTED_AA_MESSAGE_PATH ENCRYPTED_AA_MESSAGE_PATH
) )
) )
if __name__ == "__main__":
save_encrypted_ascii_armor_message()
...@@ -114,7 +114,7 @@ def get_signed_raw_revocation_document( ...@@ -114,7 +114,7 @@ def get_signed_raw_revocation_document(
return revocation.signed_raw() return revocation.signed_raw()
def main(): def save_revoke_document():
""" """
Main code Main code
""" """
...@@ -167,4 +167,4 @@ def main(): ...@@ -167,4 +167,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() save_revoke_document()
...@@ -98,7 +98,7 @@ def get_certification_document( ...@@ -98,7 +98,7 @@ def get_certification_document(
) )
def main(): def send_certification():
""" """
Main code Main code
""" """
...@@ -148,4 +148,4 @@ def main(): ...@@ -148,4 +148,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() send_certification()
...@@ -67,7 +67,7 @@ def get_identity_document( ...@@ -67,7 +67,7 @@ def get_identity_document(
return identity return identity
def main(): def send_identity():
""" """
Main code Main code
""" """
...@@ -105,4 +105,4 @@ def main(): ...@@ -105,4 +105,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() send_identity()
...@@ -74,7 +74,7 @@ def get_membership_document( ...@@ -74,7 +74,7 @@ def get_membership_document(
return membership return membership
def main(): def send_membership():
""" """
Main code Main code
""" """
...@@ -115,4 +115,4 @@ def main(): ...@@ -115,4 +115,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() send_membership()
...@@ -105,7 +105,7 @@ def get_transaction_document( ...@@ -105,7 +105,7 @@ def get_transaction_document(
return transaction return transaction
def main(): def send_transaction():
""" """
Main code Main code
""" """
...@@ -160,4 +160,4 @@ def main(): ...@@ -160,4 +160,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() send_transaction()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment