libmongocrypt-helper 1.8.0.0.1001 → 1.11.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (385) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +33 -0
  3. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +12 -1
  4. data/ext/libmongocrypt/libmongocrypt/CODEOWNERS +1 -4
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +151 -3
  6. data/ext/libmongocrypt/libmongocrypt/README.md +36 -40
  7. data/ext/libmongocrypt/libmongocrypt/bindings/cs/CMakeLists.txt +1 -0
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Driver.snk +0 -0
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/AssemblyInfo.cs +2 -2
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Binary.cs +16 -2
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClientFactory.cs +8 -4
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +10 -0
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/LibraryLoader.cs +81 -44
  14. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/MongoDB.Libmongocrypt.csproj +2 -1
  15. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/MongoDB.Libmongocrypt.Test.csproj +2 -0
  16. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test32/MongoDB.Libmongocrypt.Test32.csproj +2 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/cs/README.md +3 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +21 -26
  19. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.config +3 -0
  20. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.sh +0 -0
  21. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/build.gradle.kts +28 -0
  22. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/java/com/mongodb/crypt/benchmark/BenchmarkRunner.java +217 -0
  23. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/resources/keyDocument.json +24 -0
  24. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +21 -6
  25. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.jar +0 -0
  26. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.properties +1 -1
  27. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew +154 -108
  28. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew.bat +7 -18
  29. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/settings.gradle.kts +1 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPI.java +41 -6
  31. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPIHelper.java +5 -5
  32. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CipherCallback.java +27 -1
  33. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoCryptImpl.java +34 -19
  34. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoExplicitEncryptOptions.java +6 -4
  35. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/jni-config.json +180 -0
  36. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/reflect-config.json +134 -0
  37. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +44 -2
  38. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +1 -1
  39. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/rangeopts.json +3 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +4 -900
  41. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +60 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +41 -20
  43. data/ext/libmongocrypt/libmongocrypt/bindings/python/RELEASE.rst +6 -24
  44. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +4 -13
  45. data/ext/libmongocrypt/libmongocrypt/bindings/python/hatch_build.py +36 -0
  46. data/ext/libmongocrypt/libmongocrypt/bindings/python/libmongocrypt-version.txt +1 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/__init__.py +2 -2
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/auto_encrypter.py +61 -0
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/credentials.py +156 -0
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/explicit_encrypter.py +156 -0
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/state_machine.py +149 -0
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/auto_encrypter.py +2 -46
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binary.py +14 -17
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +107 -61
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +6 -4
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/credentials.py +2 -121
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/crypto.py +31 -20
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/errors.py +2 -2
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +2 -233
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +168 -238
  61. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/options.py +265 -0
  62. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/state_machine.py +2 -141
  63. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/auto_encrypter.py +61 -0
  64. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/credentials.py +156 -0
  65. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/explicit_encrypter.py +156 -0
  66. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/state_machine.py +149 -0
  67. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  68. data/ext/libmongocrypt/libmongocrypt/bindings/python/pyproject.toml +118 -0
  69. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +97 -61
  70. data/ext/libmongocrypt/libmongocrypt/bindings/python/{test-requirements.txt → requirements-test.txt} +4 -1
  71. data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements.txt +4 -0
  72. data/ext/libmongocrypt/libmongocrypt/bindings/python/sbom.json +76 -0
  73. data/ext/libmongocrypt/libmongocrypt/bindings/python/strip_header.py +6 -7
  74. data/ext/libmongocrypt/libmongocrypt/bindings/python/synchro.py +64 -0
  75. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -0
  76. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/collection-info.json +1 -1
  77. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/command.json +1 -1
  78. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/compact/success/encrypted-payload.json +21 -21
  79. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-command-reply.json +1 -1
  80. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-field-config-map.json +1 -1
  81. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +1 -1
  82. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/rangeopts.json +3 -0
  83. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-rangePreview-explicit/int32/rangeopts.json +11 -0
  84. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-rangePreview-explicit/int32/value-to-encrypt.json +20 -0
  85. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-azure.json +1 -1
  86. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-gcp.json +1 -1
  87. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document.json +1 -1
  88. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-filter.json +1 -1
  89. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/list-collections-filter.json +1 -1
  90. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-command.json +1 -1
  91. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-reply.json +1 -1
  92. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/schema-map.json +1 -1
  93. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/keyDocument.json +24 -0
  94. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/perf_test.py +165 -0
  95. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_binding.py +8 -12
  96. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_crypto.py +9 -11
  97. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +988 -340
  98. data/ext/libmongocrypt/libmongocrypt/bindings/python/update-sbom.sh +14 -0
  99. data/ext/libmongocrypt/libmongocrypt/cmake/FetchMongoC.cmake +19 -1
  100. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +23 -0
  101. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +19 -227
  102. data/ext/libmongocrypt/libmongocrypt/cmake/Patch.cmake +54 -0
  103. data/ext/libmongocrypt/libmongocrypt/doc/img/cli-icon.png +0 -0
  104. data/ext/libmongocrypt/libmongocrypt/doc/img/reference-targets.png +0 -0
  105. data/ext/libmongocrypt/libmongocrypt/doc/releasing.md +153 -0
  106. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version.py +61 -28
  107. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version_selftest.sh +73 -0
  108. data/ext/libmongocrypt/libmongocrypt/etc/cyclonedx.sbom.json +108 -0
  109. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +1 -1
  110. data/ext/libmongocrypt/libmongocrypt/etc/libbson-remove-GCC-diagnostic-pragma.patch +27 -0
  111. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-alpine-arm-fix.patch +17 -0
  112. data/ext/libmongocrypt/libmongocrypt/etc/packager.py +120 -91
  113. data/ext/libmongocrypt/libmongocrypt/etc/purls.txt +14 -0
  114. data/ext/libmongocrypt/libmongocrypt/etc/repo_config.yaml +56 -0
  115. data/ext/libmongocrypt/libmongocrypt/etc/silk-create-asset-group.sh +70 -0
  116. data/ext/libmongocrypt/libmongocrypt/etc/ssdlc_compliance_report.md +37 -0
  117. data/ext/libmongocrypt/libmongocrypt/etc/third_party_vulnerabilities.md +42 -0
  118. data/ext/libmongocrypt/libmongocrypt/integrating.md +18 -1
  119. data/ext/libmongocrypt/libmongocrypt/kms-message/CMakeLists.txt +11 -3
  120. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_gcp_request.c +1 -1
  121. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer.c +17 -0
  122. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer_private.h +6 -0
  123. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_request.c +211 -1
  124. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_response.c +163 -0
  125. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_tag_type_private.h +2 -1
  126. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_request.h +17 -0
  127. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_response.h +6 -0
  128. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_port.c +3 -2
  129. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request.c +4 -2
  130. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.c +2 -2
  131. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kmip_reader_writer.c +23 -2
  132. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +13 -10
  133. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +1 -1
  134. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +16 -2
  135. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +94 -6
  136. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +15 -5
  137. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +114 -53
  138. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +1 -1
  139. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +1 -1
  140. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +2 -2
  141. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +2 -2
  142. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +21 -6
  143. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +5 -5
  144. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +38 -2
  145. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +1 -1
  146. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +20 -7
  147. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +8 -8
  148. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +89 -1
  149. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +3 -3
  150. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +1 -23
  151. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +4 -3
  152. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +15 -12
  153. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +11 -0
  154. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +16 -6
  155. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +64 -22
  156. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +23 -4
  157. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +359 -65
  158. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +26 -14
  159. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +17 -6
  160. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +31 -13
  161. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +16 -3
  162. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +259 -63
  163. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +40 -24
  164. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +57 -13
  165. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +17 -0
  166. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +5 -0
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +0 -5
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +5 -7
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +1 -0
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +16 -18
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +105 -76
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +9 -3
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +170 -89
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +5 -5
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +505 -124
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +31 -6
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +81 -13
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +7 -0
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +5 -1
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +161 -103
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +2 -7
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +191 -69
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +1 -1
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +50 -15
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +365 -69
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +2 -1
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +200 -107
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +50 -5
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +591 -15
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +6 -13
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +3 -2
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +47 -234
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +75 -24
  194. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +18 -2
  195. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +4 -0
  196. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/bypassQueryAnalysis/payload.json +53 -0
  197. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd-to-mongocryptd.json +23 -0
  198. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd.json +20 -0
  199. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd-to-mongocryptd.json +50 -0
  200. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd.json +20 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/collinfo.json +44 -0
  202. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-field-map.json +24 -0
  203. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-payload-pattern.json +53 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/mongocryptd-reply.json +62 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd-to-mongocryptd.json +30 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd.json +17 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/mongocryptd-reply.json +39 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/payload.json +21 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/missing-key-id/collinfo.json +20 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/collinfo.json +9 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/encrypted-payload.json +4 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/cmd.json +1 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/collinfo.json +63 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-field-config-map.json +61 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload-range-v2.json +37 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload.json +29 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/cmd.json +1 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/collinfo.json +64 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload-range-v2.json +105 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload.json +30 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/cmd.json +1 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/collinfo.json +49 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-field-config-map.json +47 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-payload.json +23 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/collinfo.json +15 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-field-config-map.json +10 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload-range-v2.json +104 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload.json +6 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/collinfo.json +4 -4
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +3 -3
  231. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/decrypt-response.txt +16 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/encrypt-response.txt +16 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/oauth-response.txt +19 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/cmd.json +9 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-field-map.json +19 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-payload.json +62 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/mongocryptd-reply.json +69 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/cmd.json +11 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-field-map.json +19 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-payload.json +40 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/mongocryptd-reply.json +47 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_decimal128.cstruct +1 -1
  243. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_double.cstruct +8637 -7958
  244. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int32.cstruct +5522 -1382
  245. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int64.cstruct +5042 -1262
  246. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128.cstruct +1 -1
  247. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128_precision.cstruct +1 -1
  248. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double.cstruct +1 -1
  249. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double_precision.cstruct +2 -2
  250. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int32.cstruct +1 -1
  251. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int64.cstruct +1 -1
  252. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/cmd.json +8 -0
  253. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-field-map.json +19 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-payload.json +53 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/mongocryptd-reply.json +58 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/cmd.json +11 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-field-map.json +19 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-payload.json +40 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/mongocryptd-reply.json +45 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/expected.json +26 -0
  261. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/to-encrypt.json +20 -0
  262. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/expected.json +26 -0
  263. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/to-encrypt.json +20 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-double/expected.json +8 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32/expected.json +8 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32-defaults/expected.json +8 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +7 -4
  268. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +9 -5
  269. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +9 -5
  270. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +1 -0
  271. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +8 -8
  272. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +6 -4
  273. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +43 -3
  274. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +76 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +5 -5
  276. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +89 -14
  277. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +342 -76
  278. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +94 -12
  279. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +205 -7
  280. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +49 -23
  281. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +16 -19
  282. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +22 -1
  283. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +94 -11
  284. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cleanup.c +374 -0
  285. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +121 -42
  286. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +134 -4
  287. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +40 -0
  288. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +16 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +11 -11
  290. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +8 -5
  291. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +922 -92
  292. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +2 -2
  293. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +114 -12
  294. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +14 -9
  295. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +424 -3
  296. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +1 -1
  297. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +447 -28
  298. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-opts.c +42 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +30 -26
  300. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +7 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +3 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +66 -14
  303. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +11 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/test-named-kms-providers.c +2381 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/util/HELP.autogen +3 -1
  306. data/ext/libmongocrypt/libmongocrypt/test/util/README.md +1 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +4 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/util/make_includes.py +1 -1
  309. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +38 -3
  310. data/lib/libmongocrypt_helper/version.rb +2 -2
  311. metadata +112 -106
  312. checksums.yaml.gz.sig +0 -0
  313. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +0 -1
  314. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +0 -79
  315. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +0 -105
  316. data/ext/libmongocrypt/libmongocrypt/bindings/node/LICENSE +0 -201
  317. data/ext/libmongocrypt/libmongocrypt/bindings/node/binding.gyp +0 -79
  318. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/README.hbs +0 -44
  319. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +0 -36
  320. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +0 -641
  321. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +0 -420
  322. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/buffer_pool.js +0 -123
  323. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +0 -821
  324. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +0 -98
  325. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/cryptoCallbacks.js +0 -87
  326. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +0 -75
  327. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +0 -73
  328. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js +0 -66
  329. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +0 -26
  330. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +0 -178
  331. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +0 -24
  332. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +0 -54
  333. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +0 -39
  334. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +0 -492
  335. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +0 -15302
  336. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +0 -100
  337. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +0 -956
  338. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.h +0 -114
  339. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +0 -950
  340. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/buffer_pool.test.js +0 -91
  341. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +0 -1093
  342. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +0 -94
  343. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +0 -240
  344. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/README.md +0 -5
  345. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/cmd.json +0 -6
  346. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/collection-info.json +0 -37
  347. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document-nested.json +0 -8
  348. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document.json +0 -11
  349. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encryptedFields.json +0 -30
  350. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key-document.json +0 -32
  351. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key1-document.json +0 -30
  352. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/mongocryptd-reply.json +0 -18
  353. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +0 -45
  354. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +0 -48
  355. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +0 -551
  356. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +0 -66
  357. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +0 -51
  358. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +0 -331
  359. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +0 -8
  360. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/mongodb_reporter.js +0 -325
  361. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +0 -63
  362. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +0 -89
  363. data/ext/libmongocrypt/libmongocrypt/debian/build_snapshot.sh +0 -79
  364. data/ext/libmongocrypt/libmongocrypt/debian/changelog +0 -105
  365. data/ext/libmongocrypt/libmongocrypt/debian/compat +0 -1
  366. data/ext/libmongocrypt/libmongocrypt/debian/control +0 -41
  367. data/ext/libmongocrypt/libmongocrypt/debian/copyright +0 -129
  368. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +0 -23
  369. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.dirs +0 -2
  370. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.install +0 -5
  371. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.dirs +0 -1
  372. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.install +0 -1
  373. data/ext/libmongocrypt/libmongocrypt/debian/rules +0 -46
  374. data/ext/libmongocrypt/libmongocrypt/debian/source/format +0 -1
  375. data/ext/libmongocrypt/libmongocrypt/debian/source/lintian-overrides +0 -3
  376. data/ext/libmongocrypt/libmongocrypt/debian/source/options +0 -1
  377. data/ext/libmongocrypt/libmongocrypt/debian/watch +0 -3
  378. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/mongocryptd-reply.json +0 -72
  379. data.tar.gz.sig +0 -1
  380. metadata.gz.sig +0 -0
  381. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-decrypt-reply.txt → test/data/kms-aws/decrypt-response.txt} +0 -0
  382. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-encrypt-reply.txt → test/data/kms-aws/encrypt-response.txt} +0 -0
  383. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/decrypt-response.txt +0 -0
  384. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/encrypt-response.txt +0 -0
  385. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/oauth-response.txt +0 -0
