libmongocrypt-helper 1.13.2.0.1001 → 1.14.0.0.1001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +8 -0
  3. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +5 -1
  4. data/ext/libmongocrypt/libmongocrypt/CODEOWNERS +4 -1
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +18 -17
  6. data/ext/libmongocrypt/libmongocrypt/README.md +8 -8
  7. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +7 -0
  8. data/ext/libmongocrypt/libmongocrypt/bindings/python/CONTRIBUTING.md +34 -0
  9. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/state_machine.py +6 -2
  10. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +18 -2
  11. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +9 -1
  12. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/options.py +14 -0
  13. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/state_machine.py +6 -2
  14. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +1 -1
  15. data/ext/libmongocrypt/libmongocrypt/bindings/python/sbom.json +8 -8
  16. data/ext/libmongocrypt/libmongocrypt/bindings/python/scripts/libmongocrypt-version.txt +1 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/python/{release.sh → scripts/release.sh} +9 -3
  18. data/ext/libmongocrypt/libmongocrypt/bindings/python/{synchro.py → scripts/synchro.py} +16 -9
  19. data/ext/libmongocrypt/libmongocrypt/bindings/python/scripts/synchro.sh +8 -0
  20. data/ext/libmongocrypt/libmongocrypt/bindings/python/scripts/update-version.sh +27 -0
  21. data/ext/libmongocrypt/libmongocrypt/bindings/python/scripts/update_binding.py +78 -0
  22. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +15 -0
  23. data/ext/libmongocrypt/libmongocrypt/doc/releasing.md +25 -18
  24. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version.py +39 -13
  25. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version_selftest.sh +1 -1
  26. data/ext/libmongocrypt/libmongocrypt/etc/cyclonedx.sbom.json +2 -2
  27. data/ext/libmongocrypt/libmongocrypt/kms-message/CMakeLists.txt +1 -1
  28. data/ext/libmongocrypt/libmongocrypt/kms-message/src/hexlify.c +5 -0
  29. data/ext/libmongocrypt/libmongocrypt/kms-message/src/hexlify.h +1 -1
  30. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_azure_request.c +1 -1
  31. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_gcp_request.c +1 -1
  32. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer.c +4 -2
  33. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_request.c +1 -2
  34. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message_private.h +5 -1
  35. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request.c +1 -1
  36. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_opt.c +1 -1
  37. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.c +2 -8
  38. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.h +9 -0
  39. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_response_parser.c +0 -1
  40. data/ext/libmongocrypt/libmongocrypt/kms-message/src/sort.c +7 -3
  41. data/ext/libmongocrypt/libmongocrypt/kms-message/src/sort.h +2 -0
  42. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kmip_reader_writer.c +8 -1
  43. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kms_assert.h +5 -4
  44. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kms_azure_online.c +1 -1
  45. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kms_gcp_online.c +1 -1
  46. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kms_kmip_request.c +4 -0
  47. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kms_kmip_response.c +3 -0
  48. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kms_kmip_response_parser.c +4 -0
  49. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kms_online_util.c +1 -1
  50. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kms_online_util.h +1 -1
  51. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kms_request.c +39 -39
  52. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +235 -65
  53. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +1 -1
  54. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +4 -2
  55. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +2 -2
  56. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +2 -2
  57. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +1 -4
  58. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +9 -11
  59. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +1 -0
  60. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +10 -8
  61. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +167 -176
  62. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +6 -17
  63. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +6 -17
  64. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +1 -1
  65. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +25 -26
  66. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +2 -1
  67. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-text-payload-private.h +122 -0
  68. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-text-payload.c +477 -0
  69. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +1 -3
  70. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +28 -43
  71. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +6 -17
  72. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +6 -5
  73. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +13 -10
  74. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +3 -2
  75. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +7 -6
  76. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-tag-and-encrypted-metadata-block.c +4 -3
  77. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +1 -1
  78. data/ext/libmongocrypt/libmongocrypt/src/mc-parse-utils-private.h +27 -0
  79. data/ext/libmongocrypt/libmongocrypt/src/mc-parse-utils.c +48 -0
  80. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +5 -5
  81. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +15 -20
  82. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +4 -6
  83. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +9 -18
  84. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +4 -5
  85. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +5 -9
  86. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +14 -19
  87. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +2 -4
  88. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +109 -119
  89. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +2 -2
  90. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +4 -2
  91. data/ext/libmongocrypt/libmongocrypt/src/mc-schema-broker-private.h +0 -3
  92. data/ext/libmongocrypt/libmongocrypt/src/mc-schema-broker.c +4 -14
  93. data/ext/libmongocrypt/libmongocrypt/src/mc-str-encode-string-sets-private.h +1 -1
  94. data/ext/libmongocrypt/libmongocrypt/src/mc-str-encode-string-sets.c +3 -3
  95. data/ext/libmongocrypt/libmongocrypt/src/mc-text-search-str-encode-private.h +8 -1
  96. data/ext/libmongocrypt/libmongocrypt/src/mc-text-search-str-encode.c +78 -2
  97. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +34 -16
  98. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +66 -74
  99. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +1 -1
  100. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +4 -2
  101. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +1 -1
  102. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +12 -1
  103. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +5 -0
  104. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +5 -5
  105. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +2 -5
  106. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +65 -58
  107. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +3 -3
  108. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +1 -1
  109. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +1 -1
  110. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -1
  111. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +4 -0
  112. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +1 -1
  113. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +4 -4
  114. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +29 -25
  115. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +3 -2
  116. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +6 -3
  117. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +48 -58
  118. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +12 -0
  119. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +5 -13
  120. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +19 -2
  121. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +9 -9
  122. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +3 -4
  123. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +285 -89
  124. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +0 -2
  125. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +0 -1
  126. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +1 -1
  127. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +4 -1
  128. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +47 -31
  129. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +2 -0
  130. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +1 -1
  131. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +3 -1
  132. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +1 -1
  133. data/ext/libmongocrypt/libmongocrypt/src/unicode/case-fold-map.c +1 -1
  134. data/ext/libmongocrypt/libmongocrypt/src/unicode/diacritic-fold-map.c +1 -1
  135. data/ext/libmongocrypt/libmongocrypt/src/unicode/fold.c +1 -1
  136. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +0 -14
  137. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-field-config-map.json +6 -1
  138. data/ext/libmongocrypt/libmongocrypt/test/data/explicit-decrypt/FLE2InsertUpdatePayloadV2-RangeV2.json +8 -0
  139. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +1 -1
  140. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +6 -4
  141. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +1 -1
  142. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +1 -1
  143. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +6 -4
  144. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +2 -2
  145. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +1 -1
  146. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +6 -4
  147. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +1 -1
  148. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +14 -6
  149. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +1 -1
  150. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +6 -4
  151. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +1 -1
  152. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +1 -1
  153. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +6 -4
  154. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +1 -1
  155. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +1 -1
  156. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +6 -4
  157. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +1 -1
  158. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +1 -1
  159. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +1 -1
  160. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +1 -1
  161. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +1 -1
  162. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +1 -1
  163. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +6 -4
  164. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +1 -1
  165. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +1 -1
  166. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +6 -4
  167. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +1 -1
  168. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +1 -1
  169. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +6 -4
  170. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +1 -1
  171. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +14 -6
  172. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +1 -1
  173. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +6 -4
  174. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +1 -1
  175. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +1 -1
  176. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +3 -3
  177. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +1 -1
  178. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +1 -1
  179. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +6 -4
  180. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +1 -1
  181. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +1 -1
  182. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +1 -1
  183. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +1 -1
  184. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +1 -1
  185. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +8 -0
  186. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +8 -0
  187. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +5 -5
  188. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +11 -5
  189. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +2 -2
  190. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +9 -11
  191. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-encryption-placeholder.c +18 -29
  192. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +1 -1
  193. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +2 -18
  194. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-text-payload.c +320 -0
  195. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +2 -17
  196. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +1 -1
  197. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +8 -5
  198. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +6 -10
  199. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +29 -33
  200. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +12 -20
  201. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +5 -20
  202. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +5 -5
  203. data/ext/libmongocrypt/libmongocrypt/test/test-mc-text-search-str-encode.c +147 -18
  204. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +35 -14
  205. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +10 -10
  206. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +3 -7
  207. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +36 -24
  208. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +4 -4
  209. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +2 -2
  210. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +13 -13
  211. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cleanup.c +49 -55
  212. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +64 -67
  213. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +18 -18
  214. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +4 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +4 -3
  216. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +13 -3
  217. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +31 -13
  218. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +35 -52
  219. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +28 -1
  220. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +50 -91
  221. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +1 -1
  222. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +7 -4
  223. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +1 -1
  224. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +1 -1
  225. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +3 -5
  226. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +2 -2
  227. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +1 -1
  228. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +2 -2
  229. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +527 -225
  230. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +1 -1
  231. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +45 -56
  232. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +12 -3
  233. data/ext/libmongocrypt/libmongocrypt/test/test-named-kms-providers.c +11 -11
  234. data/ext/libmongocrypt/libmongocrypt/test/test-unicode-fold.c +6 -2
  235. data/ext/libmongocrypt/libmongocrypt/test/util/HELP.autogen +1 -1
  236. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +1 -1
  237. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +5 -5
  238. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +7 -6
  239. data/lib/libmongocrypt_helper/version.rb +2 -2
  240. metadata +17 -13
  241. data/ext/libmongocrypt/libmongocrypt/bindings/python/libmongocrypt-version.txt +0 -1
  242. data/ext/libmongocrypt/libmongocrypt/bindings/python/strip_header.py +0 -50
  243. data/ext/libmongocrypt/libmongocrypt/bindings/python/update-sbom.sh +0 -14
  244. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload.json +0 -29
  245. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload.json +0 -29
  246. data/ext/libmongocrypt/libmongocrypt/test/data/explicit-decrypt/FLE2EqualityIndexedValueV2.json +0 -8
  247. data/ext/libmongocrypt/libmongocrypt/test/data/explicit-decrypt/FLE2RangeIndexedValueV2.json +0 -8
  248. /data/ext/libmongocrypt/libmongocrypt/bindings/python/{build-manylinux-wheel.sh → scripts/build-manylinux-wheel.sh} +0 -0
  249. /data/ext/libmongocrypt/libmongocrypt/test/data/explicit-decrypt/{FLE2InsertUpdatePayload-with-edges.json → FLE2InsertUpdatePayload-RangeV1.json} +0 -0
  250. /data/ext/libmongocrypt/libmongocrypt/test/data/explicit-decrypt/{FLE2InsertUpdatePayload-with-edges-V2.json → FLE2InsertUpdatePayloadV2-RangeV1.json} +0 -0
