Skip to content

Commit 23785a4

Browse files
committed
add docs and stub API for contention factor and query type
1 parent dddadc1 commit 23785a4

7 files changed

+103
-0
lines changed

src/libmongoc/doc/mongoc_client_encryption_encrypt.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Performs explicit encryption.
2020

2121
``ciphertext`` is always initialized (even on failure). Caller must call :symbol:`bson_value_destroy()` to free.
2222

23+
To insert or query with an "Indexed" encrypted payload, use a :symbol:`mongoc_client_t` configured with :symbol:`mongoc_auto_encryption_opts_t`.
24+
The :symbol:`mongoc_auto_encryption_opts_t` may be configured to bypass query analysis with :symbol:`mongoc_auto_encryption_opts_set_bypass_query_analysis`.
25+
The :symbol:`mongoc_auto_encryption_opts_t` must not be configured to bypass automatic encryption with :symbol:`mongoc_auto_encryption_opts_set_bypass_auto_encryption`.
26+
2327
Parameters
2428
----------
2529

src/libmongoc/doc/mongoc_client_encryption_encrypt_opts_set_algorithm.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ Synopsis
1414
1515
#define MONGOC_AEAD_AES_256_CBC_HMAC_SHA_512_RANDOM "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
1616
#define MONGOC_AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
17+
#define MONGOC_ENCRYPT_ALGORITHM_INDEXED "Indexed"
18+
#define MONGOC_ENCRYPT_ALGORITHM_UNINDEXED "Unindexed"
1719
1820
Identifies the algorithm to use for encryption. Valid values of ``algorithm`` are:
1921

2022
* "AEAD_AES_256_CBC_HMAC_SHA_512-Random" for randomized encryption.
2123
* "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" for deterministic (queryable) encryption.
24+
* "Indexed" for indexed encryption.
25+
* "Unindexed" for unindexed encryption.
2226

2327
Parameters
2428
----------
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
:man_page: mongoc_client_encryption_encrypt_opts_set_contention_factor
2+
3+
mongoc_client_encryption_encrypt_opts_set_contention_factor()
4+
=============================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
MONGOC_EXPORT (void)
12+
mongoc_client_encryption_encrypt_opts_set_contention_factor (
13+
mongoc_client_encryption_encrypt_opts_t *opts, int64_t contention_factor);
14+
15+
Sets a contention factor for explicit encryption.
16+
Only applies when the algorithm set by :symbol:`mongoc_client_encryption_encrypt_opts_set_algorithm()` is "Indexed".
17+
It is an error to set the contention factor when algorithm is not "Indexed".
18+
If contention factor is not supplied, it defaults to a value of 0.
19+
20+
Parameters
21+
----------
22+
23+
* ``opts``: A :symbol:`mongoc_client_encryption_encrypt_opts_t`
24+
* ``contention_factor``: A non-negative contention factor.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
:man_page: mongoc_client_encryption_encrypt_opts_set_query_type
2+
3+
mongoc_client_encryption_encrypt_opts_set_query_type()
4+
======================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
typedef enum { MONGOC_ENCRYPT_QUERY_TYPE_EQUALITY } mongoc_encrypt_query_type_t;
12+
13+
MONGOC_EXPORT (void)
14+
mongoc_client_encryption_encrypt_opts_set_query_type (
15+
mongoc_client_encryption_encrypt_opts_t *opts, mongoc_encrypt_query_type_t query_type);
16+
17+
Sets a query type for explicit encryption.
18+
Only applies when the algorithm set by :symbol:`mongoc_client_encryption_encrypt_opts_set_algorithm()` is "Indexed".
19+
It is an error to set the query type when algorithm is not "Indexed".
20+
21+
Parameters
22+
----------
23+
24+
* ``opts``: A :symbol:`mongoc_client_encryption_encrypt_opts_t`
25+
* ``query_type``: A query type to use for explicit encryption.

src/libmongoc/doc/mongoc_client_encryption_encrypt_opts_t.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Used to set options for :symbol:`mongoc_client_encryption_encrypt()`.
2727
mongoc_client_encryption_encrypt_opts_set_keyid
2828
mongoc_client_encryption_encrypt_opts_set_keyaltname
2929
mongoc_client_encryption_encrypt_opts_set_algorithm
30+
mongoc_client_encryption_encrypt_opts_set_contention_factor
31+
mongoc_client_encryption_encrypt_opts_set_query_type
3032

3133
.. seealso::
3234

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ struct _mongoc_client_encryption_encrypt_opts_t {
379379
bson_value_t keyid;
380380
char *algorithm;
381381
char *keyaltname;
382+
struct {
383+
int64_t value;
384+
bool set;
385+
} contention_factor;
386+
struct {
387+
mongoc_encrypt_query_type_t value;
388+
bool set;
389+
} query_type;
382390
};
383391

384392
mongoc_client_encryption_encrypt_opts_t *
@@ -438,6 +446,29 @@ mongoc_client_encryption_encrypt_opts_set_algorithm (
438446
opts->algorithm = bson_strdup (algorithm);
439447
}
440448

449+
void
450+
mongoc_client_encryption_encrypt_opts_set_contention_factor (
451+
mongoc_client_encryption_encrypt_opts_t *opts, int64_t contention_factor)
452+
{
453+
if (!opts) {
454+
return;
455+
}
456+
opts->contention_factor.value = contention_factor;
457+
opts->contention_factor.set = true;
458+
}
459+
460+
void
461+
mongoc_client_encryption_encrypt_opts_set_query_type (
462+
mongoc_client_encryption_encrypt_opts_t *opts,
463+
mongoc_encrypt_query_type_t query_type)
464+
{
465+
if (!opts) {
466+
return;
467+
}
468+
opts->query_type.value = query_type;
469+
opts->query_type.set = true;
470+
}
471+
441472
#ifndef MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION
442473

443474
static bool

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct _mongoc_client_pool_t;
2929
"AEAD_AES_256_CBC_HMAC_SHA_512-Random"
3030
#define MONGOC_AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC \
3131
"AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
32+
#define MONGOC_ENCRYPT_ALGORITHM_INDEXED "Indexed"
33+
#define MONGOC_ENCRYPT_ALGORITHM_UNINDEXED "Unindexed"
3234

3335
BSON_BEGIN_DECLS
3436

@@ -158,6 +160,17 @@ MONGOC_EXPORT (void)
158160
mongoc_client_encryption_encrypt_opts_set_algorithm (
159161
mongoc_client_encryption_encrypt_opts_t *opts, const char *algorithm);
160162

163+
MONGOC_EXPORT (void)
164+
mongoc_client_encryption_encrypt_opts_set_contention_factor (
165+
mongoc_client_encryption_encrypt_opts_t *opts, int64_t contention_factor);
166+
167+
typedef enum { MONGOC_ENCRYPT_QUERY_TYPE_EQUALITY } mongoc_encrypt_query_type_t;
168+
169+
MONGOC_EXPORT (void)
170+
mongoc_client_encryption_encrypt_opts_set_query_type (
171+
mongoc_client_encryption_encrypt_opts_t *opts,
172+
mongoc_encrypt_query_type_t query_type);
173+
161174
MONGOC_EXPORT (mongoc_client_encryption_datakey_opts_t *)
162175
mongoc_client_encryption_datakey_opts_new (void) BSON_GNUC_WARN_UNUSED_RESULT;
163176

0 commit comments

Comments
 (0)