Skip to content

Commit

Permalink
Migrate use of tiledb_array_create_with_key deprecated API.
Browse files Browse the repository at this point in the history
  • Loading branch information
kounelisagis committed Apr 25, 2024
1 parent d3fd583 commit 647b15f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
8 changes: 0 additions & 8 deletions tiledb/libtiledb.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 18 additions & 3 deletions tiledb/libtiledb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <void *> PyBytes_AS_STRING(bkey)
key_ptr = <const char *> PyBytes_AS_STRING(bkey)
#TODO: unsafe cast here ssize_t -> uint64_t
key_len = <unsigned int> 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:
Expand All @@ -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
Expand Down

0 comments on commit 647b15f

Please sign in to comment.