@@ -1403,11 +1403,20 @@ static bool _fle2_finalize_explicit(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *
1403
1403
_mongocrypt_buffer_copy_to (& ctx -> opts .key_id , & marking .u .fle2 .index_key_id );
1404
1404
}
1405
1405
1406
- if (ctx -> opts .contention_factor .set ) {
1406
+ // Handle contention factor:
1407
+ switch (ctx -> opts .index_type .value ) {
1408
+ case MONGOCRYPT_INDEX_TYPE_NONE :
1409
+ default :
1410
+ BSON_ASSERT (!ctx -> opts .contention_factor .set ); // Checked earlier in explicit_encrypt_init.
1411
+ break ;
1412
+
1413
+ case MONGOCRYPT_INDEX_TYPE_EQUALITY :
1414
+ case MONGOCRYPT_INDEX_TYPE_RANGEPREVIEW_DEPRECATED :
1415
+ case MONGOCRYPT_INDEX_TYPE_RANGE :
1416
+ case MONGOCRYPT_INDEX_TYPE_TEXTPREVIEW :
1417
+ // All QE indexed algorithms require contention factor.
1418
+ BSON_ASSERT (ctx -> opts .contention_factor .set ); // Checked earlier in explicit_encrypt_init.
1407
1419
marking .u .fle2 .maxContentionFactor = ctx -> opts .contention_factor .value ;
1408
- } else if (ctx -> opts .index_type .value == MONGOCRYPT_INDEX_TYPE_EQUALITY ) {
1409
- _mongocrypt_ctx_fail_w_msg (ctx , "contention factor required for indexed algorithm" );
1410
- goto fail ;
1411
1420
}
1412
1421
1413
1422
/* Convert marking to ciphertext. */
@@ -1906,6 +1915,7 @@ static bool explicit_encrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *ms
1906
1915
return _mongocrypt_ctx_fail_w_msg (ctx , "contention factor is required for indexed algorithm" );
1907
1916
}
1908
1917
1918
+ // Check required options for range algorithm are set:
1909
1919
if (ctx -> opts .index_type .set
1910
1920
&& (ctx -> opts .index_type .value == MONGOCRYPT_INDEX_TYPE_RANGE
1911
1921
|| ctx -> opts .index_type .value == MONGOCRYPT_INDEX_TYPE_RANGEPREVIEW_DEPRECATED )) {
@@ -1918,6 +1928,17 @@ static bool explicit_encrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *ms
1918
1928
}
1919
1929
}
1920
1930
1931
+ // Check required options for text algorithm are set:
1932
+ if (ctx -> opts .index_type .set && (ctx -> opts .index_type .value == MONGOCRYPT_INDEX_TYPE_TEXTPREVIEW )) {
1933
+ if (!ctx -> opts .contention_factor .set ) {
1934
+ return _mongocrypt_ctx_fail_w_msg (ctx , "contention factor is required for textPreview algorithm" );
1935
+ }
1936
+
1937
+ if (!ctx -> opts .textopts .set ) {
1938
+ return _mongocrypt_ctx_fail_w_msg (ctx , "text opts are required for textPreview algorithm" );
1939
+ }
1940
+ }
1941
+
1921
1942
if (ctx -> opts .rangeopts .set && !mc_validate_sparsity (ctx -> opts .rangeopts .value .sparsity , ctx -> status )) {
1922
1943
return _mongocrypt_ctx_fail (ctx );
1923
1944
}
0 commit comments