Skip to content

Commit 0907ab8

Browse files
committed
pass query_type, index_type, and contention_factor through to libmongocrypt
1 parent ebf1adf commit 0907ab8

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,14 +1777,17 @@ mongoc_client_encryption_encrypt (mongoc_client_encryption_t *client_encryption,
17771777
GOTO (fail);
17781778
}
17791779

1780-
if (!_mongoc_crypt_explicit_encrypt (client_encryption->crypt,
1781-
client_encryption->keyvault_coll,
1782-
opts->algorithm,
1783-
&opts->keyid,
1784-
opts->keyaltname,
1785-
value,
1786-
ciphertext,
1787-
error)) {
1780+
if (!_mongoc_crypt_explicit_encrypt (
1781+
client_encryption->crypt,
1782+
client_encryption->keyvault_coll,
1783+
opts->algorithm,
1784+
&opts->keyid,
1785+
opts->keyaltname,
1786+
opts->query_type.set ? &opts->query_type.value : NULL,
1787+
opts->contention_factor.set ? &opts->contention_factor.value : NULL,
1788+
value,
1789+
ciphertext,
1790+
error)) {
17881791
GOTO (fail);
17891792
}
17901793

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ Perform explicit encryption.
7979
- exactly one of keyid or keyaltname must be set, the other NULL, or an error is
8080
returned.
8181
- value_out is always initialized.
82+
- query_type may be NULL.
83+
- contention_factor may be NULL.
8284
- may return false and set error.
8385
*/
8486
bool
@@ -87,6 +89,8 @@ _mongoc_crypt_explicit_encrypt (_mongoc_crypt_t *crypt,
8789
const char *algorithm,
8890
const bson_value_t *keyid,
8991
char *keyaltname,
92+
mongoc_encrypt_query_type_t *query_type,
93+
int64_t *contention_factor,
9094
const bson_value_t *value_in,
9195
bson_value_t *value_out,
9296
bson_error_t *error);

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

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,8 @@ _mongoc_crypt_explicit_encrypt (_mongoc_crypt_t *crypt,
11341134
const char *algorithm,
11351135
const bson_value_t *keyid,
11361136
char *keyaltname,
1137+
mongoc_encrypt_query_type_t *query_type,
1138+
int64_t *contention_factor,
11371139
const bson_value_t *value_in,
11381140
bson_value_t *value_out,
11391141
bson_error_t *error)
@@ -1156,9 +1158,48 @@ _mongoc_crypt_explicit_encrypt (_mongoc_crypt_t *crypt,
11561158
goto fail;
11571159
}
11581160

1159-
if (!mongocrypt_ctx_setopt_algorithm (state_machine->ctx, algorithm, -1)) {
1160-
_ctx_check_error (state_machine->ctx, error, true);
1161-
goto fail;
1161+
if (NULL != algorithm &&
1162+
0 == strcmp (algorithm, MONGOC_ENCRYPT_ALGORITHM_INDEXED)) {
1163+
if (!mongocrypt_ctx_setopt_index_type (state_machine->ctx,
1164+
MONGOCRYPT_INDEX_TYPE_EQUALITY)) {
1165+
_ctx_check_error (state_machine->ctx, error, true);
1166+
goto fail;
1167+
}
1168+
} else if (NULL != algorithm &&
1169+
0 == strcmp (algorithm, MONGOC_ENCRYPT_ALGORITHM_UNINDEXED)) {
1170+
if (!mongocrypt_ctx_setopt_index_type (state_machine->ctx,
1171+
MONGOCRYPT_INDEX_TYPE_NONE)) {
1172+
_ctx_check_error (state_machine->ctx, error, true);
1173+
goto fail;
1174+
}
1175+
} else {
1176+
if (!mongocrypt_ctx_setopt_algorithm (
1177+
state_machine->ctx, algorithm, -1)) {
1178+
_ctx_check_error (state_machine->ctx, error, true);
1179+
goto fail;
1180+
}
1181+
}
1182+
1183+
if (query_type != NULL) {
1184+
mongocrypt_query_type_t converted;
1185+
1186+
switch (*query_type) {
1187+
case MONGOC_ENCRYPT_QUERY_TYPE_EQUALITY:
1188+
converted = MONGOCRYPT_QUERY_TYPE_EQUALITY;
1189+
break;
1190+
}
1191+
if (!mongocrypt_ctx_setopt_query_type (state_machine->ctx, converted)) {
1192+
_ctx_check_error (state_machine->ctx, error, true);
1193+
goto fail;
1194+
}
1195+
}
1196+
1197+
if (contention_factor != NULL) {
1198+
if (!mongocrypt_ctx_setopt_contention_factor (state_machine->ctx,
1199+
*contention_factor)) {
1200+
_ctx_check_error (state_machine->ctx, error, true);
1201+
goto fail;
1202+
}
11621203
}
11631204

11641205
if (keyaltname) {

0 commit comments

Comments
 (0)