@@ -1403,11 +1403,20 @@ static bool _fle2_finalize_explicit(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *
14031403 _mongocrypt_buffer_copy_to (& ctx -> opts .key_id , & marking .u .fle2 .index_key_id );
14041404 }
14051405
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.
14071419 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 ;
14111420 }
14121421
14131422 /* Convert marking to ciphertext. */
@@ -1906,6 +1915,7 @@ static bool explicit_encrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *ms
19061915 return _mongocrypt_ctx_fail_w_msg (ctx , "contention factor is required for indexed algorithm" );
19071916 }
19081917
1918+ // Check required options for range algorithm are set:
19091919 if (ctx -> opts .index_type .set
19101920 && (ctx -> opts .index_type .value == MONGOCRYPT_INDEX_TYPE_RANGE
19111921 || 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
19181928 }
19191929 }
19201930
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+
19211942 if (ctx -> opts .rangeopts .set && !mc_validate_sparsity (ctx -> opts .rangeopts .value .sparsity , ctx -> status )) {
19221943 return _mongocrypt_ctx_fail (ctx );
19231944 }
0 commit comments