Skip to content

Commit a9fe55a

Browse files
vector-of-boolkevinAlbs
authored andcommitted
[CDRIVER-4404] mongocrypt queryType option is now a string (#1042)
1 parent 7e2ee65 commit a9fe55a

File tree

5 files changed

+24
-50
lines changed

5 files changed

+24
-50
lines changed

src/libmongoc/doc/mongoc_client_encryption_encrypt_opts_set_query_type.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ Synopsis
88

99
.. code-block:: c
1010
11-
typedef enum { MONGOC_ENCRYPT_QUERY_TYPE_EQUALITY } mongoc_encrypt_query_type_t;
11+
#define MONGOC_ENCRYPT_QUERY_TYPE_EQUALITY "equality"
1212
1313
MONGOC_EXPORT (void)
1414
mongoc_client_encryption_encrypt_opts_set_query_type (
15-
mongoc_client_encryption_encrypt_opts_t *opts, mongoc_encrypt_query_type_t query_type);
15+
mongoc_client_encryption_encrypt_opts_t *opts, const char* query_type);
1616
1717
.. important:: |qenc:api-is-experimental|
1818
.. versionadded:: 1.22.0
1919

20-
Sets a query type for explicit encryption.
20+
Sets a query type for explicit encryption. Currently, the only supported value
21+
for ``query_type`` is ``"equality"``.
22+
2123
Only applies when the algorithm set by :symbol:`mongoc_client_encryption_encrypt_opts_set_algorithm()` is "Indexed".
2224
It is an error to set the query type when algorithm is not "Indexed".
2325

src/libmongoc/src/mongoc/mongoc-client-side-encryption.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,7 @@ struct _mongoc_client_encryption_encrypt_opts_t {
405405
int64_t value;
406406
bool set;
407407
} contention_factor;
408-
struct {
409-
mongoc_encrypt_query_type_t value;
410-
bool set;
411-
} query_type;
408+
char *query_type;
412409
};
413410

414411
mongoc_client_encryption_encrypt_opts_t *
@@ -427,6 +424,7 @@ mongoc_client_encryption_encrypt_opts_destroy (
427424
bson_value_destroy (&opts->keyid);
428425
bson_free (opts->algorithm);
429426
bson_free (opts->keyaltname);
427+
bson_free (opts->query_type);
430428
bson_free (opts);
431429
}
432430

@@ -481,14 +479,13 @@ mongoc_client_encryption_encrypt_opts_set_contention_factor (
481479

482480
void
483481
mongoc_client_encryption_encrypt_opts_set_query_type (
484-
mongoc_client_encryption_encrypt_opts_t *opts,
485-
mongoc_encrypt_query_type_t query_type)
482+
mongoc_client_encryption_encrypt_opts_t *opts, const char *query_type)
486483
{
487484
if (!opts) {
488485
return;
489486
}
490-
opts->query_type.value = query_type;
491-
opts->query_type.set = true;
487+
bson_free (opts->query_type);
488+
opts->query_type = query_type ? bson_strdup (query_type) : NULL;
492489
}
493490