@@ -20,6 +20,7 @@
20
20
 
21
21
  #include <float.h> // DBL_MAX
22
22
  #include <math.h> // INFINITY, NAN
23
+ #include <stdint.h>
23
24
 
24
25
  typedef struct {
25
26
  mc_getTypeInfo32_args_t args;
@@ -193,16 +194,84 @@ static void _test_RangeTest_Encode_Int64(_mongocrypt_tester_t *tester) {
193
194
  }
194
195
  }
195
196
 
197
+ #define INT_64_MAX_DOUBLE (double)18446744073709551615ull
198
+
199
+ static void _test_canUsePrecisionModeDouble(_mongocrypt_tester_t *tester) {
200
+ #define CAN_USE_PRECISION_MODE(lb, ub, prc, expected, expected_bits_out) \
201
+ { \
202
+ uint32_t bits_out = 0; \
203
+ mongocrypt_status_t *const status = mongocrypt_status_new(); \
204
+ printf("_test_canUsePrecisionModeDecimal, min: %f, max: %f, prc: %" PRIu32, lb, ub, prc); \
205
+ bool result = mc_canUsePrecisionModeDouble(lb, ub, prc, &bits_out, status); \
206
+ ASSERT_OK_STATUS(mongocrypt_status_ok(status), status); \
207
+ ASSERT(result == expected); \
208
+ ASSERT_CMPINT32(expected_bits_out, ==, bits_out); \
209
+ mongocrypt_status_destroy(status); \
210
+ }
211
+
212
+ #define CAN_USE_PRECISION_MODE_ERRORS(lb, ub, prc, error) \
213
+ { \
214
+ mongocrypt_status_t *const status = mongocrypt_status_new(); \
215
+ printf("_test_canUsePrecisionModeDecimal errors, min: %f, max: %f, prc: %" PRIu32, lb, ub, prc); \
216
+ uint32_t bits_out = 0; \
217
+ bool result = mc_canUsePrecisionModeDouble(lb, ub, prc, &bits_out, status); \
218
+ ASSERT_OR_PRINT_MSG(!result, "expected error, but got none"); \
219
+ ASSERT_STATUS_CONTAINS(status, error); \
220
+ mongocrypt_status_destroy(status); \
221
+ }
222
+
223
+ CAN_USE_PRECISION_MODE(1.0, 16.0, 0, true, 4);
224
+ CAN_USE_PRECISION_MODE(0.0, 16.0, 0, true, 5);
225
+ // 2^53 + 1 is where double starts to lose precision, so we need to ensure that we get the
226
+ // correct value for max_bits out.
227
+ CAN_USE_PRECISION_MODE_ERRORS(1.0, 9007199254740992.0, 0, "Invalid upper bound for double precision. Absolute");
228
+ CAN_USE_PRECISION_MODE_ERRORS(0.0, 9007199254740992.0, 0, "Invalid upper bound for double precision. Absolute");
229
+
230
+ CAN_USE_PRECISION_MODE(2.718281, 314.159265, 6, true, 29);
231
+
232
+ CAN_USE_PRECISION_MODE_ERRORS(-1000000000.0,
233
+ 9223372036844775424.0,
234
+ 0,
235
+ "Invalid upper bound for double precision. Absolute");
236
+
237
+ CAN_USE_PRECISION_MODE_ERRORS(2.710000,
238
+ 314.150000,
239
+ 2,
240
+ "Invalid upper bound for double precision. Fractional digits");
241
+ CAN_USE_PRECISION_MODE_ERRORS(314.150000, 350.0, 2, "Invalid lower bound for double precision. Fractional digits");
242
+
243
+ CAN_USE_PRECISION_MODE_ERRORS((double)9007199254740992,
244
+ INT_64_MAX_DOUBLE,
245
+ 0,
246
+ "Invalid upper bound for double precision. Absolute scaled value");
247
+ CAN_USE_PRECISION_MODE_ERRORS(-1 * INT_64_MAX_DOUBLE,
248
+ 1.0,
249
+ 0,
250
+ "Invalid lower bound for double precision. Absolute scaled value");
251
+ CAN_USE_PRECISION_MODE_ERRORS(-92233720368547.0,
252
+ 92233720368547.0,
253
+ 5,
254
+ "Invalid upper bound for double precision. Absolute");
255
+
256
+ #undef CAN_USE_PRECISION_MODE
257
+ #undef CAN_USE_PRECISION_MODE_ERRORS
258
+ }
259
+
196
260
  typedef struct {
197
261
  double value;
198
262
  mc_optional_double_t min;
199
263
  mc_optional_double_t max;
200
- mc_optional_uint32_t precision;
264
+ mc_optional_int32_t precision;
201
265
  uint64_t expect;
202
266
  mc_optional_uint64_t expectMax;
203
267
  const char *expectError;
268
+ bool use_range_v1; // By default, use range v2.
204
269
  } DoubleTest;
