From 745c926d76e9cb4ff65cf1e12e8785e035868bb2 Mon Sep 17 00:00:00 2001 From: LucasVerdelho Date: Tue, 19 Mar 2024 21:58:27 +0000 Subject: [PATCH] Refactored elifs into match case --- TPs/TP05/sig_fich.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/TPs/TP05/sig_fich.py b/TPs/TP05/sig_fich.py index 694b82a..ee23477 100644 --- a/TPs/TP05/sig_fich.py +++ b/TPs/TP05/sig_fich.py @@ -140,23 +140,25 @@ def main(): parser.add_argument("command", choices=["sign", "verify"], help="Command to execute: 'sign' or 'verify'") parser.add_argument("user", help="Username") parser.add_argument("filename", help="File name") + parser.add_argument("--test", action="store_true", help="Perform testing (simulate errors)") args = parser.parse_args() - if args.command == "sign": - if os.path.exists(args.user + ".crt") and os.path.exists(args.user + ".key"): + match args.command: + case "sign" if os.path.exists(args.user + ".crt") and os.path.exists(args.user + ".key"): sign(args.user, args.filename) print("File signed successfully.") - else: + case "sign": print("User certificate or private key not found.") - elif args.command == "verify": - if os.path.exists(args.filename + ".sig"): + case "verify" if os.path.exists(args.filename + ".sig"): verify(args.filename, args.user) - else: + case "verify": print("Signature file not found.") - else: - parser.print_help() - sys.exit(1) + case _: + parser.print_help() + sys.exit(1) + + if __name__ == "__main__": main()