494491
/*--------------------------------------------------------------------------
@@ -2422,7 +2419,6 @@ mongoc_client_encryption_remove_key_alt_name (
24222419
}
24232420
}
24242421

2425-
fail:
24262422
bson_destroy (&query);
24272423
bson_destroy (&local_reply);
24282424

@@ -2511,7 +2507,7 @@ mongoc_client_encryption_encrypt (mongoc_client_encryption_t *client_encryption,
25112507
opts->algorithm,
25122508
&opts->keyid,
25132509
opts->keyaltname,
2514-
opts->query_type.set ? &opts->query_type.value : NULL,
2510+
opts->query_type,
25152511
opts->contention_factor.set ? &opts->contention_factor.value : NULL,
25162512
value,
25172513
ciphertext,

src/libmongoc/src/mongoc/mongoc-client-side-encryption.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ struct _mongoc_cursor_t;
3333
#define MONGOC_ENCRYPT_ALGORITHM_INDEXED "Indexed"
3434
#define MONGOC_ENCRYPT_ALGORITHM_UNINDEXED "Unindexed"
3535

36+
#define MONGOC_ENCRYPT_QUERY_TYPE_EQUALITY "equality"
37+
38+
3639
BSON_BEGIN_DECLS
3740

3841
typedef struct _mongoc_auto_encryption_opts_t mongoc_auto_encryption_opts_t;
@@ -237,12 +240,9 @@ MONGOC_EXPORT (void)
237240
mongoc_client_encryption_encrypt_opts_set_contention_factor (
238241
mongoc_client_encryption_encrypt_opts_t *opts, int64_t contention_factor);
239242

240-
typedef enum { MONGOC_ENCRYPT_QUERY_TYPE_EQUALITY } mongoc_encrypt_query_type_t;
241-
242243
MONGOC_EXPORT (void)
243244
mongoc_client_encryption_encrypt_opts_set_query_type (
244-
mongoc_client_encryption_encrypt_opts_t *opts,
245-
mongoc_encrypt_query_type_t query_type);
245+
mongoc_client_encryption_encrypt_opts_t *opts, const char *query_type);
246246

247247
MONGOC_EXPORT (mongoc_client_encryption_datakey_opts_t *)
248248
mongoc_client_encryption_datakey_opts_new (void) BSON_GNUC_WARN_UNUSED_RESULT;

src/libmongoc/src/mongoc/mongoc-crypt-private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ _mongoc_crypt_explicit_encrypt (_mongoc_crypt_t *crypt,
8989
const char *algorithm,
9090
const bson_value_t *keyid,
9191
char *keyaltname,
92-
const mongoc_encrypt_query_type_t *query_type,
92+
const char *query_type,
9393
const int64_t *contention_factor,
9494
const bson_value_t *value_in,
9595
bson_value_t *value_out,

src/libmongoc/src/mongoc/mongoc-crypt.c

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,8 @@ _mongoc_crypt_new (const bson_t *kms_providers,
994994
const char *s =
995995
mongocrypt_crypt_shared_lib_version_string (crypt->handle, &len);
996996
if (!s || len == 0) {
997-
// empty/null version string indicates that crypt_shared was not loaded by
998-
// libmongocrypt
997+
// empty/null version string indicates that crypt_shared was not loaded
998+
// by libmongocrypt
999999
bson_set_error (
10001000
error,
10011001
MONGOC_ERROR_CLIENT_SIDE_ENCRYPTION,
@@ -1132,7 +1132,7 @@ _mongoc_crypt_explicit_encrypt (_mongoc_crypt_t *crypt,
11321132
const char *algorithm,
11331133
const bson_value_t *keyid,
11341134
char *keyaltname,
1135-
const mongoc_encrypt_query_type_t *query_type,
1135+
const char *query_type,
11361136
const int64_t *contention_factor,
11371137
const bson_value_t *value_in,
11381138
bson_value_t *value_out,
@@ -1156,38 +1156,14 @@ _mongoc_crypt_explicit_encrypt (_mongoc_crypt_t *crypt,
11561156
goto fail;
11571157
}
11581158

1159-
if (NULL != algorithm &&
1160-
0 == strcmp (algorithm, MONGOC_ENCRYPT_ALGORITHM_INDEXED)) {
1161-
if (!mongocrypt_ctx_setopt_index_type (state_machine->ctx,
1162-
MONGOCRYPT_INDEX_TYPE_EQUALITY)) {
1163-
_ctx_check_error (state_machine->ctx, error, true);
1164-
goto fail;
1165-
}
1166-
} else if (NULL != algorithm &&
1167-
0 == strcmp (algorithm, MONGOC_ENCRYPT_ALGORITHM_UNINDEXED)) {
1168-
if (!mongocrypt_ctx_setopt_index_type (state_machine->ctx,
1169-
MONGOCRYPT_INDEX_TYPE_NONE)) {
1170-
_ctx_check_error (state_machine->ctx, error, true);
1171-
goto fail;
1172-
}
1173-
} else {
1174-
if (!mongocrypt_ctx_setopt_algorithm (
1175-
state_machine->ctx, algorithm, -1)) {
1176-
_ctx_check_error (state_machine->ctx, error, true);
1177-
goto fail;
1178-
}
1159+
if (!mongocrypt_ctx_setopt_algorithm (state_machine->ctx, algorithm, -1)) {
1160+
_ctx_check_error (state_machine->ctx, error, true);
1161+
goto fail;
11791162
}
11801163

11811164
if (query_type != NULL) {
1182-
mongocrypt_query_type_t converted = 0;
1183-
1184-
switch (*query_type) {
1185-
case MONGOC_ENCRYPT_QUERY_TYPE_EQUALITY:
1186-
converted = MONGOCRYPT_QUERY_TYPE_EQUALITY;
1187-
break;
1188-
}
1189-
if (!mongocrypt_ctx_setopt_query_type (state_machine->ctx, converted)) {
1190-
_ctx_check_error (state_machine->ctx, error, true);
1165+
if (!mongocrypt_ctx_setopt_query_type (
1166+
state_machine->ctx, query_type, -1)) {
11911167
goto fail;
11921168
}
11931169
}

0 commit comments

Comments
 (0)