205
270
 
271
+ // Smallest and Largest integer that fits in a double before precision is lost
272
+ #define DOUBLE_MIN_SAFE_INT -9007199254740992 // -2^53
273
+ #define DOUBLE_MAX_SAFE_INT 9007199254740992 // 2^53
274
+
206
275
  static void _test_RangeTest_Encode_Double(_mongocrypt_tester_t *tester) {
207
276
  DoubleTest tests[] = {/* Test cases copied from server Double_Bounds test ... begin */
208
277
  // Larger numbers map to larger uint64
@@ -254,43 +323,43 @@ static void _test_RangeTest_Encode_Double(_mongocrypt_tester_t *tester) {
254
323
 
255
324
  /* Test cases copied from Double_Bounds_Precision ... begin */
256
325
  {.value = 3.141592653589,
257
- .precision = OPT_U32_C(1),
326
+ .precision = OPT_I32_C(1),
258
327
  .min = OPT_DOUBLE_C(-100000),
259
328
  .max = OPT_DOUBLE_C(100000),
260
329
  .expect = UINT64_C(1000031),
261
330
  .expectMax = OPT_U64_C(2097151)},
262
331
  {.value = 3.141592653589,
263
- .precision = OPT_U32_C(2),
332
+ .precision = OPT_I32_C(2),
264
333
  .min = OPT_DOUBLE_C(-100000),
265
334
  .max = OPT_DOUBLE_C(100000),
266
335
  .expect = 10000314,
267
336
  .expectMax = OPT_U64_C(33554431)},
268
337
  {.value = 3.141592653589,
269
- .precision = OPT_U32_C(3),
338
+ .precision = OPT_I32_C(3),
270
339
  .min = OPT_DOUBLE_C(-100000),
271
340
  .max = OPT_DOUBLE_C(100000),
272
341
  .expect = 100003141,
273
342
  .expectMax = OPT_U64_C(268435455)},
274
343
  {.value = 3.141592653589,
275
- .precision = OPT_U32_C(4),
344
+ .precision = OPT_I32_C(4),
276
345
  .min = OPT_DOUBLE_C(-100000),
277
346
  .max = OPT_DOUBLE_C(100000),
278
347
  .expect = 1000031415,
279
348
  .expectMax = OPT_U64_C(2147483647)},
280
349
  {.value = 3.141592653589,
281
- .precision = OPT_U32_C(5),
350
+ .precision = OPT_I32_C(5),
282
351
  .min = OPT_DOUBLE_C(-100000),
283
352
  .max = OPT_DOUBLE_C(100000),
284
353
  .expect = 10000314159,
285
354
  .expectMax = OPT_U64_C(34359738367)},
286
355
  {.value = 3.141592653589,
287
- .precision = OPT_U32_C(6),
356
+ .precision = OPT_I32_C(6),
288
357
  .min = OPT_DOUBLE_C(-100000),
289
358
  .max = OPT_DOUBLE_C(100000),
290
359
  .expect = 100003141592,
291
360
  .expectMax = OPT_U64_C(274877906943)},
292
361
  {.value = 3.141592653589,
293
- .precision = OPT_U32_C(7),
362
+ .precision = OPT_I32_C(7),
294
363
  .min = OPT_DOUBLE_C(-100000),
295
364
  .max = OPT_DOUBLE_C(100000),
296
365
  .expect = 1000031415926,
@@ -298,113 +367,184 @@ static void _test_RangeTest_Encode_Double(_mongocrypt_tester_t *tester) {
298
367
  {.value = 0,
299
368
  .max = OPT_DOUBLE_C(1),
300
369
  .min = OPT_DOUBLE_C(-1),
301
- .precision = OPT_U32_C(3),
370
+ .precision = OPT_I32_C(3),
302
371
  .expect = 1000,
303
372
  .expectMax = OPT_U64_C(4095)},
304
373
  {.value = 0,
305
374
  .max = OPT_DOUBLE_C(1),
306
375
  .min = OPT_DOUBLE_C(-1E5),
307
- .precision = OPT_U32_C(3),
376
+ .precision = OPT_I32_C(3),
308
377
  .expect = 100000000,
309
378
  .expectMax = OPT_U64_C(134217727)},
310
379
  {.value = -1E-33,
311
380
  .max = OPT_DOUBLE_C(1),
312
381
  .min = OPT_DOUBLE_C(-1E5),
313
- .precision = OPT_U32_C(3),
382
+ .precision = OPT_I32_C(3),
314
383
  .expect = 100000000,
315
384
  .expectMax = OPT_U64_C(134217727)},
316
385
  {.value = 0,
317
386
  .max = OPT_DOUBLE_C(DBL_MAX),
318
387
  .min = OPT_DOUBLE_C(-DBL_MAX),
319
- .precision = OPT_U32_C(3),
320
- .expect = UINT64_C(9223372036854775808),
321
- // Expect precision not to be used.
322
- .expectMax = OPT_U64_C(UINT64_MAX)},
388
+ .precision = OPT_I32_C(3),
389
+ // Applying min/max/precision result in a domain needing >= 64 bits to represent.
390
+ // For range v2, expect an error.
391
+ .expectError = "Invalid upper bound for double precision."},
392
+ {.value = 0,
393
+ .max = OPT_DOUBLE_C(DBL_MAX),
394
+ .min = OPT_DOUBLE_C(-DBL_MAX),
395
+ .precision = OPT_I32_C(3),
396
+ // Applying min/max/precision result in a domain needing >= 64 bits to represent.
397
+ // For range v2, expect an error.
398
+ .expectError = "Invalid upper bound for double precision."},
323
399
  {.value = 3.141592653589,
324
400
  .max = OPT_DOUBLE_C(5),
325
401
  .min = OPT_DOUBLE_C(0),
326
- .precision = OPT_U32_C(0),
402
+ .precision = OPT_I32_C(0),
327
403
  .expect = 3,
328
404
  .expectMax = OPT_U64_C(7)},
329
405
  {.value = 3.141592653589,
330
406
  .max = OPT_DOUBLE_C(5),
331
407
  .min = OPT_DOUBLE_C(0),
332
- .precision = OPT_U32_C(1),
408
+ .precision = OPT_I32_C(1),
333
409
  .expect = 31,
334
410
  .expectMax = OPT_U64_C(63)},
335
411
  {.value = 3.141592653589,
336
412
  .max = OPT_DOUBLE_C(5),
337
413
  .min = OPT_DOUBLE_C(0),
338
- .precision = OPT_U32_C(2),
414
+ .precision = OPT_I32_C(2),
339
415
  .expect = 314,
340
416
  .expectMax = OPT_U64_C(1023)},
341
417
  {.value = 3.141592653589,
342
418
  .max = OPT_DOUBLE_C(5),
343
419
  .min = OPT_DOUBLE_C(0),
344
- .precision = OPT_U32_C(3),
420
+ .precision = OPT_I32_C(3),
345
421
  .expect = 3141,
346
422
  .expectMax = OPT_U64_C(8191)},
347
423
  {.value = 3.141592653589,
348
424
  .max = OPT_DOUBLE_C(5),
349
425
  .min = OPT_DOUBLE_C(0),
350
- .precision = OPT_U32_C(16),
351
- .expect = 31415926535890000,
352
- .expectMax = OPT_U64_C(72057594037927935)},
426
+ .precision = OPT_I32_C(16),
427
+ .expectError = "Invalid upper bound for double precision"},
353
428
  {.value = -5,
354
429
  .max = OPT_DOUBLE_C(-1),
355
430
  .min = OPT_DOUBLE_C(-10),
356
- .precision = OPT_U32_C(3),
431
+ .precision = OPT_I32_C(3),
357
432
  .expect = 5000,
358
433
  .expectMax = OPT_U64_C(16383)},
359
434
  {.value = 1E100,
360
435
  .max = OPT_DOUBLE_C(DBL_MAX),
361
436
  .min = OPT_DOUBLE_C(-DBL_MAX),
362
- .precision = OPT_U32_C(3),
363
- .expect = 15326393489903895421ULL,
364
- // Expect precision not to be used.
365
- .expectMax = OPT_U64_C(UINT64_MAX)},
437
+ .precision = OPT_I32_C(3),
438
+ // Applying min/max/precision result in a domain needing >= 64 bits to represent.
439
+ // For range v2, expect an error.
440
+ .expectError = "Invalid upper bound for double precision."},
441
+ {.value = 1E100,
442
+ .max = OPT_DOUBLE_C(DBL_MAX),
443
+ .min = OPT_DOUBLE_C(-DBL_MAX),
444
+ .precision = OPT_I32_C(3),
445
+ // Applying min/max/precision result in a domain needing >= 64 bits to represent.
446
+ // For range v2, expect an error.
447
+ .expectError = "Invalid upper bound for double precision."},
366
448
  {.value = 1E9,
367
449
  .max = OPT_DOUBLE_C(1E10),
368
450
  .min = OPT_DOUBLE_C(0),
369
- .precision = OPT_U32_C(3),
451
+ .precision = OPT_I32_C(3),
370
452
  .expect = 1000000000000,
371
453
  .expectMax = OPT_U64_C(17592186044415)},
372
454
  {.value = 1E9,
373
455
  .max = OPT_DOUBLE_C(1E10),
374
456
  .min = OPT_DOUBLE_C(0),
375
- .precision = OPT_U32_C(0),
457
+ .precision = OPT_I32_C(0),
376
458
  .expect = 1000000000,
377
459
  .expectMax = OPT_U64_C(17179869183)},
378
460
  {.value = -5,
379
461
  .max = OPT_DOUBLE_C(10),
380
462
  .min = OPT_DOUBLE_C(-10),
381
- .precision = OPT_U32_C(0),
463
+ .precision = OPT_I32_C(0),
382
464
  .expect = 5,
383
465
  .expectMax = OPT_U64_C(31)},
384
466
  {.value = -5,
385
467
  .max = OPT_DOUBLE_C(10),
386
468
  .min = OPT_DOUBLE_C(-10),
387
- .precision = OPT_U32_C(2),
469
+ .precision = OPT_I32_C(2),
388
470
  .expect = 500,
389
471
  .expectMax = OPT_U64_C(4095)},
390
472
  {.value = 1E-30,
391
473
  .max = OPT_DOUBLE_C(10E-30),
392
474
  .min = OPT_DOUBLE_C(1E-30),
393
- .precision = OPT_U32_C(35),
394
- .expect = 13381399884061196960ULL,
395
- // Expect precision not to be used.
396
- .expectMax = OPT_U64_C(UINT64_MAX)},
475
+ .precision = OPT_I32_C(35),
476
+ // Applying min/max/precision result in a domain needing >= 53 bits to represent.
477
+ // For range v2, expect an error.
478
+ .expectError = "Invalid upper bound for double precision."},
479
+ {.value = 1E-30,
480
+ .max = OPT_DOUBLE_C(10E-30),
481
+ .min = OPT_DOUBLE_C(1E-30),
482
+ .precision = OPT_I32_C(35),
483
+ // Applying min/max/precision result in a domain needing >= 53 bits to represent.
484
+ // For range v2, expect an error.
485
+ .expectError = "Invalid upper bound for double precision."},
486
+ /* Test max and min integer bounds for doubles */
487
+ {.value = DOUBLE_MIN_SAFE_INT,
488
+ .max = OPT_DOUBLE_C(DOUBLE_MAX_SAFE_INT),
489
+ .min = OPT_DOUBLE_C(DOUBLE_MIN_SAFE_INT),
490
+ .precision = OPT_I32_C(0),
491
+ .expect = 0,
492
+ // Applying min/max/precision result in a domain needing >= 53 bits to represent.
493
+ // For range v2, expect an error.
494
+ .expectError = "Invalid upper bound for double precision. Absolute"},
495
+ {.value = 900719925474099.6,
496
+ .max = OPT_DOUBLE_C(900719925474100.0),
497
+ .min = OPT_DOUBLE_C(900719925474099.0),
498
+ .precision = OPT_I32_C(0),
499
+ .expect = 0,
500
+ .expectMax = OPT_U64_C(1)},
501
+ // Domain size is small but min/max * 10^precision loses precision.
502
+ {.value = 900719925474099.6,
503
+ .max = OPT_DOUBLE_C(900719925474100.0),
504
+ .min = OPT_DOUBLE_C(900719925474099.0),
505
+ .precision = OPT_I32_C(1),
506
+ .expectError = "Invalid upper bound for double precision. Absolute"},
507
+ {.value = -900719925474099.6,
508
+ .max = OPT_DOUBLE_C(-900719925474099.0),
509
+ .min = OPT_DOUBLE_C(-900719925474100.0),
510
+ .precision = OPT_I32_C(1),
511
+ .expectError = "Invalid lower bound for double precision. Absolute"},
512
+ // 2^52
513
+ // The expected values increase by 4503599627370496 * 2^(i-52) + j
514
+ // i.e. the gaps between integers as the exponent increases since doubles lose precision as
515
+ // the exponent increases
516
+ {.value = 0,
517
+ .max = OPT_DOUBLE_C(4503599627370496),
518
+ .min = OPT_DOUBLE_C(-4503599627370496),
519
+ .precision = OPT_I32_C(0),
520
+ .expect = 0,
521
+ // Applying min/max/precision result in a domain needing >= 53 bits to represent.
522
+ // For range v2, expect an error.
523
+ .expectError = "The domain of double values specified by the min"},
397
524
  /* Test cases copied from Double_Bounds_Precision ... end */
398
525
  {.value = -1,
399
526
  .min = OPT_DOUBLE_C(0),
400
527
  .max = OPT_DOUBLE_C(200),
401
- .precision = OPT_U32_C(1),
528
+ .precision = OPT_I32_C(1),
402
529
  .expectError = "greater than or equal to the minimum value"},
403
530
  {.value = -1,
404
531
  .min = OPT_DOUBLE_C(0),
405
532
  .max = OPT_DOUBLE_C(201),
406
- .precision = OPT_U32_C(1),
407
- .expectError = "less than or equal to the maximum value"}};
533
+ .precision = OPT_I32_C(1),
534
+ .expectError = "less than or equal to the maximum value"},
535
+ {// Expect error due to precision exceeding INT32_MAX.
536
+ .value = 1,
537
+ .min = OPT_DOUBLE_C(1),
538
+ .max = OPT_DOUBLE_C(2),
539
+ .precision = OPT_I32_C(-1),
540
+ .expectError = "Precision must be non-negative"},
541
+ {// Expect error due to precision exceeding max finite double.
542
+ // The largest double value is 1.7976931348623157x10^308. 10^309 results in infinity.
543
+ .value = 1,
544
+ .min = OPT_DOUBLE_C(0),
545
+ .max = OPT_DOUBLE_C(1),
546
+ .precision = OPT_I32_C(309),
547
+ .expectError = "Precision is too large"}};
408
548
 
