Skip to content

DRIVERS-2767 QE Range Protocol v2 #1627

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 15 commits into from
Jun 4, 2024
Merged
13 changes: 13 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-client-side-encryption.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ struct _mongoc_client_encryption_encrypt_range_opts_t {
bson_value_t value;
bool set;
} max;
int32_t trim_factor;
int64_t sparsity;
struct {
int32_t value;
Expand Down Expand Up @@ -549,6 +550,14 @@ mongoc_client_encryption_encrypt_range_opts_new (void)
return bson_malloc0 (sizeof (mongoc_client_encryption_encrypt_range_opts_t));
}

void
mongoc_client_encryption_encrypt_range_opts_set_trim_factor (mongoc_client_encryption_encrypt_range_opts_t *range_opts,
int32_t trim_factor)
{
BSON_ASSERT_PARAM (range_opts);
range_opts->trim_factor = trim_factor;
}

void
mongoc_client_encryption_encrypt_range_opts_set_sparsity (mongoc_client_encryption_encrypt_range_opts_t *range_opts,
int64_t sparsity)
Expand Down Expand Up @@ -612,6 +621,7 @@ copy_range_opts (const mongoc_client_encryption_encrypt_range_opts_t *opts)
opts_new->precision.set = true;
}
opts_new->sparsity = opts->sparsity;
opts_new->trim_factor = opts->trim_factor;
return opts_new;
}

Expand Down Expand Up @@ -991,6 +1001,9 @@ append_bson_range_opts (bson_t *bson_range_opts, const mongoc_client_encryption_
if (opts->range_opts->sparsity) {
BSON_ASSERT (BSON_APPEND_INT64 (bson_range_opts, "sparsity", opts->range_opts->sparsity));
}
if (opts->range_opts->trim_factor) {
BSON_ASSERT (BSON_APPEND_INT32 (bson_range_opts, "trimFactor", opts->range_opts->trim_factor));
}
}

/*--------------------------------------------------------------------------
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 @@ -33,10 +33,10 @@ struct _mongoc_database_t;
#define MONGOC_AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
#define MONGOC_ENCRYPT_ALGORITHM_INDEXED "Indexed"
#define MONGOC_ENCRYPT_ALGORITHM_UNINDEXED "Unindexed"
#define MONGOC_ENCRYPT_ALGORITHM_RANGEPREVIEW "RangePreview"
#define MONGOC_ENCRYPT_ALGORITHM_RANGE "Range"

#define MONGOC_ENCRYPT_QUERY_TYPE_EQUALITY "equality"
#define MONGOC_ENCRYPT_QUERY_TYPE_RANGEPREVIEW "rangePreview"
#define MONGOC_ENCRYPT_QUERY_TYPE_RANGE "range"


BSON_BEGIN_DECLS
Expand Down Expand Up @@ -247,6 +247,10 @@ mongoc_client_encryption_encrypt_range_opts_new (void);
MONGOC_EXPORT (void)
mongoc_client_encryption_encrypt_range_opts_destroy (mongoc_client_encryption_encrypt_range_opts_t *range_opts);

MONGOC_EXPORT (void)
mongoc_client_encryption_encrypt_range_opts_set_trim_factor (mongoc_client_encryption_encrypt_range_opts_t *range_opts,
int32_t trim_factor);

MONGOC_EXPORT (void)
mongoc_client_encryption_encrypt_range_opts_set_sparsity (mongoc_client_encryption_encrypt_range_opts_t *range_opts,
int64_t sparsity);
Expand Down
5 changes: 5 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,11 @@ _mongoc_crypt_new (const bson_t *kms_providers,
// Enable the NEEDS_CREDENTIALS state for on-demand credential loading
mongocrypt_setopt_use_need_kms_credentials_state (crypt->handle);

if (!mongocrypt_setopt_use_range_v2 (crypt->handle)) {
_crypt_check_error (crypt->handle, error, true);
goto fail;
}

if (!mongocrypt_init (crypt->handle)) {
_crypt_check_error (crypt->handle, error, true);
goto fail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberLong": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"path": "encryptedDecimalNoPrecision",
"bsonType": "decimal",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
"path": "encryptedDecimalPrecision",
"bsonType": "decimal",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberLong": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"path": "encryptedDoubleNoPrecision",
"bsonType": "double",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
"path": "encryptedDoublePrecision",
"bsonType": "double",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberLong": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
"path": "encryptedInt",
"bsonType": "int",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberLong": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
"path": "encryptedLong",
"bsonType": "long",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberLong": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"runOn": [
{
"minServerVersion": "7.0.0",
"minServerVersion": "8.0.0",
"topology": [
"replicaset",
"sharded",
"load-balanced"
],
"maxServerVersion": "7.99.99"
"maxServerVersion": "8.99.99"
}
],
"database_name": "default",
Expand All @@ -25,10 +25,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberInt": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down Expand Up @@ -226,10 +229,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberInt": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down Expand Up @@ -283,10 +289,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberInt": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down Expand Up @@ -346,10 +355,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberInt": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down Expand Up @@ -383,12 +395,6 @@
"$$type": "binData"
},
"__safeContent__": [
{
"$binary": {
"base64": "5nRutVIyq7URVOVtbE4vM01APSIajAVnsShMwjBlzkM=",
"subType": "00"
}
},
{
"$binary": {
"base64": "RjBYT2h3ZAoHxhf8DU6/dFbDkEBZp0IxREcsRTu2MXs=",
Expand Down Expand Up @@ -445,12 +451,6 @@
"$$type": "binData"
},
"__safeContent__": [
{
"$binary": {
"base64": "bE1vqWj3KNyM7cCYUv/cnYm8BPaUL3eMp5syTHq6NF4=",
"subType": "00"
}
},
{
"$binary": {
"base64": "25j9sQXZCihCmHKvTHgaBsAVZFcGPn7JjHdrCGlwyyw=",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"runOn": [
{
"minServerVersion": "7.0.0",
"minServerVersion": "8.0.0",
"topology": [
"replicaset",
"sharded",
"load-balanced"
],
"maxServerVersion": "7.99.99"
"maxServerVersion": "8.99.99"
}
],
"database_name": "default",
Expand All @@ -25,10 +25,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberInt": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"runOn": [
{
"minServerVersion": "7.0.0",
"minServerVersion": "8.0.0",
"topology": [
"replicaset",
"sharded",
"load-balanced"
],
"maxServerVersion": "7.99.99"
"maxServerVersion": "8.99.99"
}
],
"database_name": "default",
Expand All @@ -25,10 +25,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberInt": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down Expand Up @@ -215,10 +218,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberInt": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down Expand Up @@ -272,10 +278,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberInt": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down Expand Up @@ -336,10 +345,13 @@
"path": "encryptedDate",
"bsonType": "date",
"queries": {
"queryType": "rangePreview",
"queryType": "range",
"contention": {
"$numberLong": "0"
},
"trimFactor": {
"$numberInt": "1"
},
"sparsity": {
"$numberLong": "1"
},
Expand Down Expand Up @@ -373,12 +385,6 @@
"$$type": "binData"
},
"__safeContent__": [
{
"$binary": {
"base64": "5nRutVIyq7URVOVtbE4vM01APSIajAVnsShMwjBlzkM=",
"subType": "00"
}
},
{
"$binary": {
"base64": "RjBYT2h3ZAoHxhf8DU6/dFbDkEBZp0IxREcsRTu2MXs=",
Expand Down
Loading