From 9104af98437305e142f58249447237178ca3c523 Mon Sep 17 00:00:00 2001 From: Levent Kaya <42411502+lvntky@users.noreply.github.com> Date: Tue, 15 Jun 2021 02:53:24 +0300 Subject: [PATCH] Retrieve CIPHER_KEY_SIZE from C++ in Python generate_symmetric_key() (#146) Fixes #139 --- python-package/mc2client/core.py | 4 +++- src/c_api.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/python-package/mc2client/core.py b/python-package/mc2client/core.py index 6fa033c..8e6d6d7 100644 --- a/python-package/mc2client/core.py +++ b/python-package/mc2client/core.py @@ -582,7 +582,7 @@ def generate_keypair(expiration=10 * 365 * 24 * 60 * 60): logger.info("Generated certificate and outputted to {}".format(cert_path)) -def generate_symmetric_key(num_bytes=32): +def generate_symmetric_key(): """ Generate a new symmetric key and save it path specified by user in config YAML passed to `set_config()` @@ -591,6 +591,8 @@ def generate_symmetric_key(num_bytes=32): num_bytes : int Number of bytes for key """ + num_bytes = _LIB.cipher_key_size() + if _CONF.get("general_config") is None: raise MC2ClientConfigError("Configuration not set") diff --git a/src/c_api.cpp b/src/c_api.cpp index 06413e3..052fb79 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -142,3 +142,5 @@ extern "C" void opaque_decrypt_data(char **encrypted_files, plaintext_file, key_file); *result = status; } + +extern "C" size_t cipher_key_size() { return CIPHER_KEY_SIZE; } \ No newline at end of file