409
549
  for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
410
550
  DoubleTest *test = tests + i;
@@ -421,13 +561,15 @@ static void _test_RangeTest_Encode_Double(_mongocrypt_tester_t *tester) {
421
561
  printf("_test_RangeTest_Encode_Double: value=%f\n", test->value);
422
562
  }
423
563
 
564
+ const bool use_range_v2 = !test->use_range_v1;
424
565
  mc_OSTType_Double got;
425
566
  const bool ok = mc_getTypeInfoDouble((mc_getTypeInfoDouble_args_t){.value = test->value,
426
567
  .min = test->min,
427
568
  .max = test->max,
428
569
  .precision = test->precision},
429
570
  &got,
430
- status);
571
+ status,
572
+ use_range_v2);
431
573
  if (test->expectError) {
432
574
  ASSERT_OR_PRINT_MSG(!ok, "expected error, but got none");
433
575
  ASSERT_STATUS_CONTAINS(status, test->expectError);
@@ -446,11 +588,88 @@ typedef struct {
446
588
  mc_dec128 value;
447
589
  mc_optional_dec128_t min;
448
590
  mc_optional_dec128_t max;
449
- mc_optional_uint32_t precision;
591
+ mc_optional_int32_t precision;
450
592
  mlib_int128 expect;
451
593
  const char *expectError;
594
+ bool use_range_v1; // By default, use range v2.
452
595
  } Decimal128Test;
453
596
 
597
+ static void _test_canUsePrecisionModeDecimal(_mongocrypt_tester_t *tester) {
598
+ #define CAN_USE_PRECISION_MODE(lb, ub, prc, expected, expected_bits_out) \
599
+ { \
600
+ uint32_t bits_out = 0; \
601
+ mongocrypt_status_t *const status = mongocrypt_status_new(); \
602
+ printf("_test_canUsePrecisionModeDecimal, min: %s, max: %s, prc: %" PRIu32, \
603
+ mc_dec128_to_string(lb).str, \
604
+ mc_dec128_to_string(ub).str, \
605
+ prc); \
606
+ bool result = mc_canUsePrecisionModeDecimal(lb, ub, prc, &bits_out, status); \
607
+ ASSERT_OK_STATUS(mongocrypt_status_ok(status), status); \
608
+ ASSERT(result == expected); \
609
+ ASSERT_CMPINT32(expected_bits_out, ==, bits_out); \
610
+ mongocrypt_status_destroy(status); \
611
+ }
612
+
613
+ #define CAN_USE_PRECISION_MODE_ERRORS(lb, ub, prc, error) \
614
+ { \
615
+ mongocrypt_status_t *const status = mongocrypt_status_new(); \
616
+ printf("_test_canUsePrecisionModeDecimal errors, min: %s, max: %s, prc: %" PRIu32, \
617
+ mc_dec128_to_string(lb).str, \
618
+ mc_dec128_to_string(ub).str, \
619
+ prc); \
620
+ uint32_t bits_out = 0; \
621
+ bool result = mc_canUsePrecisionModeDecimal(lb, ub, prc, &bits_out, status); \
622
+ ASSERT_OR_PRINT_MSG(!result, "expected error, but got none"); \
623
+ ASSERT_STATUS_CONTAINS(status, error); \
624
+ mongocrypt_status_destroy(status); \
625
+ }
626
+
627
+ CAN_USE_PRECISION_MODE(MC_DEC128(1), MC_DEC128(16), 0, true, 4);
628
+ CAN_USE_PRECISION_MODE(MC_DEC128(0), MC_DEC128(16), 0, true, 5);
629
+
630
+ // It is unclear where Decimal128 looses precision, so we choose an arbitrarily large value
631
+ // and make sure that max_bits is correct for that boundary.
632
+ CAN_USE_PRECISION_MODE(MC_DEC128(1), mc_dec128_from_string("324518553658426726783156020576256"), 0, true, 108);
633
+ CAN_USE_PRECISION_MODE(MC_DEC128(0), mc_dec128_from_string("324518553658426726783156020576256"), 0, true, 109);
634
+
635
+ CAN_USE_PRECISION_MODE(mc_dec128_from_string("-100000000000000000000000000000000"),
636
+ mc_dec128_from_string("170141183460469231731687303715880000000"),
637
+ 0,
638
+ false,
639
+ 128);
640
+
641
+ CAN_USE_PRECISION_MODE_ERRORS(mc_dec128_from_string("788545.12392843"),
642
+ mc_dec128_from_string("4607431769000000.129834923"),
643
+ 4,
644
+ "Invalid upper bound for Decimal128 precision. Fractional digits");
645
+ CAN_USE_PRECISION_MODE_ERRORS(mc_dec128_from_string("788545.12392843"),
646
+ mc_dec128_from_string("7885451.2"),
647
+ 4,
648
+ "Invalid lower bound for Decimal128 precision. Fractional digits");
649
+ CAN_USE_PRECISION_MODE_ERRORS(mc_dec128_from_string("324518553658426726783156020576256"),
650
+ mc_dec128_from_string("340282366920938463463374607431768211455"),
651
+ 10,
652
+ "Invalid upper bound for Decimal128 precision. Absolute scaled");
653
+
654
+ CAN_USE_PRECISION_MODE_ERRORS(mc_dec128_from_string("-340282366920938463463374607431768211455"),
655
+ mc_dec128_from_string("-3245185536584267267831560"),
656
+ 10,
657
+ "Invalid lower bound for Decimal128 precision. Absolute scaled");
658
+
659
+ CAN_USE_PRECISION_MODE_ERRORS(mc_dec128_from_string("-17014118346046923173168730371588.0000000"),
660
+ mc_dec128_from_string("17014118346046923173168730371588.0000000"),
661
+ 7,
662
+ "Invalid value for precision");
663
+
664
+ CAN_USE_PRECISION_MODE_ERRORS(MC_DEC128(788545.000000),
665
+ mc_dec128_from_string("340282366920938463463374607431769000000.000000"),
666
+ 0,
667
+ "Invalid upper bound for Decimal128 precision. Absolute scaled");
668
+
669
+ #undef CAN_USE_PRECISION_MODE
670
+ #undef CAN_USE_PRECISION_MODE_ERRORS
671
+ }
672
+
454
673
  static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
455
674
  Decimal128Test tests[] = {
456
675
  #define CASE(Value, ExpectStr) \
@@ -553,29 +772,29 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
553
772
  ERROR_CASE(MC_DEC128_C(1),
554
773
  OPT_NULLOPT,
555
774
  OPT_MC_DEC128(MC_DEC128_C(2)),
556
- OPT_U32(5),
775
+ OPT_I32(5),
557
776
  "min, max, and precision must all be set or must all be unset"),
558
777
  ERROR_CASE(MC_DEC128_C(1),
559
778
  OPT_MC_DEC128(MC_DEC128_C(0)),
560
779
  OPT_NULLOPT,
561
- OPT_U32(5),
780
+ OPT_I32(5),
562
781
  "min, max, and precision must all be set or must all be unset"),
563
782
  ERROR_CASE(MC_DEC128_C(1),
564
783
  OPT_MC_DEC128(MC_DEC128_C(2)),
565
784
  OPT_MC_DEC128(MC_DEC128_C(1)),
566
- OPT_U32(5),
785
+ OPT_I32(5),
567
786
  "The minimum value must be less than the maximum value"),
568
787
 
569
788
  ERROR_CASE(MC_DEC128_C(1),
570
789
  OPT_MC_DEC128(MC_DEC128_C(2)),
571
790
  OPT_MC_DEC128(MC_DEC128_C(3)),
572
- OPT_U32(5),
791
+ OPT_I32(5),
573
792
  "Value must be greater than or equal to the minimum value "
574
793
  "and less than or equal to the maximum value"),
575
794
  ERROR_CASE(MC_DEC128_C(4),
576
795
  OPT_MC_DEC128(MC_DEC128_C(2)),
577
796
  OPT_MC_DEC128(MC_DEC128_C(3)),
578
- OPT_U32(5),
797
+ OPT_I32(5),
579
798
  "Value must be greater than or equal to the minimum value "
580
799
  "and less than or equal to the maximum value"),
581
800
 
@@ -608,7 +827,7 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
608
827
  .value = mc_dec128_from_string(Value), \
609
828
  .min = OPT_MC_DEC128(MC_DEC128_C(-100000)), \
610
829
  .max = OPT_MC_DEC128(MC_DEC128_C(100000)), \
611
- .precision = OPT_U32(Precision), \
830
+ .precision = OPT_I32(Precision), \
612
831
  .expect = MLIB_INT128(Expect), \
613
832
  }
614
833
  ASSERT_EIBP("3.141592653589E-1", 10, 1000003141592653),
@@ -626,7 +845,7 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
626
845
  .value = mc_dec128_from_string(Value), \
627
846
  .min = OPT_MC_DEC128(MC_DEC128_C(-100000)), \
628
847
  .max = OPT_MC_DEC128(mc_dec128_from_string("1E22")), \
629
- .precision = OPT_U32(Precision), \
848
+ .precision = OPT_I32(Precision), \
630
849
  .expect = mlib_int128_from_string(Expect, NULL), \
631
850
  }
