Skip to content

CDRIVER-4610 add separate min/max setters #1241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
:man_page: mongoc_client_encryption_encrypt_range_opts_set_max

mongoc_client_encryption_encrypt_range_opts_set_max()
=====================================================

Synopsis
--------

.. code-block:: c

void
mongoc_client_encryption_encrypt_range_opts_set_max (
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
const bson_value_t *max);

.. important:: The |qenc:range-is-experimental| |qenc:api-is-experimental|
.. versionadded:: 1.24.0

Sets the maximum value of the range for explicit encryption.
Only applies when the algorithm set by :symbol:`mongoc_client_encryption_encrypt_opts_set_algorithm()` is "RangePreview".
It is an error to set maximum when algorithm is not "RangePreview".

The maximum must match the value set in the encryptedFields of the destination collection.
It is an error to set a different value.

For double and decimal128 fields, max/max/precision must all be set, or all be unset.

Parameters
----------

* ``range_opts``: A :symbol:`mongoc_client_encryption_encrypt_range_opts_t`
* ``max``: The maximum bson value of the range.

.. seealso::

| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_precision`
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_min`
| :symbol:`mongoc_client_encryption_encrypt_range_opts_t`
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
:man_page: mongoc_client_encryption_encrypt_range_opts_set_min

mongoc_client_encryption_encrypt_range_opts_set_min()
=====================================================

Synopsis
--------

.. code-block:: c

void
mongoc_client_encryption_encrypt_range_opts_set_min (
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
const bson_value_t *min);

.. important:: The |qenc:range-is-experimental| |qenc:api-is-experimental|
.. versionadded:: 1.24.0

Sets the minimum value of the range for explicit encryption.
Only applies when the algorithm set by :symbol:`mongoc_client_encryption_encrypt_opts_set_algorithm()` is "RangePreview".
It is an error to set minimum when algorithm is not "RangePreview".

The minimum must match the value set in the encryptedFields of the destination collection.
It is an error to set a different value.

For double and decimal128 fields, min/max/precision must all be set, or all be unset.

Parameters
----------

* ``range_opts``: A :symbol:`mongoc_client_encryption_encrypt_range_opts_t`
* ``min``: The minimum bson value of the range.

.. seealso::

| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_precision`
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_max`
| :symbol:`mongoc_client_encryption_encrypt_range_opts_t`

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ Parameters

.. seealso::

| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_min_max`
| :symbol:`mongoc_client_encryption_encrypt_range_opts_t`
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_min`
| :symbol:`mongoc_client_encryption_encrypt_range_opts_set_max`
| :symbol:`mongoc_client_encryption_encrypt_range_opts_t`
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ For double and decimal128 fields, min/max/precision must all be set, or all be u
mongoc_client_encryption_encrypt_range_opts_new
mongoc_client_encryption_encrypt_range_opts_destroy
mongoc_client_encryption_encrypt_range_opts_set_sparsity
mongoc_client_encryption_encrypt_range_opts_set_min_max
mongoc_client_encryption_encrypt_range_opts_set_min
mongoc_client_encryption_encrypt_range_opts_set_max
mongoc_client_encryption_encrypt_range_opts_set_precision
mongoc_client_encryption_encrypt_opts_set_range_opts

.. seealso::

