Skip to content

Commit dd787b5

Browse files
authored
MONGOCRYPT-711 remove implementation for Range-V1 (#978)
* remove Range-V1 implementation * update tests using Range-V1 to Range-V2 or remove if not applicable * test decryption of insert payloads with RangeV1 and RangeV2
1 parent 69d9984 commit dd787b5

File tree

97 files changed

+510
-866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+510
-866
lines changed

src/mc-efc-private.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ typedef struct {
5353
* into @efc. Fields are copied from @efc_bson. It is OK to free efc_bson after
5454
* this call. Fields are appended in reverse order to @efc->fields. Extra
5555
* unrecognized fields are not considered an error for forward compatibility. */
56-
bool mc_EncryptedFieldConfig_parse(mc_EncryptedFieldConfig_t *efc,
57-
const bson_t *efc_bson,
58-
mongocrypt_status_t *status,
59-
bool use_range_v2);
56+
bool mc_EncryptedFieldConfig_parse(mc_EncryptedFieldConfig_t *efc, const bson_t *efc_bson, mongocrypt_status_t *status);
6057

6158
void mc_EncryptedFieldConfig_cleanup(mc_EncryptedFieldConfig_t *efc);
6259

src/mc-efc.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ _parse_supported_query_types(bson_iter_t *iter, supported_query_type_flags *out,
7878
}
7979

8080
/* _parse_field parses and prepends one field document to efc->fields. */
81-
static bool
82-
_parse_field(mc_EncryptedFieldConfig_t *efc, bson_t *field, mongocrypt_status_t *status, bool use_range_v2) {
81+
static bool _parse_field(mc_EncryptedFieldConfig_t *efc, bson_t *field, mongocrypt_status_t *status) {
8382
supported_query_type_flags query_types = SUPPORTS_NO_QUERIES;
8483
bson_iter_t field_iter;
8584

@@ -141,8 +140,8 @@ _parse_field(mc_EncryptedFieldConfig_t *efc, bson_t *field, mongocrypt_status_t
141140
}
142141
}
143142

144-
if (query_types & SUPPORTS_RANGE_PREVIEW_DEPRECATED_QUERIES && use_range_v2) {
145-
// When rangev2 is enabled ("range") error if "rangePreview" is included.
143+
if (query_types & SUPPORTS_RANGE_PREVIEW_DEPRECATED_QUERIES) {
144+
// Error if the removed "rangePreview" is included.
146145
// This check is intended to give an easier-to-understand earlier error.
147146
CLIENT_ERR("Cannot use field '%s' with 'rangePreview' queries. 'rangePreview' is unsupported. Use 'range' "
148147
"instead. 'range' is not compatible with 'rangePreview' and requires recreating the collection.",
@@ -163,8 +162,7 @@ _parse_field(mc_EncryptedFieldConfig_t *efc, bson_t *field, mongocrypt_status_t
163162

164163
bool mc_EncryptedFieldConfig_parse(mc_EncryptedFieldConfig_t *efc,
165164
const bson_t *efc_bson,
166-
mongocrypt_status_t *status,
167-
bool use_range_v2) {
165+
mongocrypt_status_t *status) {
168166
bson_iter_t iter;
169167

170168
BSON_ASSERT_PARAM(efc);
@@ -189,7 +187,7 @@ bool mc_EncryptedFieldConfig_parse(mc_EncryptedFieldConfig_t *efc,
189187
if (!mc_iter_document_as_bson(&iter, &field, status)) {
190188
return false;
191189
}
192-
if (!_parse_field(efc, &field, status, use_range_v2)) {
190+
if (!_parse_field(efc, &field, status)) {
193191
return false;
194192
}
195193
// The first element of efc->fields contains the newly parsed field.

src/mc-fle2-encryption-placeholder-private.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ typedef struct {
8686
BSON_STATIC_ASSERT2(alignof_mc_FLE2RangeFindSpec_t,
8787
BSON_ALIGNOF(mc_FLE2RangeFindSpec_t) >= BSON_ALIGNOF(mc_FLE2RangeFindSpecEdgesInfo_t));
8888

89-
bool mc_FLE2RangeFindSpec_parse(mc_FLE2RangeFindSpec_t *out,
90-
const bson_iter_t *in,
91-
bool use_range_v2,
92-
mongocrypt_status_t *status);
89+
bool mc_FLE2RangeFindSpec_parse(mc_FLE2RangeFindSpec_t *out, const bson_iter_t *in, mongocrypt_status_t *status);
9390

9491
/** mc_FLE2RangeInsertSpec_t represents the range insert specification that is
9592
* encoded inside of a FLE2EncryptionPlaceholder. See
@@ -114,10 +111,7 @@ typedef struct {
114111
BSON_STATIC_ASSERT2(alignof_mc_FLE2RangeInsertSpec_t,
115112
BSON_ALIGNOF(mc_FLE2RangeInsertSpec_t) >= BSON_ALIGNOF(bson_iter_t));
116113

117-
bool mc_FLE2RangeInsertSpec_parse(mc_FLE2RangeInsertSpec_t *out,
118-
const bson_iter_t *in,
119-
bool use_range_v2,
120-
mongocrypt_status_t *status);
114+
bool mc_FLE2RangeInsertSpec_parse(mc_FLE2RangeInsertSpec_t *out, const bson_iter_t *in, mongocrypt_status_t *status);
121115

122116
// Note: For the substring/suffix/prefix insert specs, all lengths are in terms of number of UTF-8 codepoints, not
123117
// number of bytes.

src/mc-fle2-encryption-placeholder.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ bool mc_validate_sparsity(int64_t sparsity, mongocrypt_status_t *status) {
224224

225225
static bool mc_FLE2RangeFindSpecEdgesInfo_parse(mc_FLE2RangeFindSpecEdgesInfo_t *out,
226226
const bson_iter_t *in,
227-
bool use_range_v2,
228227
mongocrypt_status_t *status) {
229228
bson_iter_t iter;
230229
bool has_lowerBound = false, has_lbIncluded = false, has_upperBound = false, has_ubIncluded = false,
@@ -323,11 +322,6 @@ static bool mc_FLE2RangeFindSpecEdgesInfo_parse(mc_FLE2RangeFindSpecEdgesInfo_t
323322
// Do not error if precision is not present. Precision optional and only
324323
// applies to double/decimal128.
325324

326-
if (!use_range_v2 && out->trimFactor.set) {
327-
CLIENT_ERR(ERROR_PREFIX "'trimFactor' is not supported for QE range v1");
328-
return false;
329-
}
330-
331325
return true;
332326

333327
fail:
@@ -337,10 +331,7 @@ static bool mc_FLE2RangeFindSpecEdgesInfo_parse(mc_FLE2RangeFindSpecEdgesInfo_t
337331
#undef ERROR_PREFIX
338332
#define ERROR_PREFIX "Error parsing FLE2RangeFindSpec: "
339333

340-
bool mc_FLE2RangeFindSpec_parse(mc_FLE2RangeFindSpec_t *out,
341-
const bson_iter_t *in,
342-
bool use_range_v2,
343-
mongocrypt_status_t *status) {
334+
bool mc_FLE2RangeFindSpec_parse(mc_FLE2RangeFindSpec_t *out, const bson_iter_t *in, mongocrypt_status_t *status) {
344335
BSON_ASSERT_PARAM(out);
345336
BSON_ASSERT_PARAM(in);
346337

@@ -360,7 +351,7 @@ bool mc_FLE2RangeFindSpec_parse(mc_FLE2RangeFindSpec_t *out,
360351
BSON_ASSERT(field);
361352

362353
IF_FIELD(edgesInfo) {
363-
if (!mc_FLE2RangeFindSpecEdgesInfo_parse(&out->edgesInfo.value, &iter, use_range_v2, status)) {
354+
if (!mc_FLE2RangeFindSpecEdgesInfo_parse(&out->edgesInfo.value, &iter, status)) {
364355
goto fail;
365356
}
366357
out->edgesInfo.set = true;
@@ -422,10 +413,7 @@ bool mc_FLE2RangeFindSpec_parse(mc_FLE2RangeFindSpec_t *out,
422413
#undef ERROR_PREFIX
423414
#define ERROR_PREFIX "Error parsing FLE2RangeInsertSpec: "
424415

425-
bool mc_FLE2RangeInsertSpec_parse(mc_FLE2RangeInsertSpec_t *out,
426-
const bson_iter_t *in,
427-
bool use_range_v2,
428-
mongocrypt_status_t *status) {
416+
bool mc_FLE2RangeInsertSpec_parse(mc_FLE2RangeInsertSpec_t *out, const bson_iter_t *in, mongocrypt_status_t *status) {
429417
BSON_ASSERT_PARAM(out);
430418
BSON_ASSERT_PARAM(in);
431419

@@ -494,11 +482,6 @@ bool mc_FLE2RangeInsertSpec_parse(mc_FLE2RangeInsertSpec_t *out,
494482
// Do not error if precision is not present. Precision optional and only
495483
// applies to double/decimal128.
496484

497-
if (!use_range_v2 && out->trimFactor.set) {
498-
CLIENT_ERR(ERROR_PREFIX "'trimFactor' is not supported for QE range v1");
499-
return false;
500-
}
501-
502485
return true;
503486

504487
fail:

src/mc-fle2-find-range-payload-private-v2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ typedef struct {
101101

102102
void mc_FLE2FindRangePayloadV2_init(mc_FLE2FindRangePayloadV2_t *payload);
103103

104-
bool mc_FLE2FindRangePayloadV2_serialize(const mc_FLE2FindRangePayloadV2_t *payload, bson_t *out, bool use_range_v2);
104+
bool mc_FLE2FindRangePayloadV2_serialize(const mc_FLE2FindRangePayloadV2_t *payload, bson_t *out);
105105

106106
void mc_FLE2FindRangePayloadV2_cleanup(mc_FLE2FindRangePayloadV2_t *payload);
107107

src/mc-fle2-find-range-payload-v2.c

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void mc_FLE2FindRangePayloadV2_cleanup(mc_FLE2FindRangePayloadV2_t *payload) {
5353
return false; \
5454
}
5555

56-
bool mc_FLE2FindRangePayloadV2_serialize(const mc_FLE2FindRangePayloadV2_t *payload, bson_t *out, bool use_range_v2) {
56+
bool mc_FLE2FindRangePayloadV2_serialize(const mc_FLE2FindRangePayloadV2_t *payload, bson_t *out) {
5757
BSON_ASSERT_PARAM(out);
5858
BSON_ASSERT_PARAM(payload);
5959

@@ -131,39 +131,37 @@ bool mc_FLE2FindRangePayloadV2_serialize(const mc_FLE2FindRangePayloadV2_t *payl
131131
return false;
132132
}
133133

134-
if (use_range_v2) {
135-
// Encode parameters that were used to generate the mincover.
136-
// The crypto parameters are all optionally set. Find payloads may come in pairs (a lower and upper bound).
137-
// One of the pair includes the mincover. The other payload was not generated with crypto parameters.
134+
// Encode parameters that were used to generate the mincover.
135+
// The crypto parameters are all optionally set. Find payloads may come in pairs (a lower and upper bound).
136+
// One of the pair includes the mincover. The other payload was not generated with crypto parameters.
138137

139-
if (payload->sparsity.set) {
140-
if (!BSON_APPEND_INT64(out, "sp", payload->sparsity.value)) {
141-
return false;
142-
}
138+
if (payload->sparsity.set) {
139+
if (!BSON_APPEND_INT64(out, "sp", payload->sparsity.value)) {
140+
return false;
143141
}
142+
}
144143

145-
if (payload->precision.set) {
146-
if (!BSON_APPEND_INT32(out, "pn", payload->precision.value)) {
147-
return false;
148-
}
144+
if (payload->precision.set) {
145+
if (!BSON_APPEND_INT32(out, "pn", payload->precision.value)) {
146+
return false;
149147
}
148+
}
150149

151-
if (payload->trimFactor.set) {
152-
if (!BSON_APPEND_INT32(out, "tf", payload->trimFactor.value)) {
153-
return false;
154-
}
150+
if (payload->trimFactor.set) {
151+
if (!BSON_APPEND_INT32(out, "tf", payload->trimFactor.value)) {
152+
return false;
155153
}
154+
}
156155

157-
if (payload->indexMin.value_type != BSON_TYPE_EOD) {
158-
if (!BSON_APPEND_VALUE(out, "mn", &payload->indexMin)) {
159-
return false;
160-
}
156+
if (payload->indexMin.value_type != BSON_TYPE_EOD) {
157+
if (!BSON_APPEND_VALUE(out, "mn", &payload->indexMin)) {
158+
return false;
161159
}
160+
}
162161

163-
if (payload->indexMax.value_type != BSON_TYPE_EOD) {
164-
if (!BSON_APPEND_VALUE(out, "mx", &payload->indexMax)) {
165-
return false;
166-
}
162+
if (payload->indexMax.value_type != BSON_TYPE_EOD) {
163+
if (!BSON_APPEND_VALUE(out, "mx", &payload->indexMax)) {
164+
return false;
167165
}
168166
}
169167

src/mc-fle2-insert-update-payload-private-v2.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ const _mongocrypt_buffer_t *mc_FLE2InsertUpdatePayloadV2_decrypt(_mongocrypt_cry
158158

159159
bool mc_FLE2InsertUpdatePayloadV2_serialize(const mc_FLE2InsertUpdatePayloadV2_t *payload, bson_t *out);
160160

161-
bool mc_FLE2InsertUpdatePayloadV2_serializeForRange(const mc_FLE2InsertUpdatePayloadV2_t *payload,
162-
bson_t *out,
163-
bool use_range_v2);
161+
bool mc_FLE2InsertUpdatePayloadV2_serializeForRange(const mc_FLE2InsertUpdatePayloadV2_t *payload, bson_t *out);
164162

165163
bool mc_FLE2InsertUpdatePayloadV2_serializeForTextSearch(const mc_FLE2InsertUpdatePayloadV2_t *payload, bson_t *out);
166164

src/mc-fle2-insert-update-payload-v2.c

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ bool mc_FLE2InsertUpdatePayloadV2_serialize(const mc_FLE2InsertUpdatePayloadV2_t
330330
return true;
331331
}
332332

333-
bool mc_FLE2InsertUpdatePayloadV2_serializeForRange(const mc_FLE2InsertUpdatePayloadV2_t *payload,
334-
bson_t *out,
335-
bool use_range_v2) {
333+
bool mc_FLE2InsertUpdatePayloadV2_serializeForRange(const mc_FLE2InsertUpdatePayloadV2_t *payload, bson_t *out) {
336334
BSON_ASSERT_PARAM(out);
337335
BSON_ASSERT_PARAM(payload);
338336

@@ -376,34 +374,32 @@ bool mc_FLE2InsertUpdatePayloadV2_serializeForRange(const mc_FLE2InsertUpdatePay
376374
return false;
377375
}
378376

379-
if (use_range_v2) {
380-
// Encode parameters that were used to generate the payload.
381-
BSON_ASSERT(payload->sparsity.set);
382-
if (!BSON_APPEND_INT64(out, "sp", payload->sparsity.value)) {
383-
return false;
384-
}
385-
386-
// Precision may be unset.
387-
if (payload->precision.set) {
388-
if (!BSON_APPEND_INT32(out, "pn", payload->precision.value)) {
389-
return false;
390-
}
391-
}
377+
// Encode parameters that were used to generate the payload.
378+
BSON_ASSERT(payload->sparsity.set);
379+
if (!BSON_APPEND_INT64(out, "sp", payload->sparsity.value)) {
380+
return false;
381+
}
392382

393-
BSON_ASSERT(payload->trimFactor.set);
394-
if (!BSON_APPEND_INT32(out, "tf", payload->trimFactor.value)) {
383+
// Precision may be unset.
384+
if (payload->precision.set) {
385+
if (!BSON_APPEND_INT32(out, "pn", payload->precision.value)) {
395386
return false;
396387
}
388+
}
397389

398-
BSON_ASSERT(payload->indexMin.value_type != BSON_TYPE_EOD);
399-
if (!BSON_APPEND_VALUE(out, "mn", &payload->indexMin)) {
400-
return false;
401-
}
390+
BSON_ASSERT(payload->trimFactor.set);
391+
if (!BSON_APPEND_INT32(out, "tf", payload->trimFactor.value)) {
392+
return false;
393+
}
402394

403-
BSON_ASSERT(payload->indexMax.value_type != BSON_TYPE_EOD);
404-
if (!BSON_APPEND_VALUE(out, "mx", &payload->indexMax)) {
405-
return false;
406-
}
395+
BSON_ASSERT(payload->indexMin.value_type != BSON_TYPE_EOD);
396+
if (!BSON_APPEND_VALUE(out, "mn", &payload->indexMin)) {
397+
return false;
398+
}
399+
400+
BSON_ASSERT(payload->indexMax.value_type != BSON_TYPE_EOD);
401+
if (!BSON_APPEND_VALUE(out, "mx", &payload->indexMax)) {
402+
return false;
407403
}
408404

409405
return true;

src/mc-range-edge-generation-private.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ typedef struct {
5353

5454
// mc_getEdgesInt32 implements the Edge Generation algorithm described in
5555
// SERVER-67751 for int32_t.
56-
mc_edges_t *mc_getEdgesInt32(mc_getEdgesInt32_args_t args, mongocrypt_status_t *status, bool use_range_v2);
56+
mc_edges_t *mc_getEdgesInt32(mc_getEdgesInt32_args_t args, mongocrypt_status_t *status);
5757

5858
typedef struct {
5959
int64_t value;
@@ -65,7 +65,7 @@ typedef struct {
6565

6666
// mc_getEdgesInt64 implements the Edge Generation algorithm described in
6767
// SERVER-67751 for int64_t.
68-
mc_edges_t *mc_getEdgesInt64(mc_getEdgesInt64_args_t args, mongocrypt_status_t *status, bool use_range_v2);
68+
mc_edges_t *mc_getEdgesInt64(mc_getEdgesInt64_args_t args, mongocrypt_status_t *status);
6969

7070
typedef struct {
7171
double value;
@@ -78,7 +78,7 @@ typedef struct {
7878

7979
// mc_getEdgesDouble implements the Edge Generation algorithm described in
8080
// SERVER-67751 for double.
81-
mc_edges_t *mc_getEdgesDouble(mc_getEdgesDouble_args_t args, mongocrypt_status_t *status, bool use_range_v2);
81+
mc_edges_t *mc_getEdgesDouble(mc_getEdgesDouble_args_t args, mongocrypt_status_t *status);
8282

8383
#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT()
8484
typedef struct {
@@ -89,7 +89,7 @@ typedef struct {
8989
mc_optional_int32_t trimFactor;
9090
} mc_getEdgesDecimal128_args_t;
9191

92-
mc_edges_t *mc_getEdgesDecimal128(mc_getEdgesDecimal128_args_t args, mongocrypt_status_t *status, bool use_range_v2);
92+
mc_edges_t *mc_getEdgesDecimal128(mc_getEdgesDecimal128_args_t args, mongocrypt_status_t *status);
9393
#endif // MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
9494

9595
BSON_STATIC_ASSERT2(ull_is_u64, sizeof(uint64_t) == sizeof(unsigned long long));

0 commit comments

Comments
 (0)