diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-11-21 11:13:15 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-11-21 11:15:24 +0100 |
commit | a4d045b0a8d6548be58b3b8abb3509429758c89d (patch) | |
tree | be7d00ca101f9b2f758490342b68bf40d26e7efa /rtemsspec | |
parent | 3ae44e02ef4aae4ce06aa4b64015f943ef91628c (diff) |
util: Add base64_to_hex()
Diffstat (limited to 'rtemsspec')
-rw-r--r-- | rtemsspec/tests/test_util.py | 8 | ||||
-rw-r--r-- | rtemsspec/util.py | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/rtemsspec/tests/test_util.py b/rtemsspec/tests/test_util.py index 0873dc5e..35d484d0 100644 --- a/rtemsspec/tests/test_util.py +++ b/rtemsspec/tests/test_util.py @@ -27,8 +27,8 @@ import os import logging -from rtemsspec.util import copy_files, create_argument_parser, init_logging, \ - load_config, run_command +from rtemsspec.util import copy_files, create_argument_parser, base64_to_hex, \ + init_logging, load_config, run_command from rtemsspec.tests.util import get_and_clear_log @@ -41,6 +41,10 @@ def test_copy_files(tmpdir): assert os.path.exists(os.path.join(tmpdir, filename)) +def test_base64_to_hex(): + assert base64_to_hex("ABCD") == "001083" + + def test_load_config(): filename = os.path.join(os.path.dirname(__file__), "config", "a.yml") config = load_config(filename) diff --git a/rtemsspec/util.py b/rtemsspec/util.py index 41127031..851a7a25 100644 --- a/rtemsspec/util.py +++ b/rtemsspec/util.py @@ -25,6 +25,8 @@ # POSSIBILITY OF SUCH DAMAGE. import argparse +import base64 +import binascii import logging import os import shutil @@ -33,6 +35,12 @@ from typing import Any, List, Optional import yaml +def base64_to_hex(data: str) -> str: + """ Converts the data from base64 to hex. """ + binary = base64.urlsafe_b64decode(data) + return binascii.hexlify(binary).decode('ascii') + + def copy_files(src_dir: str, dst_dir: str, files: List[str]) -> None: """ Copies a list of files in the source directory to the destination |