diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e6875e..1f1c425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.2.0] - 2022-03-08 + +- Switch to using SetupJson instead of Setup for initialization + ## [0.1.0] - 2022-03-04 - Initial release diff --git a/asherah/asherah.py b/asherah/asherah.py index da2497f..e57767a 100644 --- a/asherah/asherah.py +++ b/asherah/asherah.py @@ -1,6 +1,7 @@ """Main Asherah class, for encrypting and decrypting of data""" # pylint: disable=line-too-long, too-many-locals +import json import os from datetime import datetime, timezone from typing import ByteString, Union @@ -21,7 +22,7 @@ def __init__(self): os.path.join(os.path.dirname(__file__), "libasherah"), "libasherah", """ - int32_t Setup(void* kmsTypePtr, void* metastorePtr, void* rdbmsConnectionStringPtr, void* dynamoDbEndpointPtr, void* dynamoDbRegionPtr, void* dynamoDbTableNamePtr, int32_t enableRegionSuffixInt, void* serviceNamePtr, void* productIdPtr, void* preferredRegionPtr, void* regionMapPtr, int32_t verboseInt, int32_t sessionCacheInt, int32_t debugOutputInt); + int32_t SetupJson(void* configJson); int32_t Decrypt(void* partitionIdPtr, void* encryptedDataPtr, void* encryptedKeyPtr, int64_t created, void* parentKeyIdPtr, int64_t parentKeyCreated, void* outputDecryptedDataPtr); int32_t Encrypt(void* partitionIdPtr, void* dataPtr, void* outputEncryptedDataPtr, void* outputEncryptedKeyPtr, void* outputCreatedPtr, void* outputParentKeyIdPtr, void* outputParentKeyCreatedPtr); """, @@ -29,39 +30,9 @@ def __init__(self): def setup(self, config: types.AsherahConfig) -> None: """Set up/initialize the underlying encryption library.""" - kms_type_buf = self.__cobhan.str_to_buf(config.kms_type) - metastore_buf = self.__cobhan.str_to_buf(config.metastore) - service_name_buf = self.__cobhan.str_to_buf(config.service_name) - product_id_buf = self.__cobhan.str_to_buf(config.product_id) - rdbms_connection_string_buf = self.__cobhan.str_to_buf( - config.rdbms_connection_string - ) - dynamo_db_endpoint_buf = self.__cobhan.str_to_buf(config.dynamo_db_endpoint) - dynamo_db_region_buf = self.__cobhan.str_to_buf(config.dynamo_db_region) - dynamo_db_table_name_buf = self.__cobhan.str_to_buf(config.dynamo_db_table_name) - enable_region_suffix_int = int(config.enable_region_suffix) - preferred_region_buf = self.__cobhan.str_to_buf(config.preferred_region) - region_map_buf = self.__cobhan.str_to_buf(config.region_map) - verbose_int = int(config.verbose) - session_cache_int = int(config.session_cache) - debug_output_int = int(config.debug_output) - - result = self.__libasherah.Setup( - kms_type_buf, - metastore_buf, - rdbms_connection_string_buf, - dynamo_db_endpoint_buf, - dynamo_db_region_buf, - dynamo_db_table_name_buf, - enable_region_suffix_int, - service_name_buf, - product_id_buf, - preferred_region_buf, - region_map_buf, - verbose_int, - session_cache_int, - debug_output_int, - ) + config_json = json.dumps(config.to_json()) + config_buf = self.__cobhan.str_to_buf(config_json) + result = self.__libasherah.SetupJson(config_buf) if result < 0: raise exceptions.AsherahException( f"Setup failed with error number {result}" diff --git a/asherah/types.py b/asherah/types.py index b788450..0ed075f 100644 --- a/asherah/types.py +++ b/asherah/types.py @@ -1,7 +1,7 @@ """Type definitions for the Asherah library""" # pylint: disable=too-many-instance-attributes,invalid-name -from dataclasses import dataclass +from dataclasses import asdict, dataclass from datetime import datetime from typing import ByteString, Optional @@ -25,6 +25,15 @@ class AsherahConfig: session_cache: bool = False debug_output: bool = False + def to_json(self): + def camel_case(key): + """Translate snake_case into camelCase.""" + parts = key.split("_") + parts = [parts[0]] + [part.capitalize() for part in parts[1:]] + return "".join(parts) + + return {camel_case(key): val for key, val in asdict(self).items()} + @dataclass class KeyMeta: diff --git a/pyproject.toml b/pyproject.toml index 412a841..ecd6c7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "asherah" -version = "0.1.0" +version = "0.2.0" description = "Asherah envelope encryption and key rotation library" authors = [ "Jeremiah Gowdy ",