@@ -21,6 +21,7 @@
21
21
  #include "mc-fle2-find-equality-payload-private.h"
22
22
  #include "mc-fle2-find-range-payload-private-v2.h"
23
23
  #include "mc-fle2-find-range-payload-private.h"
24
+ #include "mc-fle2-find-text-payload-private.h"
24
25
  #include "mc-fle2-insert-update-payload-private-v2.h"
25
26
  #include "mc-fle2-insert-update-payload-private.h"
26
27
  #include "mc-fle2-payload-uev-private.h"
@@ -65,7 +66,7 @@ _mongocrypt_marking_parse_fle1_placeholder(const bson_t *in, _mongocrypt_marking
65
66
  BSON_ASSERT(field);
66
67
  if (0 == strcmp("ki", field)) {
67
68
  has_ki = true;
68
- if (!_mongocrypt_buffer_from_uuid_iter(&out->key_id, &iter)) {
69
+ if (!_mongocrypt_buffer_from_uuid_iter(&out->u.fle1.key_id, &iter)) {
69
70
  CLIENT_ERR("key id must be a UUID");
70
71
  return false;
71
72
  }
@@ -85,14 +86,14 @@ _mongocrypt_marking_parse_fle1_placeholder(const bson_t *in, _mongocrypt_marking
85
86
  }
86
87
  /* CDRIVER-3100 We must make a copy of this value; the result of
87
88
  * bson_iter_value is ephemeral. */
88
- bson_value_copy(value, &out->key_alt_name);
89
+ bson_value_copy(value, &out->u.fle1.key_alt_name);
89
90
  out->type = MONGOCRYPT_MARKING_FLE1_BY_ALTNAME;
90
91
  continue;
91
92
  }
92
93
 
93
94
  if (0 == strcmp("v", field)) {
94
95
  has_v = true;
95
- memcpy(&out->v_iter, &iter, sizeof(bson_iter_t));
96
+ memcpy(&out->u.fle1.v_iter, &iter, sizeof(bson_iter_t));
96
97
  continue;
97
98
  }
98
99
 
@@ -110,7 +111,7 @@ _mongocrypt_marking_parse_fle1_placeholder(const bson_t *in, _mongocrypt_marking
110
111
  CLIENT_ERR("invalid algorithm value: %d", algorithm);
111
112
  return false;
112
113
  }
113
- out->algorithm = (mongocrypt_encryption_algorithm_t)algorithm;
114
+ out->u.fle1.algorithm = (mongocrypt_encryption_algorithm_t)algorithm;
114
115
  continue;
115
116
  }
116
117
 
@@ -147,7 +148,7 @@ _mongocrypt_marking_parse_fle2_placeholder(const bson_t *in, _mongocrypt_marking
147
148
  BSON_ASSERT_PARAM(out);
148
149
 
149
150
  out->type = MONGOCRYPT_MARKING_FLE2_ENCRYPTION;
150
- return mc_FLE2EncryptionPlaceholder_parse(&out->fle2, in, status);
151
+ return mc_FLE2EncryptionPlaceholder_parse(&out->u.fle2, in, status);
151
152
  }
152
153
 
153
154
  bool _mongocrypt_marking_parse_unowned(const _mongocrypt_buffer_t *in,
@@ -191,13 +192,13 @@ void _mongocrypt_marking_cleanup(_mongocrypt_marking_t *marking) {
191
192
  return;
192
193
  }
193
194
  if (marking->type == MONGOCRYPT_MARKING_FLE2_ENCRYPTION) {
194
- mc_FLE2EncryptionPlaceholder_cleanup(&marking->fle2);
195
+ mc_FLE2EncryptionPlaceholder_cleanup(&marking->u.fle2);
195
196
  return;
196
197
  }
197
198
 
198
199
  // else FLE1
199
- _mongocrypt_buffer_cleanup(&marking->key_id);
200
- bson_value_destroy(&marking->key_alt_name);
200
+ _mongocrypt_buffer_cleanup(&marking->u.fle1.key_id);
201
+ bson_value_destroy(&marking->u.fle1.key_alt_name);
201
202
  }
202
203
 
203
204
  /**
@@ -278,7 +279,8 @@ DERIVE_TOKEN_IMPL(ESC)
278
279
  * Calculates:
279
280
  * E?CToken = HMAC(collectionLevel1Token, n)
280
281
  * E?CText<T>Token = HMAC(E?CToken, t)
281
- * E?CText<T>DerivedFromDataTokenAndContentionFactorToken = HMAC(HMAC(E?CText<T>Token, v) cf)
282
+ * E?CText<T>DerivedFromDataToken = HMAC(E?CText<T>Token, v)
283
+ * E?CText<T>DerivedFromDataTokenAndContentionFactorToken = HMAC(E?CText<T>DerivedFromDataToken, cf)
282
284
  *
283
285
  * E?C = EDC|ESC
284
286
  * n = 1 for EDC, 2 for ESC
@@ -286,7 +288,9 @@ DERIVE_TOKEN_IMPL(ESC)
286
288
  * t = 1 for Exact, 2 for Substring, 3 for Suffix, 4 for Prefix
287
289
  * cf = contentionFactor
288
290
  *
289
- * E?CText<T>DerivedFromDataTokenAndContentionFactorToken is saved to out.
291
+ * If {useContentionFactor} is False, E?CText<T>DerivedFromDataToken is saved to out, and
292
+ * {contentionFactor} is ignored.
293
+ * Otherwise, E?CText<T>DerivedFromDataTokenAndContentionFactorToken is saved to out.
290
294
  * Note that {out} is initialized even on failure.
291
295
  */
292
296
  #define DERIVE_TEXT_SEARCH_TOKEN_IMPL(Name, Type) \
@@ -294,13 +298,13 @@ DERIVE_TOKEN_IMPL(ESC)
294
298
  _mongocrypt_buffer_t *out, \
295
299
  const mc_CollectionsLevel1Token_t *level1Token, \
296
300
  const _mongocrypt_buffer_t *value, \
301
+ bool useContentionFactor, \
297
302
  int64_t contentionFactor, \
298
303
  mongocrypt_status_t *status) { \
299
304
  BSON_ASSERT_PARAM(crypto); \
300
305
  BSON_ASSERT_PARAM(out); \
301
306
  BSON_ASSERT_PARAM(level1Token); \
302
307
  BSON_ASSERT_PARAM(value); \
303
- BSON_ASSERT(contentionFactor >= 0); \
304
308
  \
305
309
  _mongocrypt_buffer_init(out); \
306
310
  \
@@ -313,13 +317,28 @@ DERIVE_TOKEN_IMPL(ESC)
313
317
  if (!textToken) { \
314
318
  return false; \
315
319
  } \
320
+ mc_##Name##Text##Type##DerivedFromDataToken_t *fromDataToken = \
321
+ mc_##Name##Text##Type##DerivedFromDataToken_new(crypto, textToken, value, status); \
322
+ mc_##Name##Text##Type##Token_destroy(textToken); \
323
+ if (!fromDataToken) { \
324
+ return false; \
325
+ } \
326
+ \
327
+ if (!useContentionFactor) { \
328
+ /* FindTextPayload uses *fromDataToken */ \
329
+ _mongocrypt_buffer_copy_to(mc_##Name##Text##Type##DerivedFromDataToken_get(fromDataToken), out); \
330
+ mc_##Name##Text##Type##DerivedFromDataToken_destroy(fromDataToken); \
331
+ return true; \
332
+ } \
333
+ \
334
+ BSON_ASSERT(contentionFactor >= 0); \
335
+ /* InsertUpdatePayload continues through *fromDataTokenAndContentionFactor */ \
316
336
  mc_##Name##Text##Type##DerivedFromDataTokenAndContentionFactorToken_t *fromDataAndContentionFactor = \
317
337
  mc_##Name##Text##Type##DerivedFromDataTokenAndContentionFactorToken_new(crypto, \
318
- textToken, \
319
- value, \
338
+ fromDataToken, \
320
339
  (uint64_t)contentionFactor, \
321
340
  status); \
322
- mc_##Name##Text##Type##Token_destroy(textToken); \
341
+ mc_##Name##Text##Type##DerivedFromDataToken_destroy(fromDataToken); \
323
342
  if (!fromDataAndContentionFactor) { \
324
343
  return false; \
325
344
  } \
@@ -495,7 +514,7 @@ static bool _fle2_placeholder_aes_aead_encrypt(_mongocrypt_key_broker_t *kb,
495
514
  // Range V2: p := EncryptCTR(ECOCToken, ESCDerivedFromDataTokenAndContentionFactor || isLeaf)
496
515
  static bool _fle2_derive_encrypted_token(_mongocrypt_crypto_t *crypto,
497
516
  _mongocrypt_buffer_t *out,
498
- bool use_range_v2,
517
+ bool concatentate_leaf,
499
518
  const mc_CollectionsLevel1Token_t *collectionsLevel1Token,
500
519
  const _mongocrypt_buffer_t *escDerivedToken,
501
520
  const _mongocrypt_buffer_t *eccDerivedToken,
@@ -512,7 +531,7 @@ static bool _fle2_derive_encrypted_token(_mongocrypt_crypto_t *crypto,
512
531
  const _mongocrypt_buffer_t *p = &tmp;
513
532
  if (!eccDerivedToken) {
514
533
  // FLE2v2
515
- if (use_range_v2 && is_leaf.set) {
534
+ if (concatentate_leaf && is_leaf.set) {
516
535
  // Range V2; concat isLeaf
517
536
  _mongocrypt_buffer_t isLeafBuf;
518
537
  if (!_mongocrypt_buffer_copy_from_data_and_size(&isLeafBuf, (uint8_t[]){is_leaf.value}, 1)) {
@@ -597,7 +616,7 @@ static bool _get_tokenKey(_mongocrypt_key_broker_t *kb,
597
616
  }
598
617
 
599
618
  if (indexKey.len != MONGOCRYPT_KEY_LEN) {
600
- CLIENT_ERR("invalid indexKey, expected len=%" PRIu32 ", got len=%" PRIu32, MONGOCRYPT_KEY_LEN, indexKey.len);
619
+ CLIENT_ERR("invalid indexKey, expected len=%d, got len=%" PRIu32, MONGOCRYPT_KEY_LEN, indexKey.len);
601
620
  _mongocrypt_buffer_cleanup(&indexKey);
602
621
  return false;
603
622
  }
@@ -737,7 +756,7 @@ static bool _mongocrypt_fle2_placeholder_to_insert_update_common(_mongocrypt_key
737
756
  if (!_fle2_derive_encrypted_token(
738
757
  crypto,
739
758
  &out->encryptedTokens,
740
- kb->crypt->opts.use_range_v2,
759
+ true,
741
760
  common->collectionsLevel1Token,
742
761
  &out->escDerivedToken,
743
762
  NULL, // unused in v2
@@ -801,7 +820,7 @@ static bool _mongocrypt_fle2_placeholder_to_insert_update_ciphertext(_mongocrypt
801
820
  BSON_ASSERT(kb->crypt);
802
821
  BSON_ASSERT(marking->type == MONGOCRYPT_MARKING_FLE2_ENCRYPTION);
803
822
 
804
- mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->fle2;
823
+ mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->u.fle2;
805
824
  _FLE2EncryptedPayloadCommon_t common = {{0}};
806
825
  mc_FLE2InsertUpdatePayloadV2_t payload;
807
826
  mc_FLE2InsertUpdatePayloadV2_init(&payload);
@@ -837,8 +856,7 @@ fail:
837
856
 
838
857
  // get_edges creates and returns edges from an FLE2RangeInsertSpec. Returns NULL
839
858
  // on error.
840
- static mc_edges_t *
841
- get_edges(mc_FLE2RangeInsertSpec_t *insertSpec, size_t sparsity, mongocrypt_status_t *status, bool use_range_v2) {
859
+ static mc_edges_t *get_edges(mc_FLE2RangeInsertSpec_t *insertSpec, size_t sparsity, mongocrypt_status_t *status) {
842
860
  BSON_ASSERT_PARAM(insertSpec);
843
861
 
844
862
  bson_type_t value_type = bson_iter_type(&insertSpec->v);
@@ -849,8 +867,7 @@ get_edges(mc_FLE2RangeInsertSpec_t *insertSpec, size_t sparsity, mongocrypt_stat
849
867
  .max = OPT_I32(bson_iter_int32(&insertSpec->max)),
850
868
  .sparsity = sparsity,
851
869
  .trimFactor = insertSpec->trimFactor},
852
- status,
853
- use_range_v2);
870
+ status);
854
871
  }
855
872
 
856
873
  else if (value_type == BSON_TYPE_INT64) {
@@ -859,8 +876,7 @@ get_edges(mc_FLE2RangeInsertSpec_t *insertSpec, size_t sparsity, mongocrypt_stat
859
876
  .max = OPT_I64(bson_iter_int64(&insertSpec->max)),
860
877
  .sparsity = sparsity,
861
878
  .trimFactor = insertSpec->trimFactor},
862
- status,
863
- use_range_v2);
879
+ status);
864
880
  }
865
881
 
866
882
  else if (value_type == BSON_TYPE_DATE_TIME) {
@@ -869,8 +885,7 @@ get_edges(mc_FLE2RangeInsertSpec_t *insertSpec, size_t sparsity, mongocrypt_stat
869
885
  .max = OPT_I64(bson_iter_date_time(&insertSpec->max)),
870
886
  .sparsity = sparsity,
871
887
  .trimFactor = insertSpec->trimFactor},
872
- status,
873
- use_range_v2);
888
+ status);
874
889
  }
875
890
 
876
891
  else if (value_type == BSON_TYPE_DOUBLE) {
@@ -886,11 +901,11 @@ get_edges(mc_FLE2RangeInsertSpec_t *insertSpec, size_t sparsity, mongocrypt_stat
886
901
  args.precision = insertSpec->precision;
887
902
  }
888
903
 
889
- return mc_getEdgesDouble(args, status, use_range_v2);
904
+ return mc_getEdgesDouble(args, status);
890
905
  }
891
906
 
892
907
  else if (value_type == BSON_TYPE_DECIMAL128) {
893
- #if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
908
+ #if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT()
894
909
  const mc_dec128 value = mc_dec128_from_bson_iter(&insertSpec->v);
895
910
  mc_getEdgesDecimal128_args_t args = {
896
911
  .value = value,
@@ -904,7 +919,7 @@ get_edges(mc_FLE2RangeInsertSpec_t *insertSpec, size_t sparsity, mongocrypt_stat
904
919
  args.max = OPT_MC_DEC128(max);
905
920
  args.precision = insertSpec->precision;
906
921
  }
907
- return mc_getEdgesDecimal128(args, status, use_range_v2);
922
+ return mc_getEdgesDecimal128(args, status);
908
923
  #else // ↑↑↑↑↑↑↑↑ With Decimal128 / Without ↓↓↓↓↓↓↓↓↓↓
909
924
  CLIENT_ERR("unsupported BSON type (Decimal128) for range: libmongocrypt "
910
925
  "was built without extended Decimal128 support");
@@ -936,9 +951,8 @@ static bool _mongocrypt_fle2_placeholder_to_insert_update_ciphertextForRange(_mo
936
951
  BSON_ASSERT_PARAM(ciphertext);
937
952
  BSON_ASSERT(kb->crypt);
938
953
  BSON_ASSERT(marking->type == MONGOCRYPT_MARKING_FLE2_ENCRYPTION);
939
- const bool use_range_v2 = kb->crypt->opts.use_range_v2;
940
954
 
941
- mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->fle2;
955
+ mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->u.fle2;
942
956
  _FLE2EncryptedPayloadCommon_t common = {{0}};
943
957
  mc_FLE2InsertUpdatePayloadV2_t payload;
944
958
  mc_FLE2InsertUpdatePayloadV2_init(&payload);
@@ -948,14 +962,14 @@ static bool _mongocrypt_fle2_placeholder_to_insert_update_ciphertextForRange(_mo
948
962
  // Parse the value ("v"), min ("min"), and max ("max") from
949
963
  // FLE2EncryptionPlaceholder for range insert.
950
964
  mc_FLE2RangeInsertSpec_t insertSpec;
951
- if (!mc_FLE2RangeInsertSpec_parse(&insertSpec, &placeholder->v_iter, use_range_v2, status)) {
965
+ if (!mc_FLE2RangeInsertSpec_parse(&insertSpec, &placeholder->v_iter, status)) {
952
966
  goto fail;
953
967
  }
954
968
 
955
969
  if (!_mongocrypt_fle2_placeholder_to_insert_update_common(kb,
956
970
  &payload,
957
971
  &common,
958
- &marking->fle2,
972
+ &marking->u.fle2,
959
973
  &insertSpec.v,
960
974
  status)) {
961
975
  goto fail;
@@ -964,7 +978,7 @@ static bool _mongocrypt_fle2_placeholder_to_insert_update_ciphertextForRange(_mo
964
978
  // g:= array<EdgeTokenSetV2>
965
979
  {
966
980
  BSON_ASSERT(placeholder->sparsity >= 0 && (uint64_t)placeholder->sparsity <= (uint64_t)SIZE_MAX);
967
- edges = get_edges(&insertSpec, (size_t)placeholder->sparsity, status, kb->crypt->opts.use_range_v2);
981
+ edges = get_edges(&insertSpec, (size_t)placeholder->sparsity, status);
968
982
  if (!edges) {
969
983
  goto fail;
970
984
  }
@@ -1007,7 +1021,7 @@ static bool _mongocrypt_fle2_placeholder_to_insert_update_ciphertextForRange(_mo
1007
1021
  // Or in Range V2: p := EncryptCTR(ECOCToken, ESCDerivedFromDataTokenAndContentionFactor || isLeaf)
1008
1022
  if (!_fle2_derive_encrypted_token(kb->crypt->crypto,
1009
1023
  &etc.encryptedTokens,
1010
- kb->crypt->opts.use_range_v2,
1024
+ true,
1011
1025
  edge_tokens.collectionsLevel1Token,
1012
1026
  &etc.escDerivedToken,
1013
1027
  NULL, // ecc unsed in FLE2v2
@@ -1039,7 +1053,7 @@ static bool _mongocrypt_fle2_placeholder_to_insert_update_ciphertextForRange(_mo
1039
1053
  {
1040
1054
  bson_t out;
1041
1055
  bson_init(&out);
1042
- mc_FLE2InsertUpdatePayloadV2_serializeForRange(&payload, &out, use_range_v2);
1056
+ mc_FLE2InsertUpdatePayloadV2_serializeForRange(&payload, &out);
1043
1057
  _mongocrypt_buffer_steal_from_bson(&ciphertext->data, &out);
1044
1058
  }
1045
1059
  // Do not set ciphertext->original_bson_type and ciphertext->key_id. They are
@@ -1087,6 +1101,7 @@ fail:
1087
1101
  &out->edcDerivedToken, \
1088
1102
  collLevel1Token, \
1089
1103
  value, \
1104
+ true, \
1090
1105
  contentionFactor, \
1091
1106
  status)) { \
1092
1107
  return false; \
@@ -1095,6 +1110,7 @@ fail:
1095
1110
  &out->escDerivedToken, \
1096
1111
  collLevel1Token, \
1097
1112
  value, \
1113
+ true, \
1098
1114
  contentionFactor, \
1099
1115
  status)) { \
1100
1116
  return false; \
@@ -1117,8 +1133,48 @@ fail:
1117
1133
  return false; \
1118
1134
  } \
1119
1135
  return true; \
1136
+ } \
1137
+ static bool _fle2_generate_Text##Type##FindTokenSet( \
1138
+ _mongocrypt_key_broker_t *kb, \
1139
+ mc_Text##Type##FindTokenSet_t *out, \
1140
+ const _mongocrypt_buffer_t *value, \
1141
+ const mc_CollectionsLevel1Token_t *collLevel1Token, \
1142
+ const mc_ServerTokenDerivationLevel1Token_t *serverLevel1Token, \
1143
+ mongocrypt_status_t *status) { \
1144
+ BSON_ASSERT_PARAM(kb); \
1145
+ BSON_ASSERT_PARAM(kb->crypt); \
1146
+ BSON_ASSERT_PARAM(out); \
1147
+ BSON_ASSERT_PARAM(value); \
1148
+ BSON_ASSERT_PARAM(collLevel1Token); \
1149
+ BSON_ASSERT_PARAM(serverLevel1Token); \
1150
+ if (!_fle2_derive_EDCText##Type##_token(kb->crypt->crypto, \
1151
+ &out->edcDerivedToken, \
1152
+ collLevel1Token, \
1153
+ value, \
1154
+ false, \
1155
+ 0, \
1156
+ status)) { \
1157
+ return false; \
1158
+ } \
1159
+ if (!_fle2_derive_ESCText##Type##_token(kb->crypt->crypto, \
1160
+ &out->escDerivedToken, \
1161
+ collLevel1Token, \
1162
+ value, \
1163
+ false, \
1164
+ 0, \
1165
+ status)) { \
1166
+ return false; \
1167
+ } \
1168
+ if (!_fle2_derive_serverText##Type##DerivedFromDataToken(kb->crypt->crypto, \
1169
+ &out->serverDerivedFromDataToken, \
1170
+ serverLevel1Token, \
1171
+ value, \
1172
+ status)) { \
1173
+ return false; \
1174
+ } \
1175
+ return true; \
1120
1176
  }
1121
- GENERATE_TEXT_SEARCH_TOKEN_SET_FOR_TYPE_IMPL(Exact);
1177
+ GENERATE_TEXT_SEARCH_TOKEN_SET_FOR_TYPE_IMPL(Exact)
1122
1178
  GENERATE_TEXT_SEARCH_TOKEN_SET_FOR_TYPE_IMPL(Substring)
1123
1179
  GENERATE_TEXT_SEARCH_TOKEN_SET_FOR_TYPE_IMPL(Suffix)
1124
1180
  GENERATE_TEXT_SEARCH_TOKEN_SET_FOR_TYPE_IMPL(Prefix)
@@ -1313,6 +1369,98 @@ fail:
1313
1369
  return res;
1314
1370
  }
1315
1371
 
1372
+ static bool _fle2_generate_TextSearchFindTokenSets(_mongocrypt_key_broker_t *kb,
1373
+ mc_TextSearchFindTokenSets_t *out,
1374
+ const _mongocrypt_buffer_t *indexKeyId,
1375
+ const mc_FLE2TextSearchInsertSpec_t *spec,
1376
+ mongocrypt_status_t *status) {
1377
+ BSON_ASSERT_PARAM(kb);
1378
+ BSON_ASSERT_PARAM(kb->crypt);
1379
+ BSON_ASSERT_PARAM(out);
1380
+ BSON_ASSERT_PARAM(indexKeyId);
1381
+ BSON_ASSERT_PARAM(spec);
1382
+
1383
+ _mongocrypt_crypto_t *crypto = kb->crypt->crypto;
1384
+ _FLE2EncryptedPayloadCommon_t common = {{0}};
1385
+ _mongocrypt_buffer_t asBsonValue = {0};
1386
+ bool res = false;
1387
+
1388
+ int operator_count = (int)spec->substr.set + (int)spec->suffix.set + (int)spec->prefix.set;
1389
+ if (operator_count > 1) {
1390
+ CLIENT_ERR("Text search query specification cannot contain multiple query type specifications");
1391
+ goto fail;
1392
+ }
1393
+
1394
+ if (!mc_text_search_str_query(spec, &asBsonValue, status)) {
1395
+ goto fail;
1396
+ }
1397
+
1398
+ // Start the token derivations
1399
+ if (!_get_tokenKey(kb, indexKeyId, &common.tokenKey, status)) {
1400
+ goto fail;
1401
+ }
1402
+
1403
+ common.collectionsLevel1Token = mc_CollectionsLevel1Token_new(crypto, &common.tokenKey, status);
1404
+ if (!common.collectionsLevel1Token) {
1405
+ CLIENT_ERR("unable to derive collectionLevel1Token");
1406
+ goto fail;
1407
+ }
1408
+
1409
+ common.serverTokenDerivationLevel1Token = mc_ServerTokenDerivationLevel1Token_new(crypto, &common.tokenKey, status);
1410
+ if (!common.serverTokenDerivationLevel1Token) {
1411
+ CLIENT_ERR("unable to derive serverTokenDerivationLevel1Token");
1412
+ goto fail;
1413
+ }
1414
+
1415
+ if (spec->substr.set) {
1416
+ if (!_fle2_generate_TextSubstringFindTokenSet(kb,
1417
+ &out->substring.value,
1418
+ &asBsonValue,
1419
+ common.collectionsLevel1Token,
1420
+ common.serverTokenDerivationLevel1Token,
1421
+ status)) {
1422
+ goto fail;
1423
+ }
1424
+ out->substring.set = true;
1425
+ } else if (spec->suffix.set) {
1426
+ if (!_fle2_generate_TextSuffixFindTokenSet(kb,
1427
+ &out->suffix.value,
1428
+ &asBsonValue,
1429
+ common.collectionsLevel1Token,
1430
+ common.serverTokenDerivationLevel1Token,
1431
+ status)) {
1432
+ goto fail;
1433
+ }
1434
+ out->suffix.set = true;
1435
+
1436
+ } else if (spec->prefix.set) {
1437
+ if (!_fle2_generate_TextPrefixFindTokenSet(kb,
1438
+ &out->prefix.value,
1439
+ &asBsonValue,
1440
+ common.collectionsLevel1Token,
1441
+ common.serverTokenDerivationLevel1Token,
1442
+ status)) {
1443
+ goto fail;
1444
+ }
1445
+ out->prefix.set = true;
1446
+ } else {
1447
+ if (!_fle2_generate_TextExactFindTokenSet(kb,
1448
+ &out->exact.value,
1449
+ &asBsonValue,
1450
+ common.collectionsLevel1Token,
1451
+ common.serverTokenDerivationLevel1Token,
1452
+ status)) {
1453
+ goto fail;
1454
+ }
1455
+ out->exact.set = true;
1456
+ }
1457
+ res = true;
1458
+ fail:
1459
+ _mongocrypt_buffer_cleanup(&asBsonValue);
1460
+ _FLE2EncryptedPayloadCommon_cleanup(&common);
1461
+ return res;
1462
+ }
1463
+
1316
1464
  /**
1317
1465
  * Payload subtype 11: FLE2InsertUpdatePayloadV2 for text search inserts/updates
1318
1466
  *
@@ -1335,7 +1483,7 @@ static bool _mongocrypt_fle2_placeholder_to_insert_update_ciphertextForTextSearc
1335
1483
  BSON_ASSERT(kb->crypt);
1336
1484
  BSON_ASSERT(marking->type == MONGOCRYPT_MARKING_FLE2_ENCRYPTION);
1337
1485
 
1338
- mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->fle2;
1486
+ mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->u.fle2;
1339
1487
  BSON_ASSERT(placeholder->type == MONGOCRYPT_FLE2_PLACEHOLDER_TYPE_INSERT);
1340
1488
  BSON_ASSERT(placeholder->algorithm == MONGOCRYPT_FLE2_ALGORITHM_TEXT_SEARCH);
1341
1489
 
@@ -1351,6 +1499,12 @@ static bool _mongocrypt_fle2_placeholder_to_insert_update_ciphertextForTextSearc
1351
1499
  goto fail;
1352
1500
  }
1353
1501
 
1502
+ // One of substr/suffix/prefix must be set for inserts
1503
+ if (!(insertSpec.substr.set || insertSpec.suffix.set || insertSpec.prefix.set)) {
1504
+ CLIENT_ERR("FLE2TextSearchInsertSpec is missing a substring, suffix, or prefix index specification");
1505
+ goto fail;
1506
+ }
1507
+
1354
1508
  // t
1355
1509
  payload.valueType = BSON_TYPE_UTF8;
1356
1510
 
@@ -1468,7 +1622,7 @@ static bool _mongocrypt_fle2_placeholder_to_find_ciphertext(_mongocrypt_key_brok
1468
1622
 
1469
1623
  _FLE2EncryptedPayloadCommon_t common = {{0}};
1470
1624
  _mongocrypt_buffer_t value = {0};
1471
- mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->fle2;
1625
+ mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->u.fle2;
1472
1626
  mc_FLE2FindEqualityPayloadV2_t payload;
1473
1627
  bool res = false;
1474
1628
 
@@ -1526,10 +1680,8 @@ static bool isInfinite(bson_iter_t *iter) {
1526
1680
 
1527
1681
  // mc_get_mincover_from_FLE2RangeFindSpec creates and returns a mincover from an
1528
1682
  // FLE2RangeFindSpec. Returns NULL on error.
1529
- mc_mincover_t *mc_get_mincover_from_FLE2RangeFindSpec(mc_FLE2RangeFindSpec_t *findSpec,
1530
- size_t sparsity,
1531
- mongocrypt_status_t *status,
1532
- bool use_range_v2) {
1683
+ mc_mincover_t *
1684
+ mc_get_mincover_from_FLE2RangeFindSpec(mc_FLE2RangeFindSpec_t *findSpec, size_t sparsity, mongocrypt_status_t *status) {
1533
1685
  BSON_ASSERT_PARAM(findSpec);
1534
1686
  BSON_ASSERT(findSpec->edgesInfo.set);
1535
1687
 
@@ -1590,8 +1742,7 @@ mc_mincover_t *mc_get_mincover_from_FLE2RangeFindSpec(mc_FLE2RangeFindSpec_t *fi
1590
1742
  .max = OPT_I32(bson_iter_int32(&findSpec->edgesInfo.value.indexMax)),
1591
1743
  .sparsity = sparsity,
1592
1744
  .trimFactor = findSpec->edgesInfo.value.trimFactor},
1593
- status,
1594
- use_range_v2);
1745
+ status);
1595
1746
 
1596
1747
  case BSON_TYPE_INT64:
1597
1748
  BSON_ASSERT(bson_iter_type(&lowerBound) == BSON_TYPE_INT64);
@@ -1607,8 +1758,7 @@ mc_mincover_t *mc_get_mincover_from_FLE2RangeFindSpec(mc_FLE2RangeFindSpec_t *fi
1607
1758
  .max = OPT_I64(bson_iter_int64(&findSpec->edgesInfo.value.indexMax)),
1608
1759
  .sparsity = sparsity,
1609
1760
  .trimFactor = findSpec->edgesInfo.value.trimFactor},
1610
- status,
1611
- use_range_v2);
1761
+ status);
1612
1762
  case BSON_TYPE_DATE_TIME:
1613
1763
  BSON_ASSERT(bson_iter_type(&lowerBound) == BSON_TYPE_DATE_TIME);
1614
1764
  BSON_ASSERT(bson_iter_type(&upperBound) == BSON_TYPE_DATE_TIME);
@@ -1623,8 +1773,7 @@ mc_mincover_t *mc_get_mincover_from_FLE2RangeFindSpec(mc_FLE2RangeFindSpec_t *fi
1623
1773
  .max = OPT_I64(bson_iter_date_time(&findSpec->edgesInfo.value.indexMax)),
1624
1774
  .sparsity = sparsity,
1625
1775
  .trimFactor = findSpec->edgesInfo.value.trimFactor},
1626
- status,
1627
- use_range_v2);
1776
+ status);
1628
1777
  case BSON_TYPE_DOUBLE: {
1629
1778
  BSON_ASSERT(bson_iter_type(&lowerBound) == BSON_TYPE_DOUBLE);
1630
1779
  BSON_ASSERT(bson_iter_type(&upperBound) == BSON_TYPE_DOUBLE);
@@ -1645,10 +1794,10 @@ mc_mincover_t *mc_get_mincover_from_FLE2RangeFindSpec(mc_FLE2RangeFindSpec_t *fi
1645
1794
  args.max = OPT_DOUBLE(bson_iter_double(&findSpec->edgesInfo.value.indexMax));
1646
1795
  args.precision = findSpec->edgesInfo.value.precision;
1647
1796
  }
1648
- return mc_getMincoverDouble(args, status, use_range_v2);
1797
+ return mc_getMincoverDouble(args, status);
1649
1798
  }
1650
1799
  case BSON_TYPE_DECIMAL128: {
1651
- #if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
1800
+ #if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT()
1652
1801
  BSON_ASSERT(bson_iter_type(&lowerBound) == BSON_TYPE_DECIMAL128);
1653
1802
  BSON_ASSERT(bson_iter_type(&upperBound) == BSON_TYPE_DECIMAL128);
1654
1803
  BSON_ASSERT(bson_iter_type(&findSpec->edgesInfo.value.indexMin) == BSON_TYPE_DECIMAL128);
@@ -1665,7 +1814,7 @@ mc_mincover_t *mc_get_mincover_from_FLE2RangeFindSpec(mc_FLE2RangeFindSpec_t *fi
1665
1814
  args.max = OPT_MC_DEC128(mc_dec128_from_bson_iter(&findSpec->edgesInfo.value.indexMax));
1666
1815
  args.precision = findSpec->edgesInfo.value.precision;
1667
1816
  }
1668
- return mc_getMincoverDecimal128(args, status, use_range_v2);
1817
+ return mc_getMincoverDecimal128(args, status);
1669
1818
  #else // ↑↑↑↑↑↑↑↑ With Decimal128 / Without ↓↓↓↓↓↓↓↓↓↓
1670
1819
  CLIENT_ERR("FLE2 find is not supported for Decimal128: libmongocrypt "
1671
1820
  "was built without Decimal128 support");
@@ -1708,8 +1857,7 @@ static bool _mongocrypt_fle2_placeholder_to_find_ciphertextForRange(_mongocrypt_
1708
1857
  BSON_ASSERT_PARAM(marking);
1709
1858
  BSON_ASSERT_PARAM(ciphertext);
1710
1859
 
1711
- const bool use_range_v2 = kb->crypt->opts.use_range_v2;
1712
- mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->fle2;
1860
+ mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->u.fle2;
1713
1861
  mc_FLE2FindRangePayloadV2_t payload;
1714
1862
  bool res = false;
1715
1863
  mc_mincover_t *mincover = NULL;
@@ -1724,7 +1872,7 @@ static bool _mongocrypt_fle2_placeholder_to_find_ciphertextForRange(_mongocrypt_
1724
1872
  // Parse the query bounds and index bounds from FLE2EncryptionPlaceholder for
1725
1873
  // range find.
1726
1874
  mc_FLE2RangeFindSpec_t findSpec;
1727
- if (!mc_FLE2RangeFindSpec_parse(&findSpec, &placeholder->v_iter, use_range_v2, status)) {
1875
+ if (!mc_FLE2RangeFindSpec_parse(&findSpec, &placeholder->v_iter, status)) {
1728
1876
  goto fail;
1729
1877
  }
1730
1878
 
@@ -1735,8 +1883,7 @@ static bool _mongocrypt_fle2_placeholder_to_find_ciphertextForRange(_mongocrypt_
1735
1883
  // g:= array<EdgeFindTokenSet>
1736
1884
  {
1737
1885
  BSON_ASSERT(placeholder->sparsity >= 0 && (uint64_t)placeholder->sparsity <= (uint64_t)SIZE_MAX);
1738
- mincover =
1739
- mc_get_mincover_from_FLE2RangeFindSpec(&findSpec, (size_t)placeholder->sparsity, status, use_range_v2);
1886
+ mincover = mc_get_mincover_from_FLE2RangeFindSpec(&findSpec, (size_t)placeholder->sparsity, status);
1740
1887
  if (!mincover) {
1741
1888
  goto fail;
1742
1889
  }
@@ -1785,14 +1932,12 @@ static bool _mongocrypt_fle2_placeholder_to_find_ciphertextForRange(_mongocrypt_
1785
1932
  }
1786
1933
  payload.payload.set = true;
1787
1934
 
1788
- if (use_range_v2) {
1789
- // Include "range" payload fields introduced in SERVER-91889.
1790
- payload.sparsity = OPT_I64(placeholder->sparsity);
1791
- payload.precision = findSpec.edgesInfo.value.precision;
1792
- payload.trimFactor = OPT_I32(mc_mincover_get_used_trimFactor(mincover));
1793
- bson_value_copy(bson_iter_value(&findSpec.edgesInfo.value.indexMin), &payload.indexMin);
1794
- bson_value_copy(bson_iter_value(&findSpec.edgesInfo.value.indexMax), &payload.indexMax);
1795
- }
1935
+ // Include "range" payload fields introduced in SERVER-91889.
1936
+ payload.sparsity = OPT_I64(placeholder->sparsity);
1937
+ payload.precision = findSpec.edgesInfo.value.precision;
1938
+ payload.trimFactor = OPT_I32(mc_mincover_get_used_trimFactor(mincover));
1939
+ bson_value_copy(bson_iter_value(&findSpec.edgesInfo.value.indexMin), &payload.indexMin);
1940
+ bson_value_copy(bson_iter_value(&findSpec.edgesInfo.value.indexMax), &payload.indexMax);
1796
1941
  }
1797
1942
 
1798
1943
  payload.payloadId = findSpec.payloadId;
@@ -1802,7 +1947,7 @@ static bool _mongocrypt_fle2_placeholder_to_find_ciphertextForRange(_mongocrypt_
1802
1947
  // Serialize.
1803
1948
  {
1804
1949
  bson_t out = BSON_INITIALIZER;
1805
- mc_FLE2FindRangePayloadV2_serialize(&payload, &out, use_range_v2);
1950
+ mc_FLE2FindRangePayloadV2_serialize(&payload, &out);
1806
1951
  _mongocrypt_buffer_steal_from_bson(&ciphertext->data, &out);
1807
1952
  }
1808
1953
  _mongocrypt_buffer_steal(&ciphertext->key_id, &placeholder->index_key_id);
@@ -1824,9 +1969,59 @@ static bool _mongocrypt_fle2_placeholder_to_find_ciphertextForTextSearch(_mongoc
1824
1969
  _mongocrypt_marking_t *marking,
1825
1970
  _mongocrypt_ciphertext_t *ciphertext,
1826
1971
  mongocrypt_status_t *status) {
1827
- // TODO MONGOCRYPT-761 implement find support for text search fields
1828
- CLIENT_ERR("Text search find is not yet supported");
1829
- return false;
1972
+ BSON_ASSERT_PARAM(kb);
1973
+ BSON_ASSERT_PARAM(marking);
1974
+ BSON_ASSERT_PARAM(ciphertext);
1975
+ BSON_ASSERT(kb->crypt);
1976
+ BSON_ASSERT(marking->type == MONGOCRYPT_MARKING_FLE2_ENCRYPTION);
1977
+
1978
+ bool res = false;
1979
+ mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->u.fle2;
1980
+ BSON_ASSERT(placeholder->type == MONGOCRYPT_FLE2_PLACEHOLDER_TYPE_FIND);
1981
+ BSON_ASSERT(placeholder->algorithm == MONGOCRYPT_FLE2_ALGORITHM_TEXT_SEARCH);
1982
+
1983
+ mc_FLE2FindTextPayload_t payload;
1984
+ mc_FLE2FindTextPayload_init(&payload);
1985
+
1986
+ mc_FLE2TextSearchInsertSpec_t spec;
1987
+ if (!mc_FLE2TextSearchInsertSpec_parse(&spec, &placeholder->v_iter, status)) {
1988
+ goto fail;
1989
+ }
1990
+
1991
+ if (!_fle2_generate_TextSearchFindTokenSets(kb, &payload.tokenSets, &placeholder->index_key_id, &spec, status)) {
1992
+ goto fail;
1993
+ }
1994
+
1995
+ payload.caseFold = spec.casef;
1996
+ payload.diacriticFold = spec.diacf;
1997
+ payload.maxContentionFactor = placeholder->maxContentionFactor;
1998
+ if (spec.substr.set) {
1999
+ payload.substringSpec.set = true;
2000
+ payload.substringSpec.value = spec.substr.value;
2001
+ } else if (spec.suffix.set) {
2002
+ payload.suffixSpec.set = true;
2003
+ payload.suffixSpec.value = spec.suffix.value;
2004
+ } else if (spec.prefix.set) {
2005
+ payload.prefixSpec.set = true;
2006
+ payload.prefixSpec.value = spec.prefix.value;
2007
+ }
2008
+
2009
+ // Serialize.
2010
+ {
2011
+ bson_t out = BSON_INITIALIZER;
2012
+ mc_FLE2FindTextPayload_serialize(&payload, &out);
2013
+ _mongocrypt_buffer_steal_from_bson(&ciphertext->data, &out);
2014
+ }
2015
+
2016
+ // Do not set ciphertext->original_bson_type and ciphertext->key_id. They are
2017
+ // not used for FLE2FindTextPayload.
2018
+ ciphertext->blob_subtype = MC_SUBTYPE_FLE2FindTextPayload;
2019
+
2020
+ res = true;
2021
+
2022
+ fail:
2023
+ mc_FLE2FindTextPayload_cleanup(&payload);
2024
+ return res;
1830
2025
  }
1831
2026
 
1832
2027
  static bool _mongocrypt_fle2_placeholder_to_FLE2UnindexedEncryptedValue(_mongocrypt_key_broker_t *kb,
@@ -1838,7 +2033,7 @@ static bool _mongocrypt_fle2_placeholder_to_FLE2UnindexedEncryptedValue(_mongocr
1838
2033
  BSON_ASSERT_PARAM(ciphertext);
1839
2034
 
1840
2035
  _mongocrypt_buffer_t plaintext = {0};
1841
- mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->fle2;
2036
+ mc_FLE2EncryptionPlaceholder_t *placeholder = &marking->u.fle2;
1842
2037
  _mongocrypt_buffer_t user_key = {0};
1843
2038
  bool res = false;
1844
2039
 
@@ -1904,12 +2099,13 @@ static bool _mongocrypt_fle1_marking_to_ciphertext(_mongocrypt_key_broker_t *kb,
1904
2099
  _mongocrypt_buffer_init(&key_id);
1905
2100
  _mongocrypt_buffer_init(&key_material);
1906
2101
 
1907
- /* Get the decrypted key for this marking. */
2102
+ /* Get the decrypted key for this marking.u.fle1. */
1908
2103
  if (marking->type == MONGOCRYPT_MARKING_FLE1_BY_ALTNAME) {
1909
- key_found = _mongocrypt_key_broker_decrypted_key_by_name(kb, &marking->key_alt_name, &key_material, &key_id);
1910
- } else if (!_mongocrypt_buffer_empty(&marking->key_id)) {
1911
- key_found = _mongocrypt_key_broker_decrypted_key_by_id(kb, &marking->key_id, &key_material);
1912
- _mongocrypt_buffer_copy_to(&marking->key_id, &key_id);
2104
+ key_found =
2105
+ _mongocrypt_key_broker_decrypted_key_by_name(kb, &marking->u.fle1.key_alt_name, &key_material, &key_id);
2106
+ } else if (!_mongocrypt_buffer_empty(&marking->u.fle1.key_id)) {
2107
+ key_found = _mongocrypt_key_broker_decrypted_key_by_id(kb, &marking->u.fle1.key_id, &key_material);
2108
+ _mongocrypt_buffer_copy_to(&marking->u.fle1.key_id, &key_id);
1913
2109
  } else {
1914
2110
  CLIENT_ERR("marking must have either key_id or key_alt_name");
1915
2111
  goto fail;
@@ -1920,11 +2116,11 @@ static bool _mongocrypt_fle1_marking_to_ciphertext(_mongocrypt_key_broker_t *kb,
1920
2116
  goto fail;
1921
2117
  }
1922
2118
 
1923
- ciphertext->original_bson_type = (uint8_t)bson_iter_type(&marking->v_iter);
1924
- if (marking->algorithm == MONGOCRYPT_ENCRYPTION_ALGORITHM_DETERMINISTIC) {
2119
+ ciphertext->original_bson_type = (uint8_t)bson_iter_type(&marking->u.fle1.v_iter);
2120
+ if (marking->u.fle1.algorithm == MONGOCRYPT_ENCRYPTION_ALGORITHM_DETERMINISTIC) {
1925
2121
  ciphertext->blob_subtype = MC_SUBTYPE_FLE1DeterministicEncryptedValue;
1926
2122
  } else {
1927
- BSON_ASSERT(marking->algorithm == MONGOCRYPT_ENCRYPTION_ALGORITHM_RANDOM);
2123
+ BSON_ASSERT(marking->u.fle1.algorithm == MONGOCRYPT_ENCRYPTION_ALGORITHM_RANDOM);
1928
2124
  ciphertext->blob_subtype = MC_SUBTYPE_FLE1RandomEncryptedValue;
1929
2125
  }
1930
2126
  _mongocrypt_buffer_copy_to(&key_id, &ciphertext->key_id);
@@ -1933,7 +2129,7 @@ static bool _mongocrypt_fle1_marking_to_ciphertext(_mongocrypt_key_broker_t *kb,
1933
2129
  goto fail;
1934
2130
  }
1935
2131
 
1936
- _mongocrypt_buffer_from_iter(&plaintext, &marking->v_iter);
2132
+ _mongocrypt_buffer_from_iter(&plaintext, &marking->u.fle1.v_iter);
1937
2133
  ciphertext->data.len = fle1->get_ciphertext_len(plaintext.len, status);
1938
2134
  if (ciphertext->data.len == 0) {
1939
2135
  goto fail;
@@ -1944,7 +2140,7 @@ static bool _mongocrypt_fle1_marking_to_ciphertext(_mongocrypt_key_broker_t *kb,
1944
2140
  ciphertext->data.owned = true;
1945
2141
 
1946
2142
  BSON_ASSERT(kb->crypt);
1947
- switch (marking->algorithm) {
2143
+ switch (marking->u.fle1.algorithm) {
1948
2144
  case MONGOCRYPT_ENCRYPTION_ALGORITHM_DETERMINISTIC:
1949
2145
  /* Use deterministic encryption. */
1950
2146
  _mongocrypt_buffer_resize(&iv, MONGOCRYPT_IV_LEN);
@@ -2019,11 +2215,11 @@ bool _mongocrypt_marking_to_ciphertext(void *ctx,
2019
2215
 
2020
2216
  switch (marking->type) {
2021
2217
  case MONGOCRYPT_MARKING_FLE2_ENCRYPTION:
2022
- switch (marking->fle2.algorithm) {
2218
+ switch (marking->u.fle2.algorithm) {
2023
2219
  case MONGOCRYPT_FLE2_ALGORITHM_UNINDEXED:
2024
2220
  return _mongocrypt_fle2_placeholder_to_FLE2UnindexedEncryptedValue(kb, marking, ciphertext, status);
2025
2221
  case MONGOCRYPT_FLE2_ALGORITHM_RANGE:
2026
- switch (marking->fle2.type) {
2222
+ switch (marking->u.fle2.type) {
2027
2223
  case MONGOCRYPT_FLE2_PLACEHOLDER_TYPE_INSERT:
2028
2224
  return _mongocrypt_fle2_placeholder_to_insert_update_ciphertextForRange(kb,
2029
2225
  marking,
@@ -2031,18 +2227,18 @@ bool _mongocrypt_marking_to_ciphertext(void *ctx,
2031
2227
  status);
2032
2228
  case MONGOCRYPT_FLE2_PLACEHOLDER_TYPE_FIND:
2033
2229
  return _mongocrypt_fle2_placeholder_to_find_ciphertextForRange(kb, marking, ciphertext, status);
2034
- default: CLIENT_ERR("unexpected fle2 type: %d", (int)marking->fle2.type); return false;
2230
+ default: CLIENT_ERR("unexpected fle2 type: %d", (int)marking->u.fle2.type); return false;
2035
2231
  }
2036
2232
  case MONGOCRYPT_FLE2_ALGORITHM_EQUALITY:
2037
- switch (marking->fle2.type) {
2233
+ switch (marking->u.fle2.type) {
2038
2234
  case MONGOCRYPT_FLE2_PLACEHOLDER_TYPE_INSERT:
2039
2235
  return _mongocrypt_fle2_placeholder_to_insert_update_ciphertext(kb, marking, ciphertext, status);
2040
2236
  case MONGOCRYPT_FLE2_PLACEHOLDER_TYPE_FIND:
2041
2237
  return _mongocrypt_fle2_placeholder_to_find_ciphertext(kb, marking, ciphertext, status);
2042
- default: CLIENT_ERR("unexpected fle2 type: %d", (int)marking->fle2.type); return false;
2238
+ default: CLIENT_ERR("unexpected fle2 type: %d", (int)marking->u.fle2.type); return false;
2043
2239
  }
2044
2240
  case MONGOCRYPT_FLE2_ALGORITHM_TEXT_SEARCH:
2045
- switch (marking->fle2.type) {
2241
+ switch (marking->u.fle2.type) {
2046
2242
  case MONGOCRYPT_FLE2_PLACEHOLDER_TYPE_INSERT:
2047
2243
  return _mongocrypt_fle2_placeholder_to_insert_update_ciphertextForTextSearch(kb,
2048
2244
  marking,
@@ -2050,9 +2246,9 @@ bool _mongocrypt_marking_to_ciphertext(void *ctx,
2050
2246
  status);
2051
2247
  case MONGOCRYPT_FLE2_PLACEHOLDER_TYPE_FIND:
2052
2248
  return _mongocrypt_fle2_placeholder_to_find_ciphertextForTextSearch(kb, marking, ciphertext, status);
2053
- default: CLIENT_ERR("unexpected fle2 type: %d", (int)marking->fle2.type); return false;
2249
+ default: CLIENT_ERR("unexpected fle2 type: %d", (int)marking->u.fle2.type); return false;
2054
2250
  }
2055
- default: CLIENT_ERR("unexpected algorithm: %d", (int)marking->algorithm); return false;
2251
+ default: CLIENT_ERR("unexpected algorithm: %d", (int)marking->u.fle1.algorithm); return false;
2056
2252
  }
2057
2253
  case MONGOCRYPT_MARKING_FLE1_BY_ID:
2058
2254
  case MONGOCRYPT_MARKING_FLE1_BY_ALTNAME: