From 647b15fa4c93c25fb23241873775fa790e620180 Mon Sep 17 00:00:00 2001 From: Agis Kounelis Date: Thu, 25 Apr 2024 14:42:19 +0300 Subject: [PATCH] Migrate use of tiledb_array_create_with_key deprecated API. --- tiledb/libtiledb.pxd | 8 -------- tiledb/libtiledb.pyx | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tiledb/libtiledb.pxd b/tiledb/libtiledb.pxd index 3b88ecf121..c251517382 100644 --- a/tiledb/libtiledb.pxd +++ b/tiledb/libtiledb.pxd @@ -845,14 +845,6 @@ cdef extern from "tiledb/tiledb.h": const char* uri, const tiledb_array_schema_t* array_schema) nogil - int tiledb_array_create_with_key( - tiledb_ctx_t* ctx, - const char* uri, - const tiledb_array_schema_t* array_schema, - tiledb_encryption_type_t key_type, - const void* key, - unsigned int key_len) nogil - int tiledb_array_is_open( tiledb_ctx_t* ctx, tiledb_array_t* array, diff --git a/tiledb/libtiledb.pyx b/tiledb/libtiledb.pyx index 1250649ec7..dafd8f0c91 100644 --- a/tiledb/libtiledb.pyx +++ b/tiledb/libtiledb.pyx @@ -940,21 +940,36 @@ cdef class Array(object): cdef bytes bkey cdef tiledb_encryption_type_t key_type = TILEDB_NO_ENCRYPTION - cdef void* key_ptr = NULL + cdef const char* key_ptr = NULL cdef unsigned int key_len = 0 cdef int rc = TILEDB_OK + cdef tiledb_config_t* config_ptr = NULL + cdef tiledb_error_t* err_ptr = NULL + if key is not None: if isinstance(key, str): bkey = key.encode('ascii') else: bkey = bytes(key) key_type = TILEDB_AES_256_GCM - key_ptr = PyBytes_AS_STRING(bkey) + key_ptr = PyBytes_AS_STRING(bkey) #TODO: unsafe cast here ssize_t -> uint64_t key_len = PyBytes_GET_SIZE(bkey) + rc = tiledb_config_alloc(&config_ptr, &err_ptr) + if rc != TILEDB_OK: + _raise_ctx_err(ctx_ptr, rc) + + rc = tiledb_config_set(config_ptr, "sm.encryption_type", "AES_256_GCM", &err_ptr) + if rc != TILEDB_OK: + _raise_ctx_err(ctx_ptr, rc) + + rc = tiledb_config_set(config_ptr, "sm.encryption_key", key_ptr, &err_ptr) + if rc != TILEDB_OK: + _raise_ctx_err(ctx_ptr, rc) + if overwrite: if object_type(uri) == "array": if uri.startswith("file://") or "://" not in uri: @@ -971,7 +986,7 @@ cdef class Array(object): "object to argument ctx") ctx_ptr = safe_ctx_ptr(ctx) with nogil: - rc = tiledb_array_create_with_key(ctx_ptr, uri_ptr, schema_ptr, key_type, key_ptr, key_len) + rc = tiledb_array_create(ctx_ptr, uri_ptr, schema_ptr) if rc != TILEDB_OK: _raise_ctx_err(ctx_ptr, rc) return