| :symbol:`mongoc_client_encryption_encrypt()`
| :symbol:`mongoc_client_encryption_encrypt_opts_t()`
| :symbol:`mongoc_client_encryption_encrypt_opts_t()`
65 changes: 43 additions & 22 deletions src/libmongoc/src/mongoc/mongoc-client-side-encryption.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,13 @@ mongoc_client_encryption_datakey_opts_set_keymaterial (
*/
struct _mongoc_client_encryption_encrypt_range_opts_t {
struct {
bson_value_t min;
bson_value_t max;
bson_value_t value;
bool set;
} minmax;
} min;
struct {
bson_value_t value;
bool set;
} max;
int64_t sparsity;
struct {
int32_t value;
Expand Down Expand Up @@ -468,9 +471,11 @@ mongoc_client_encryption_encrypt_range_opts_destroy (
return;
}

if (range_opts->minmax.set) {
bson_value_destroy (&range_opts->minmax.max);
bson_value_destroy (&range_opts->minmax.min);
if (range_opts->min.set) {
bson_value_destroy (&range_opts->min.value);
}
if (range_opts->max.set) {
bson_value_destroy (&range_opts->max.value);
}
bson_free (range_opts);
}
Expand Down Expand Up @@ -569,22 +574,33 @@ mongoc_client_encryption_encrypt_range_opts_set_sparsity (
}

void
mongoc_client_encryption_encrypt_range_opts_set_min_max (
mongoc_client_encryption_encrypt_range_opts_set_min (
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
const bson_value_t *min,
const bson_value_t *max)
const bson_value_t *min)
{
BSON_ASSERT_PARAM (range_opts);
BSON_ASSERT_PARAM (min);

if (range_opts->min.set) {
bson_value_destroy (&range_opts->min.value);
}
range_opts->min.set = true;
bson_value_copy (min, &range_opts->min.value);
}

void
mongoc_client_encryption_encrypt_range_opts_set_max (
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
const bson_value_t *max)
{
BSON_ASSERT_PARAM (range_opts);
BSON_ASSERT_PARAM (max);

if (range_opts->minmax.set) {
bson_value_destroy (&range_opts->minmax.min);
bson_value_destroy (&range_opts->minmax.max);
if (range_opts->max.set) {
bson_value_destroy (&range_opts->max.value);
}
range_opts->minmax.set = true;
bson_value_copy (min, &range_opts->minmax.min);
bson_value_copy (max, &range_opts->minmax.max);
range_opts->max.set = true;
bson_value_copy (max, &range_opts->max.value);
}

void
Expand All @@ -602,10 +618,13 @@ copy_range_opts (const mongoc_client_encryption_encrypt_range_opts_t *opts)
BSON_ASSERT_PARAM (opts);
mongoc_client_encryption_encrypt_range_opts_t *opts_new =
mongoc_client_encryption_encrypt_range_opts_new ();
if (opts->minmax.set) {
bson_value_copy (&opts->minmax.max, &opts_new->minmax.max);
bson_value_copy (&opts->minmax.min, &opts_new->minmax.min);
opts_new->minmax.set = true;
if (opts->min.set) {
bson_value_copy (&opts->min.value, &opts_new->min.value);
opts_new->min.set = true;
}
if (opts->max.set) {
bson_value_copy (&opts->max.value, &opts_new->max.value);
opts_new->max.set = true;
}
if (opts->precision.set) {
opts_new->precision.value = opts->precision.value;
Expand Down Expand Up @@ -997,11 +1016,13 @@ append_bson_range_opts (bson_t *bson_range_opts,
BSON_ASSERT_PARAM (bson_range_opts);
BSON_ASSERT_PARAM (opts);

if (opts->range_opts->minmax.set) {
if (opts->range_opts->min.set) {
BSON_ASSERT (BSON_APPEND_VALUE (
bson_range_opts, "max", &opts->range_opts->minmax.max));
bson_range_opts, "min", &opts->range_opts->min.value));
}
if (opts->range_opts->max.set) {
BSON_ASSERT (BSON_APPEND_VALUE (
bson_range_opts, "min", &opts->range_opts->minmax.min));
bson_range_opts, "max", &opts->range_opts->max.value));
}
if (opts->range_opts->precision.set) {
BSON_ASSERT (BSON_APPEND_INT32 (
Expand Down
8 changes: 6 additions & 2 deletions src/libmongoc/src/mongoc/mongoc-client-side-encryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,13 @@ mongoc_client_encryption_encrypt_range_opts_set_sparsity (
mongoc_client_encryption_encrypt_range_opts_t *range_opts, int64_t sparsity);

MONGOC_EXPORT (void)
mongoc_client_encryption_encrypt_range_opts_set_min_max (
mongoc_client_encryption_encrypt_range_opts_set_min (
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
const bson_value_t *min);

MONGOC_EXPORT (void)
mongoc_client_encryption_encrypt_range_opts_set_max (
mongoc_client_encryption_encrypt_range_opts_t *range_opts,
const bson_value_t *min,
const bson_value_t *max);

MONGOC_EXPORT (void)
Expand Down
12 changes: 8 additions & 4 deletions src/libmongoc/tests/test-mongoc-client-side-encryption.c
Original file line number Diff line number Diff line change
Expand Up @@ -3949,15 +3949,19 @@ range_explicit_encryption_setup (const char *typeStr)
// DoubleNoPrecision does not need more range options.
} else if (0 == strcmp ("DoublePrecision", typeStr) ||
0 == strcmp ("DecimalPrecision", typeStr)) {
mongoc_client_encryption_encrypt_range_opts_set_min_max (
reef->ro, &reef->zero, &reef->twoHundred);
mongoc_client_encryption_encrypt_range_opts_set_min (reef->ro,
&reef->zero);
mongoc_client_encryption_encrypt_range_opts_set_max (
reef->ro, &reef->twoHundred);
mongoc_client_encryption_encrypt_range_opts_set_precision (reef->ro,
2);
} else if (0 == strcmp ("Date", typeStr) ||
0 == strcmp ("Int", typeStr) ||
0 == strcmp ("Long", typeStr)) {
mongoc_client_encryption_encrypt_range_opts_set_min_max (
reef->ro, &reef->zero, &reef->twoHundred);
mongoc_client_encryption_encrypt_range_opts_set_min (reef->ro,
&reef->zero);
mongoc_client_encryption_encrypt_range_opts_set_max (
reef->ro, &reef->twoHundred);
} else {
test_error ("Unexpected type string: %s\n", typeStr);
}
Expand Down