From e680f010a9469f080a3f4d2559b390d899175741 Mon Sep 17 00:00:00 2001 From: lungsangg Date: Tue, 3 Dec 2024 11:23:13 +0530 Subject: [PATCH] updated_decoder --- decoder.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/decoder.py b/decoder.py index 2adb6f0634..4e7f54f99d 100644 --- a/decoder.py +++ b/decoder.py @@ -4,24 +4,26 @@ def add_base64_padding(base64_string): """Add padding to the Base64 string if necessary.""" - missing_padding = len(base64_string) % 4 - if missing_padding: - base64_string += '=' * (4 - missing_padding) + if base64_string: + missing_padding = len(base64_string) % 4 + if missing_padding: + base64_string += '=' * (4 - missing_padding) return base64_string # Retrieve the base64 encoded private key from the environment variable encoded_key = os.getenv('private_key') if encoded_key is None: - raise ValueError("Environment variable 'PRIVATE_KEY_BASE64' is not set.") + print("Environment variable 'private_key' is not set. Skipping key decoding process.") +else: + # Add padding to the encoded key + encoded_key = add_base64_padding(encoded_key) -# Add padding to the encoded key -encoded_key = add_base64_padding(encoded_key) - -# Decode the private key -try: - private_key = base64.b64decode(encoded_key) -except binascii.Error as e: - raise ValueError(f"Failed to decode Base64 string: {e}") - -private_key_1 = private_key.replace(b'\\n', b'\n') \ No newline at end of file + # Decode the private key + try: + private_key = base64.b64decode(encoded_key) + # Replace escaped newlines with actual newlines + private_key_1 = private_key.replace(b'\\n', b'\n') + print("Private key decoded successfully.") + except binascii.Error as e: + raise ValueError(f"Failed to decode Base64 string: {e}")