Skip to content

Commit 11e31e3

Browse files
authored
CDRIVER-4610 add separate min/max setters (#1241)
* add separate min/max helpers * add helpers to seealso sections
1 parent 7ae8fd3 commit 11e31e3

8 files changed

+139
-71
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
:man_page: mongoc_client_encryption_encrypt_range_opts_set_max
2+
3+
mongoc_client_encryption_encrypt_range_opts_set_max()
4+
=====================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void
12+
mongoc_client_encryption_encrypt_range_opts_set_max (
13+
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
14+
const bson_value_t *max);
15+
16+
.. important:: The |qenc:range-is-experimental| |qenc:api-is-experimental|
17+
.. versionadded:: 1.24.0
18+
19+
Sets the maximum value of the range for explicit encryption.
20+
Only applies when the algorithm set by :symbol:`mongoc_client_encryption_encrypt_opts_set_algorithm()` is "RangePreview".
21+
It is an error to set maximum when algorithm is not "RangePreview".
22+
23+
The maximum must match the value set in the encryptedFields of the destination collection.
24+
It is an error to set a different value.
25+
26+
For double and decimal128 fields, max/max/precision must all be set, or all be unset.
27+
28+
Parameters
29+
----------
30+
31+
* ``range_opts``: A :symbol:`mongoc_client_encryption_encrypt_range_opts_t`
32+
* ``max``: The maximum bson value of the range.
33+
34+
.. seealso::
35+
36+
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_precision`
37+
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_min`
38+
| :symbol:`mongoc_client_encryption_encrypt_range_opts_t`
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
:man_page: mongoc_client_encryption_encrypt_range_opts_set_min
2+
3+
mongoc_client_encryption_encrypt_range_opts_set_min()
4+
=====================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void
12+
mongoc_client_encryption_encrypt_range_opts_set_min (
13+
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
14+
const bson_value_t *min);
15+
16+
.. important:: The |qenc:range-is-experimental| |qenc:api-is-experimental|
17+
.. versionadded:: 1.24.0
18+
19+
Sets the minimum value of the range for explicit encryption.
20+
Only applies when the algorithm set by :symbol:`mongoc_client_encryption_encrypt_opts_set_algorithm()` is "RangePreview".
21+
It is an error to set minimum when algorithm is not "RangePreview".
22+
23+
The minimum must match the value set in the encryptedFields of the destination collection.
24+
It is an error to set a different value.
25+
26+
For double and decimal128 fields, min/max/precision must all be set, or all be unset.
27+
28+
Parameters
29+
----------
30+
31+
* ``range_opts``: A :symbol:`mongoc_client_encryption_encrypt_range_opts_t`
32+
* ``min``: The minimum bson value of the range.
33+
34+
.. seealso::
35+
36+
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_precision`
37+
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_max`
38+
| :symbol:`mongoc_client_encryption_encrypt_range_opts_t`

src/libmongoc/doc/mongoc_client_encryption_encrypt_range_opts_set_min_max.rst

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/libmongoc/doc/mongoc_client_encryption_encrypt_range_opts_set_precision.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ Parameters
3535

3636
.. seealso::
3737

38-
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_min_max`
39-
| :symbol:`mongoc_client_encryption_encrypt_range_opts_t`
38+
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_min`
39+
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_max`
40+
| :symbol:`mongoc_client_encryption_encrypt_range_opts_t`

src/libmongoc/doc/mongoc_client_encryption_encrypt_range_opts_t.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ For double and decimal128 fields, min/max/precision must all be set, or all be u
3131
mongoc_client_encryption_encrypt_range_opts_new
3232
mongoc_client_encryption_encrypt_range_opts_destroy
3333
mongoc_client_encryption_encrypt_range_opts_set_sparsity
34-
mongoc_client_encryption_encrypt_range_opts_set_min_max
34+
mongoc_client_encryption_encrypt_range_opts_set_min
35+
mongoc_client_encryption_encrypt_range_opts_set_max
3536
mongoc_client_encryption_encrypt_range_opts_set_precision
3637
mongoc_client_encryption_encrypt_opts_set_range_opts
3738

3839
.. seealso::
3940

4041
| :symbol:`mongoc_client_encryption_encrypt()`
41-
| :symbol:`mongoc_client_encryption_encrypt_opts_t()`
42+
| :symbol:`mongoc_client_encryption_encrypt_opts_t()`

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

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,13 @@ mongoc_client_encryption_datakey_opts_set_keymaterial (
431431
*/
432432
struct _mongoc_client_encryption_encrypt_range_opts_t {
433433
struct {
434-
bson_value_t min;
435-
bson_value_t max;
434+
bson_value_t value;
436435
bool set;
437-
} minmax;
436+
} min;
437+
struct {
438+
bson_value_t value;
439+
bool set;
440+
} max;
438441
int64_t sparsity;
439442
struct {
440443
int32_t value;
@@ -468,9 +471,11 @@ mongoc_client_encryption_encrypt_range_opts_destroy (
468471
return;
469472
}
470473

471-
if (range_opts->minmax.set) {
472-
bson_value_destroy (&range_opts->minmax.max);
473-
bson_value_destroy (&range_opts->minmax.min);
474+
if (range_opts->min.set) {
475+
bson_value_destroy (&range_opts->min.value);
476+
}
477+
if (range_opts->max.set) {
478+
bson_value_destroy (&range_opts->max.value);
474479
}
475480
bson_free (range_opts);
476481
}
@@ -569,22 +574,33 @@ mongoc_client_encryption_encrypt_range_opts_set_sparsity (
569574
}
570575

571576
void
572-
mongoc_client_encryption_encrypt_range_opts_set_min_max (
577+
mongoc_client_encryption_encrypt_range_opts_set_min (
573578
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
574-
const bson_value_t *min,
575-
const bson_value_t *max)
579+
const bson_value_t *min)
576580
{
577581
BSON_ASSERT_PARAM (range_opts);
578582
BSON_ASSERT_PARAM (min);
583+
584+
if (range_opts->min.set) {
585+
bson_value_destroy (&range_opts->min.value);
586+
}
587+
range_opts->min.set = true;
588+
bson_value_copy (min, &range_opts->min.value);
589+
}
590+
591+
void
592+
mongoc_client_encryption_encrypt_range_opts_set_max (
593+
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
594+
const bson_value_t *max)
595+
{
596+
BSON_ASSERT_PARAM (range_opts);
579597
BSON_ASSERT_PARAM (max);
580598

581-
if (range_opts->minmax.set) {
582-
bson_value_destroy (&range_opts->minmax.min);
583-
bson_value_destroy (&range_opts->minmax.max);
599+
if (range_opts->max.set) {
600+
bson_value_destroy (&range_opts->max.value);
584601
}
585-
range_opts->minmax.set = true;
586-
bson_value_copy (min, &range_opts->minmax.min);
587-
bson_value_copy (max, &range_opts->minmax.max);
602+
range_opts->max.set = true;
603+
bson_value_copy (max, &range_opts->max.value);
588604
}
589605

590606
void
@@ -602,10 +618,13 @@ copy_range_opts (const mongoc_client_encryption_encrypt_range_opts_t *opts)
602618
BSON_ASSERT_PARAM (opts);
603619
mongoc_client_encryption_encrypt_range_opts_t *opts_new =
604620
mongoc_client_encryption_encrypt_range_opts_new ();
605-
if (opts->minmax.set) {
606-
bson_value_copy (&opts->minmax.max, &opts_new->minmax.max);
607-
bson_value_copy (&opts->minmax.min, &opts_new->minmax.min);
608-
opts_new->minmax.set = true;
621+
if (opts->min.set) {
622+
bson_value_copy (&opts->min.value, &opts_new->min.value);
623+
opts_new->min.set = true;
624+
}
625+
if (opts->max.set) {
626+
bson_value_copy (&opts->max.value, &opts_new->max.value);
627+
opts_new->max.set = true;
609628
}
610629
if (opts->precision.set) {
611630
opts_new->precision.value = opts->precision.value;
@@ -997,11 +1016,13 @@ append_bson_range_opts (bson_t *bson_range_opts,
9971016
BSON_ASSERT_PARAM (bson_range_opts);
9981017
BSON_ASSERT_PARAM (opts);
9991018

1000-
if (opts->range_opts->minmax.set) {
1019+
if (opts->range_opts->min.set) {
10011020
BSON_ASSERT (BSON_APPEND_VALUE (
1002-
bson_range_opts, "max", &opts->range_opts->minmax.max));
1021+
bson_range_opts, "min", &opts->range_opts->min.value));
1022+
}
1023+
if (opts->range_opts->max.set) {
10031024
BSON_ASSERT (BSON_APPEND_VALUE (
1004-
bson_range_opts, "min", &opts->range_opts->minmax.min));
1025+
bson_range_opts, "max", &opts->range_opts->max.value));
10051026
}
10061027
if (opts->range_opts->precision.set) {
10071028
BSON_ASSERT (BSON_APPEND_INT32 (

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,13 @@ mongoc_client_encryption_encrypt_range_opts_set_sparsity (
278278
mongoc_client_encryption_encrypt_range_opts_t *range_opts, int64_t sparsity);
279279

280280
MONGOC_EXPORT (void)
281-
mongoc_client_encryption_encrypt_range_opts_set_min_max (
281+
mongoc_client_encryption_encrypt_range_opts_set_min (
282+
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
283+
const bson_value_t *min);
284+
285+
MONGOC_EXPORT (void)
286+
mongoc_client_encryption_encrypt_range_opts_set_max (
282287
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
283-
const bson_value_t *min,
284288
const bson_value_t *max);
285289

286290
MONGOC_EXPORT (void)

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3949,15 +3949,19 @@ range_explicit_encryption_setup (const char *typeStr)
39493949
// DoubleNoPrecision does not need more range options.
39503950
} else if (0 == strcmp ("DoublePrecision", typeStr) ||
39513951
0 == strcmp ("DecimalPrecision", typeStr)) {
3952-
mongoc_client_encryption_encrypt_range_opts_set_min_max (
3953-
reef->ro, &reef->zero, &reef->twoHundred);
3952+
mongoc_client_encryption_encrypt_range_opts_set_min (reef->ro,
3953+
&reef->zero);
3954+
mongoc_client_encryption_encrypt_range_opts_set_max (
3955+
reef->ro, &reef->twoHundred);
39543956
mongoc_client_encryption_encrypt_range_opts_set_precision (reef->ro,
39553957
2);
39563958
} else if (0 == strcmp ("Date", typeStr) ||
39573959
0 == strcmp ("Int", typeStr) ||
39583960
0 == strcmp ("Long", typeStr)) {
3959-
mongoc_client_encryption_encrypt_range_opts_set_min_max (
3960-
reef->ro, &reef->zero, &reef->twoHundred);
3961+
mongoc_client_encryption_encrypt_range_opts_set_min (reef->ro,
3962+
&reef->zero);
3963+
mongoc_client_encryption_encrypt_range_opts_set_max (
3964+
reef->ro, &reef->twoHundred);
39613965
} else {
39623966
test_error ("Unexpected type string: %s\n", typeStr);
39633967
}

0 commit comments

Comments
 (0)