632
851
 
@@ -643,7 +862,7 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
643
862
  .value = mc_dec128_from_string(#Value), \
644
863
  .min = OPT_MC_DEC128(MC_DEC128_C(-100000)), \
645
864
  .max = OPT_MC_DEC128(MC_DEC128_C(100000)), \
646
- .precision = OPT_U32(Precision), \
865
+ .precision = OPT_I32(Precision), \
647
866
  .expect = MLIB_INT128_CAST(Expect), \
648
867
  }
649
868
  ASSERT_EIBP(3.141592653589, 1, 1000031),
@@ -660,14 +879,41 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
660
879
  .value = mc_dec128_from_string(#Val), \
661
880
  .min = OPT_MC_DEC128(mc_dec128_from_string(#Min)), \
662
881
  .max = OPT_MC_DEC128(mc_dec128_from_string(#Max)), \
663
- .precision = OPT_U32(Precision), \
882
+ .precision = OPT_I32(Precision), \
664
883
  .expect = MLIB_INT128_CAST(Expect), \
665
884
  }
666
885
 
886
+ // ASSERT_EIBB_OVERFLOW defines cases where applying min/max/precision result in a domain needing >= 128 bits.
887
+ // For range v1, expect precision to be ignored.
888
+ // For range v2, expect an error.
667
889
  #define ASSERT_EIBB_OVERFLOW(Val, Max, Min, Precision, Expect) \
668
- (Decimal128Test) { \
890
+ (Decimal128Test){ \
891
+ .value = mc_dec128_from_string(#Val), \
892
+ .min = OPT_MC_DEC128(mc_dec128_from_string(#Min)), \
893
+ .max = OPT_MC_DEC128(mc_dec128_from_string(#Max)), \
894
+ .precision = OPT_I32(Precision), \
895
+ .expect = Expect, \
896
+ .use_range_v1 = true, \
897
+ }, \
898
+ (Decimal128Test) { \
669
899
  .value = mc_dec128_from_string(#Val), .min = OPT_MC_DEC128(mc_dec128_from_string(#Min)), \
670
- .max = OPT_MC_DEC128(mc_dec128_from_string(#Max)), .precision = OPT_U32(Precision), .expect = Expect, \
900
+ .max = OPT_MC_DEC128(mc_dec128_from_string(#Max)), .precision = OPT_I32(Precision), \
901
+ .expectError = "The domain of decimal values specified by the min, max, and precision " \
902
+ "cannot be represented in fewer than 128 bits" \
903
+ }
904
+
905
+ #define ASSERT_EIBB_ERROR(Val, Max, Min, Precision, Expect, Error) \
906
+ (Decimal128Test){ \
907
+ .value = mc_dec128_from_string(#Val), \
908
+ .min = OPT_MC_DEC128(mc_dec128_from_string(#Min)), \
909
+ .max = OPT_MC_DEC128(mc_dec128_from_string(#Max)), \
910
+ .precision = OPT_I32(Precision), \
911
+ .expect = Expect, \
912
+ .use_range_v1 = true, \
913
+ }, \
914
+ (Decimal128Test) { \
915
+ .value = mc_dec128_from_string(#Val), .min = OPT_MC_DEC128(mc_dec128_from_string(#Min)), \
916
+ .max = OPT_MC_DEC128(mc_dec128_from_string(#Max)), .precision = OPT_I32(Precision), .expectError = Error \
671
917
  }
672
918
 
673
919
  ASSERT_EIBB(0, 1, -1, 3, 1000),
@@ -675,16 +921,19 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
675
921
 
676
922
  ASSERT_EIBB(-1E-33, 1, -1E5, 3, 100000000),
677
923
 
678
- ASSERT_EIBB_OVERFLOW(0,
679
- MC_DEC128_LARGEST_POSITIVE,
680
- MC_DEC128_LARGEST_NEGATIVE,
681
- 3,
682
- mlib_int128_from_string("170141183460469231731687303715884105728", NULL)),
683
- ASSERT_EIBB_OVERFLOW(0,
684
- DBL_MAX,
685
- DBL_MIN,
686
- 3,
687
- mlib_int128_from_string("170141183460469231731687303715884105728", NULL)),
924
+ ASSERT_EIBB_ERROR(0,
925
+ MC_DEC128_LARGEST_POSITIVE,
926
+ MC_DEC128_LARGEST_NEGATIVE,
927
+ 3,
928
+ mlib_int128_from_string("170141183460469231731687303715884105728", NULL),
929
+ "Invalid upper bound for Decimal128 precision. Max is infinite."),
930
+
931
+ ASSERT_EIBB_ERROR(0,
932
+ DBL_MAX,
933
+ DBL_MIN,
934
+ 3,
935
+ mlib_int128_from_string("170141183460469231731687303715884105728", NULL),
936
+ "Invalid upper bound for Decimal128 precision. Max is infinite."),
688
937
 
689
938
  ASSERT_EIBB(3.141592653589, 5, 0, 0, 3),
690
939
  ASSERT_EIBB(3.141592653589, 5, 0, 1, 31),
@@ -696,11 +945,12 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
696
945
 
697
946
  ASSERT_EIBB(-5, -1, -10, 3, 5000),
698
947
 
699
- ASSERT_EIBB_OVERFLOW(1E100,
700
- DBL_MAX,
701
- DBL_MIN,
702
- 3,
703
- mlib_int128_from_string("232572183460469231731687303715884099485", NULL)),
948
+ ASSERT_EIBB_ERROR(1E100,
949
+ DBL_MAX,
950
+ DBL_MIN,
951
+ 3,
952
+ mlib_int128_from_string("232572183460469231731687303715884099485", NULL),
953
+ "Invalid upper bound for Decimal128 precision. Max is infinite."),
704
954
 
705
955
  ASSERT_EIBB(1E9, 1E10, 0, 3, 1000000000000),
706
956
  ASSERT_EIBB(1E9, 1E10, 0, 0, 1000000000),
@@ -712,15 +962,24 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
712
962
 
713
963
  // Test a range that requires > 64 bits.
714
964
  ASSERT_EIBB(5, 18446744073709551616, .1, 1, 49),
715
- // Test a range that requires > 64 bits.
716
- // min has more places after the decimal than precision.
717
- ASSERT_EIBB(5, 18446744073709551616, .01, 1, 49),
718
965
 
719
966
  #undef ASSERT_EIBB
720
967
  #undef ASSERT_EIBB_OVERFLOW
968
+ #undef ASSERT_EIBB_ERROR
721
969
 
722
970
  /* Test cases copied from Decimal128_Bounds_Precision ... end */
723
- };
971
+
972
+ {// Expect error due to precision exceeding INT32_MAX.
973
+ .min = OPT_MC_DEC128(MC_DEC128_C(1)),
974
+ .max = OPT_MC_DEC128(MC_DEC128_C(2)),
975
+ .precision = OPT_I32(-1),
976
+ .expectError = "Precision must be non-negative"},
977
+ {// Expect error due to precision exceeding max finite Decimal128.
978
+ // The largest decimal128 value is 9.99999...x10^6144. 10^6145 results in infinity.
979
+ .min = OPT_MC_DEC128(MC_DEC128_C(0)),
980
+ .max = OPT_MC_DEC128(MC_DEC128_C(1)),
981
+ .precision = OPT_I32(6145),
982
+ .expectError = "Precision is too large"}};
724
983
 
725
984
  for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
726
985
  Decimal128Test *test = tests + i;
@@ -738,12 +997,17 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
738
997
  }
739
998
  fflush(stdout);
740
999
  mc_OSTType_Decimal128 got;
741
- const bool ok = mc_getTypeInfoDecimal128((mc_getTypeInfoDecimal128_args_t){.value = test->value,
742
- .min = test->min,
743
- .max = test->max,
744
- .precision = test->precision},
745
- &got,
746
- status);
1000
+ const bool use_range_v2 = !test->use_range_v1;
1001
+ const bool ok = mc_getTypeInfoDecimal128(
1002
+ (mc_getTypeInfoDecimal128_args_t){
1003
+ .value = test->value,
1004
+ .min = test->min,
1005
+ .max = test->max,
1006
+ .precision = test->precision,
1007
+ },
1008
+ &got,
1009
+ status,
1010
+ use_range_v2);
747
1011
  if (test->expectError) {
748
1012
  ASSERT_OR_PRINT_MSG(!ok, "expected error, but got none");
749
1013
  ASSERT_STATUS_CONTAINS(status, test->expectError);
@@ -762,8 +1026,10 @@ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
762
1026
  void _mongocrypt_tester_install_range_encoding(_mongocrypt_tester_t *tester) {
763
1027
  INSTALL_TEST(_test_RangeTest_Encode_Int32);
764
1028
  INSTALL_TEST(_test_RangeTest_Encode_Int64);
1029
+ INSTALL_TEST(_test_canUsePrecisionModeDouble);
765
1030
  INSTALL_TEST(_test_RangeTest_Encode_Double);
766
1031
  #if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
1032
+ INSTALL_TEST(_test_canUsePrecisionModeDecimal);
767
1033
  INSTALL_TEST(_test_RangeTest_Encode_Decimal128);
768
1034
  #endif
769
1035
  }