libmongocrypt-helper 1.7.4.0.1002 → 1.11.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (600) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +40 -5
  3. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +29 -24
  4. data/ext/libmongocrypt/libmongocrypt/CODEOWNERS +1 -4
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +522 -0
  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/CryptClient.cs +25 -6
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClientFactory.cs +8 -4
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +35 -3
  14. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/LibraryLoader.cs +81 -44
  15. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/MongoDB.Libmongocrypt.csproj +2 -1
  16. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  17. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  18. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/MongoDB.Libmongocrypt.Test.csproj +2 -0
  19. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test32/MongoDB.Libmongocrypt.Test32.csproj +2 -0
  20. data/ext/libmongocrypt/libmongocrypt/bindings/cs/README.md +3 -0
  21. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +22 -26
  22. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.config +3 -0
  23. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.sh +0 -0
  24. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/build.gradle.kts +28 -0
  25. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/java/com/mongodb/crypt/benchmark/BenchmarkRunner.java +217 -0
  26. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/resources/keyDocument.json +24 -0
  27. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +22 -7
  28. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.jar +0 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.properties +1 -1
  30. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew +154 -108
  31. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew.bat +7 -18
  32. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/settings.gradle.kts +1 -0
  33. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPI.java +41 -6
  34. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPIHelper.java +5 -5
  35. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CipherCallback.java +27 -1
  36. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoCryptImpl.java +34 -19
  37. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoExplicitEncryptOptions.java +6 -4
  38. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/jni-config.json +180 -0
  39. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/reflect-config.json +134 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +50 -6
  41. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/{python/test/data/fle2-find-range-explicit → java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2}/int32/rangeopts.json +3 -0
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +4 -771
  44. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +86 -0
  45. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +41 -20
  46. data/ext/libmongocrypt/libmongocrypt/bindings/python/RELEASE.rst +6 -24
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +4 -13
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/hatch_build.py +36 -0
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/libmongocrypt-version.txt +1 -0
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/__init__.py +2 -2
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/auto_encrypter.py +61 -0
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/credentials.py +156 -0
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/explicit_encrypter.py +156 -0
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/state_machine.py +149 -0
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/auto_encrypter.py +2 -46
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binary.py +14 -17
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +232 -296
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +6 -31
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/credentials.py +2 -121
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/crypto.py +31 -20
  61. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/errors.py +2 -2
  62. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +2 -233
  63. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +168 -254
  64. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/options.py +265 -0
  65. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/state_machine.py +2 -141
  66. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/auto_encrypter.py +61 -0
  67. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/credentials.py +156 -0
  68. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/explicit_encrypter.py +156 -0
  69. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/state_machine.py +149 -0
  70. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  71. data/ext/libmongocrypt/libmongocrypt/bindings/python/pyproject.toml +118 -0
  72. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +97 -61
  73. data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements-test.txt +7 -0
  74. data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements.txt +4 -0
  75. data/ext/libmongocrypt/libmongocrypt/bindings/python/sbom.json +76 -0
  76. data/ext/libmongocrypt/libmongocrypt/bindings/python/strip_header.py +6 -7
  77. data/ext/libmongocrypt/libmongocrypt/bindings/python/synchro.py +64 -0
  78. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +2 -10
  79. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/collection-info.json +1 -1
  80. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/command.json +1 -1
  81. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/compact/success/encrypted-payload.json +21 -21
  82. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-command-reply.json +1 -1
  83. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-field-config-map.json +1 -1
  84. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  85. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/rangeopts.json +14 -0
  86. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-azure.json +1 -1
  87. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-gcp.json +1 -1
  88. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document.json +1 -1
  89. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-filter.json +1 -1
  90. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/list-collections-filter.json +1 -1
  91. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-command.json +1 -1
  92. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-reply.json +1 -1
  93. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/schema-map.json +1 -1
  94. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/keyDocument.json +24 -0
  95. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/perf_test.py +165 -0
  96. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_binding.py +8 -12
  97. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_crypto.py +9 -11
  98. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +991 -343
  99. data/ext/libmongocrypt/libmongocrypt/bindings/python/update-sbom.sh +14 -0
  100. data/ext/libmongocrypt/libmongocrypt/cmake/FetchMongoC.cmake +19 -1
  101. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +31 -6
  102. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +20 -227
  103. data/ext/libmongocrypt/libmongocrypt/cmake/Patch.cmake +54 -0
  104. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  105. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  106. data/ext/libmongocrypt/libmongocrypt/doc/img/cli-icon.png +0 -0
  107. data/ext/libmongocrypt/libmongocrypt/doc/img/reference-targets.png +0 -0
  108. data/ext/libmongocrypt/libmongocrypt/doc/releasing.md +153 -0
  109. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  110. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version.py +61 -28
  111. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version_selftest.sh +73 -0
  112. data/ext/libmongocrypt/libmongocrypt/etc/cyclonedx.sbom.json +108 -0
  113. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  114. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  115. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  116. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  117. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  118. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  119. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  120. data/ext/libmongocrypt/libmongocrypt/etc/libbson-remove-GCC-diagnostic-pragma.patch +27 -0
  121. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-alpine-arm-fix.patch +17 -0
  122. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  123. data/ext/libmongocrypt/libmongocrypt/etc/packager.py +120 -91
  124. data/ext/libmongocrypt/libmongocrypt/etc/purls.txt +14 -0
  125. data/ext/libmongocrypt/libmongocrypt/etc/repo_config.yaml +56 -0
  126. data/ext/libmongocrypt/libmongocrypt/etc/silk-create-asset-group.sh +70 -0
  127. data/ext/libmongocrypt/libmongocrypt/etc/ssdlc_compliance_report.md +37 -0
  128. data/ext/libmongocrypt/libmongocrypt/etc/third_party_vulnerabilities.md +42 -0
  129. data/ext/libmongocrypt/libmongocrypt/integrating.md +18 -1
  130. data/ext/libmongocrypt/libmongocrypt/kms-message/CMakeLists.txt +11 -3
  131. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_gcp_request.c +1 -1
  132. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer.c +17 -0
  133. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer_private.h +6 -0
  134. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_request.c +211 -1
  135. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_response.c +163 -0
  136. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_tag_type_private.h +2 -1
  137. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_request.h +17 -0
  138. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_response.h +6 -0
  139. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_port.c +3 -2
  140. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request.c +4 -2
  141. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.c +2 -2
  142. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kmip_reader_writer.c +23 -2
  143. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  144. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  145. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +183 -248
  146. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  147. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  148. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  149. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  150. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  151. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  152. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  153. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +21 -11
  154. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +175 -99
  155. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  156. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +69 -70
  157. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +445 -439
  158. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  159. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  160. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  161. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  162. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +103 -0
  163. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +28 -31
  164. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +173 -0
  165. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  166. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +130 -0
  167. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +36 -44
  168. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +382 -0
  169. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  170. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  171. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  172. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  173. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +454 -325
  174. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  175. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  176. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  177. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  178. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  179. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  180. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  181. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +56 -56
  182. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +520 -580
  183. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +47 -66
  184. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +67 -76
  185. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +201 -190
  186. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +55 -42
  187. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +809 -558
  188. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +177 -201
  189. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +54 -53
  190. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +188 -240
  191. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +43 -35
  192. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +484 -337
  193. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  194. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  195. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +87 -65
  196. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +153 -125
  197. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  198. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  199. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  200. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  201. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  202. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +461 -499
  203. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +256 -334
  204. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  205. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  206. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  207. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  208. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  209. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  210. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  211. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +1 -9
  212. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  213. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  214. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +442 -565
  215. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  216. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  217. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  218. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +104 -132
  219. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +16 -24
  220. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +110 -93
  221. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  222. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  223. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  224. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  225. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  226. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  227. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1145 -1567
  228. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +510 -476
  229. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  230. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2775 -2697
  231. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +189 -184
  232. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  233. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +990 -1139
  234. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +23 -24
  235. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  236. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  237. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  238. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +42 -44
  239. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +292 -272
  240. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +70 -110
  241. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +1010 -1033
  242. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  243. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  244. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +127 -120
  245. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1692 -1611
  246. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  247. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  248. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +31 -36
  249. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1923 -1479
  250. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  251. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +124 -107
  252. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +925 -419
  253. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +99 -122
  254. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  255. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  256. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  257. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  258. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  259. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +98 -136
  260. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +924 -1339
  261. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +199 -313
  262. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +83 -79
  263. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  264. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +64 -73
  265. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  266. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  267. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/bypassQueryAnalysis/payload.json +53 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd-to-mongocryptd.json +23 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd.json +20 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd-to-mongocryptd.json +50 -0
  271. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd.json +20 -0
  272. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/collinfo.json +44 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-field-map.json +24 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-payload-pattern.json +53 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/mongocryptd-reply.json +62 -0
  276. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd-to-mongocryptd.json +30 -0
  277. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd.json +17 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/mongocryptd-reply.json +39 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/payload.json +21 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/missing-key-id/collinfo.json +20 -0
  281. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/collinfo.json +9 -0
  282. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/encrypted-payload.json +4 -0
  283. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/cmd.json +1 -0
  284. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/collinfo.json +63 -0
  285. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-field-config-map.json +61 -0
  286. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload-range-v2.json +37 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload.json +29 -0
  288. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/cmd.json +1 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/collinfo.json +64 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload-range-v2.json +105 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload.json +30 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/cmd.json +1 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/collinfo.json +49 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-field-config-map.json +47 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-payload.json +23 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/collinfo.json +15 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-field-config-map.json +10 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload-range-v2.json +104 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload.json +6 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/collinfo.json +4 -4
  303. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +5 -5
  304. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  314. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  315. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  316. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  317. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  318. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  319. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  320. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  323. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  324. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  325. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  326. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  327. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  328. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  329. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  330. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  331. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  332. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  333. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  334. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  335. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  336. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  337. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  338. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  339. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  340. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  341. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  342. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  343. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  344. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  345. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  346. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  347. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  348. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  349. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  350. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  351. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  352. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  353. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  354. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  355. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  356. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  357. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  358. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  359. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  360. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  361. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  362. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  363. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  364. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  365. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  366. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  367. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  368. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  369. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  370. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  371. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  372. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  373. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  374. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  375. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  376. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  377. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  378. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  379. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  380. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  381. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  382. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  383. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  384. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  392. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  393. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  394. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  395. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  396. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  397. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  398. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  399. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  400. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  401. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/decrypt-response.txt +16 -0
  402. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/encrypt-response.txt +16 -0
  403. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/oauth-response.txt +19 -0
  404. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/cmd.json +9 -0
  405. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-field-map.json +19 -0
  406. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-payload.json +62 -0
  407. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/mongocryptd-reply.json +69 -0
  408. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/cmd.json +11 -0
  409. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-field-map.json +19 -0
  410. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-payload.json +40 -0
  411. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/mongocryptd-reply.json +47 -0
  412. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_decimal128.cstruct +1 -1
  413. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_double.cstruct +8637 -7958
  414. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int32.cstruct +5522 -1382
  415. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int64.cstruct +5042 -1262
  416. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128.cstruct +1 -1
  417. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128_precision.cstruct +1 -1
  418. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double.cstruct +1 -1
  419. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double_precision.cstruct +2 -2
  420. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int32.cstruct +1 -1
  421. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int64.cstruct +1 -1
  422. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/cmd.json +8 -0
  423. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-field-map.json +19 -0
  424. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-payload.json +53 -0
  425. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/mongocryptd-reply.json +58 -0
  426. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/cmd.json +11 -0
  427. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-field-map.json +19 -0
  428. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-payload.json +40 -0
  429. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/mongocryptd-reply.json +45 -0
  430. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/expected.json +26 -0
  431. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/to-encrypt.json +20 -0
  432. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/expected.json +26 -0
  433. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/to-encrypt.json +20 -0
  434. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-double/expected.json +8 -0
  435. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32/expected.json +8 -0
  436. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32-defaults/expected.json +8 -0
  437. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  438. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  439. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  440. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  441. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  442. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  443. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  444. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  445. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  446. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  447. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  448. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +30 -0
  449. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +25 -0
  450. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +25 -0
  451. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  452. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +279 -323
  453. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  454. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  455. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  456. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +60 -73
  457. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  458. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +129 -0
  459. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  460. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  461. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +248 -0
  462. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  463. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  464. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  465. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  466. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +421 -388
  467. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +974 -825
  468. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +499 -481
  469. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +312 -148
  470. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  471. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +249 -213
  472. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  473. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +632 -808
  474. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +22 -2
  475. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  476. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  477. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +118 -37
  478. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  479. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  480. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cleanup.c +374 -0
  481. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +410 -445
  482. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +798 -812
  483. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +142 -135
  484. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +70 -71
  485. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  486. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  487. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +870 -1045
  488. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +5183 -4717
  489. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  490. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +1093 -1178
  491. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +348 -420
  492. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  493. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  494. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  495. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  496. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  497. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  498. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +705 -368
  499. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  500. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  501. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  502. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +1073 -690
  503. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-opts.c +42 -0
  504. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  505. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +381 -451
  506. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +55 -67
  507. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +7 -10
  508. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +879 -918
  509. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +119 -169
  510. data/ext/libmongocrypt/libmongocrypt/test/test-named-kms-providers.c +2381 -0
  511. data/ext/libmongocrypt/libmongocrypt/test/util/HELP.autogen +3 -1
  512. data/ext/libmongocrypt/libmongocrypt/test/util/README.md +1 -0
  513. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +512 -559
  514. data/ext/libmongocrypt/libmongocrypt/test/util/make_includes.py +1 -1
  515. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +771 -882
  516. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  517. data/lib/libmongocrypt_helper/version.rb +2 -2
  518. metadata +245 -111
  519. checksums.yaml.gz.sig +0 -0
  520. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +0 -1
  521. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  522. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  523. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +0 -81
  524. data/ext/libmongocrypt/libmongocrypt/bindings/node/LICENSE +0 -201
  525. data/ext/libmongocrypt/libmongocrypt/bindings/node/binding.gyp +0 -79
  526. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/README.hbs +0 -44
  527. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +0 -39
  528. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +0 -515
  529. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +0 -420
  530. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/buffer_pool.js +0 -123
  531. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +0 -699
  532. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +0 -100
  533. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  534. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/cryptoCallbacks.js +0 -87
  535. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +0 -42
  536. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js +0 -66
  537. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +0 -487
  538. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +0 -16051
  539. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +0 -81
  540. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +0 -929
  541. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.h +0 -114
  542. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +0 -953
  543. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/buffer_pool.test.js +0 -91
  544. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +0 -701
  545. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  546. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +0 -284
  547. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/README.md +0 -5
  548. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/cmd.json +0 -6
  549. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/collection-info.json +0 -37
  550. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document-nested.json +0 -8
  551. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document.json +0 -11
  552. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encryptedFields.json +0 -30
  553. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key-document.json +0 -32
  554. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key1-document.json +0 -30
  555. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/mongocryptd-reply.json +0 -18
  556. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +0 -48
  557. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +0 -59
  558. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +0 -29
  559. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +0 -331
  560. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/mongodb_reporter.js +0 -325
  561. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +0 -84
  562. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  563. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +0 -12
  564. data/ext/libmongocrypt/libmongocrypt/debian/build_snapshot.sh +0 -79
  565. data/ext/libmongocrypt/libmongocrypt/debian/changelog +0 -105
  566. data/ext/libmongocrypt/libmongocrypt/debian/compat +0 -1
  567. data/ext/libmongocrypt/libmongocrypt/debian/control +0 -41
  568. data/ext/libmongocrypt/libmongocrypt/debian/copyright +0 -129
  569. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +0 -23
  570. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.dirs +0 -2
  571. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.install +0 -5
  572. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.dirs +0 -1
  573. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.install +0 -1
  574. data/ext/libmongocrypt/libmongocrypt/debian/rules +0 -46
  575. data/ext/libmongocrypt/libmongocrypt/debian/source/format +0 -1
  576. data/ext/libmongocrypt/libmongocrypt/debian/source/lintian-overrides +0 -3
  577. data/ext/libmongocrypt/libmongocrypt/debian/source/options +0 -1
  578. data/ext/libmongocrypt/libmongocrypt/debian/watch +0 -3
  579. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  580. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/mongocryptd-reply.json +0 -72
  581. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  582. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  583. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  584. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  585. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  586. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  587. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  588. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  589. data.tar.gz.sig +0 -0
  590. metadata.gz.sig +0 -0
  591. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
  592. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
  593. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
  594. /data/ext/libmongocrypt/libmongocrypt/bindings/{java/mongocrypt/src/test/resources/fle2-find-range-explicit → python/test/data/fle2-find-rangePreview-explicit}/int32/rangeopts.json +0 -0
  595. /data/ext/libmongocrypt/libmongocrypt/{test/data/fle2-find-range-explicit/int32-nominmax → bindings/python/test/data/fle2-find-rangePreview-explicit/int32}/value-to-encrypt.json +0 -0
  596. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-decrypt-reply.txt → test/data/kms-aws/decrypt-response.txt} +0 -0
  597. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-encrypt-reply.txt → test/data/kms-aws/encrypt-response.txt} +0 -0
  598. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/decrypt-response.txt +0 -0
  599. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/encrypt-response.txt +0 -0
  600. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/oauth-response.txt +0 -0
@@ -20,867 +20,1016 @@
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
- mc_getTypeInfo32_args_t args;
26
- mc_OSTType_Int32 expect;
27
- const char *expectError;
26
+ mc_getTypeInfo32_args_t args;
27
+ mc_OSTType_Int32 expect;
28
+ const char *expectError;
28
29
  } Int32Test;
29
30
 
30
- static void
31
- _test_RangeTest_Encode_Int32 (_mongocrypt_tester_t *tester)
32
- {
33
- Int32Test tests[] = {
34
- /* Test cases copied from server Int32_NoBounds test ... begin */
35
- {.args = {.value = INT32_C (2147483647)},
36
- .expect = {.value = UINT32_C (4294967295), .min = 0, .max = UINT32_MAX}},
37
- {.args = {.value = 1},
38
- .expect = {.value = UINT32_C (2147483649), .min = 0, .max = UINT32_MAX}},
39
- {.args = {.value = 0},
40
- .expect = {.value = UINT32_C (2147483648), .min = 0, .max = UINT32_MAX}},
41
- {.args = {.value = -1},
42
- .expect = {.value = UINT32_C (2147483647), .min = 0, .max = UINT32_MAX}},
43
- {.args = {.value = -2},
44
- .expect = {.value = UINT32_C (2147483646), .min = 0, .max = UINT32_MAX}},
45
- {.args = {.value = INT32_C (-2147483647)},
46
- .expect = {.value = 1, .min = 0, .max = UINT32_MAX}},
47
- {.args = {.value = INT32_MIN},
48
- .expect = {.value = 0, .min = 0, .max = UINT32_MAX}},
49
- /* Test cases copied from server Int32_NoBounds test ... end */
50
- /* Test cases copied from server Int32_Bounds test .. begin */
51
- {.args = {.value = 1, .min = OPT_I32 (1), .max = OPT_I32 (3)},
52
- .expect = {.value = 0, 0, .max = 2}},
53
- {.args = {.value = 0, .min = OPT_I32 (0), .max = OPT_I32 (1)},
54
- .expect = {.value = 0, .min = 0, .max = 1}},
55
- {.args = {.value = -1, .min = OPT_I32 (-1), .max = OPT_I32 (0)},
56
- .expect = {.value = 0, .min = 0, .max = 1}},
57
- {.args = {.value = -2, .min = OPT_I32 (-2), .max = OPT_I32 (0)},
58
- .expect = {.value = 0, .min = 0, .max = 2}},
59
- {.args = {.value = INT32_C (-2147483647),
60
- .min = OPT_I32 (INT32_MIN),
61
- .max = OPT_I32 (1)},
62
- .expect = {.value = 1, .min = 0, .max = UINT32_C (2147483649)}},
63
- {.args = {.value = INT32_MIN,
64
- .min = OPT_I32 (INT32_MIN),
65
- .max = OPT_I32 (0)},
66
- .expect = {.value = 0, .min = 0, .max = UINT32_C (2147483648)}},
67
- {.args = {.value = 0, .min = OPT_I32 (INT32_MIN), .max = OPT_I32 (1)},
68
- .expect = {.value = UINT32_C (2147483648),
69
- .min = 0,
70
- .max = UINT32_C (2147483649)}},
71
- {.args = {.value = 1, .min = OPT_I32 (INT32_MIN), .max = OPT_I32 (2)},
72
- .expect = {.value = UINT32_C (2147483649),
73
- .min = 0,
74
- .max = UINT32_C (2147483650)}},
75
- {.args = {.value = INT32_C (2147483647),
76
- .min = OPT_I32 (-2147483647),
77
- .max = OPT_I32 (2147483647)},
78
- .expect = {.value = UINT32_C (4294967294),
79
- .min = 0,
80
- .max = UINT32_C (4294967294)}},
81
- {.args = {.value = INT32_C (2147483647),
82
- .min = OPT_I32 (INT32_MIN),
83
- .max = OPT_I32 (2147483647)},
84
- .expect = {.value = UINT32_C (4294967295),
85
- .min = 0,
86
- .max = UINT32_C (4294967295)}},
87
- {.args = {.value = 15, .min = OPT_I32 (10), .max = OPT_I32 (26)},
88
- .expect = {.value = 5, .min = 0, .max = 16}},
89
- {.args = {.value = 15, .min = OPT_I32 (-10), .max = OPT_I32 (55)},
90
- .expect = {.value = 25, .min = 0, .max = 65}},
91
- /* Test cases copied from server Int32_Bounds test ... end */
92
- /* Test cases copied from server Int32_Errors test ... begin */
93
- {.args = {.value = 1, .max = OPT_I32 (2)},
94
- .expectError =
95
- "Must specify both a lower and upper bound or no bounds."},
96
- {.args = {.value = 1, .min = OPT_I32 (0)},
97
- .expectError =
98
- "Must specify both a lower and upper bound or no bounds."},
99
- {.args = {.value = 1, .min = OPT_I32 (2), .max = OPT_I32 (1)},
100
- .expectError = "The minimum value must be less than the maximum value"},
101
- {.args = {.value = 1, .min = OPT_I32 (2), .max = OPT_I32 (3)},
102
- .expectError = "Value must be greater than or equal to the minimum "
103
- "value and less than or equal to the maximum value"},
104
- {.args = {.value = 4, .min = OPT_I32 (2), .max = OPT_I32 (3)},
105
- .expectError = "Value must be greater than or equal to the minimum "
106
- "value and less than or equal to the maximum value"},
107
- {.args = {.value = 4,
108
- .min = OPT_I32 (INT32_MIN),
109
- .max = OPT_I32 (INT32_MIN)},
110
- .expectError = "The minimum value must be less than the maximum value"},
111
- /* Test cases copied from server Int32_Errors test ... end */
112
- };
113
-
114
- for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) {
115
- Int32Test *test = tests + i;
116
- mongocrypt_status_t *const status = mongocrypt_status_new ();
117
-
118
- // Print a description of the test case.
119
- printf ("_test_RangeTest_Encode_Int32: value=%" PRId32, test->args.value);
120
- if (test->args.min.set) {
121
- printf (" min=%" PRId32, test->args.min.value);
122
- }
123
- if (test->args.max.set) {
124
- printf (" max=%" PRId32, test->args.max.value);
125
- }
126
- printf ("\n");
127
- mc_OSTType_Int32 got;
128
- const bool ok = mc_getTypeInfo32 (test->args, &got, status);
129
- if (test->expectError) {
130
- ASSERT_OR_PRINT_MSG (!ok, "expected error, but got none");
131
- ASSERT_STATUS_CONTAINS (status, test->expectError);
132
- } else {
133
- ASSERT_OK_STATUS (ok, status);
134
- ASSERT_CMPUINT32 (got.value, ==, test->expect.value);
135
- ASSERT_CMPUINT32 (got.min, ==, test->expect.min);
136
- ASSERT_CMPUINT32 (got.max, ==, test->expect.max);
137
- }
138
- mongocrypt_status_destroy (status);
139
- }
31
+ static void _test_RangeTest_Encode_Int32(_mongocrypt_tester_t *tester) {
32
+ Int32Test tests[] = {
33
+ /* Test cases copied from server Int32_NoBounds test ... begin */
34
+ {.args = {.value = INT32_C(2147483647)},
35
+ .expect = {.value = UINT32_C(4294967295), .min = 0, .max = UINT32_MAX}},
36
+ {.args = {.value = 1}, .expect = {.value = UINT32_C(2147483649), .min = 0, .max = UINT32_MAX}},
37
+ {.args = {.value = 0}, .expect = {.value = UINT32_C(2147483648), .min = 0, .max = UINT32_MAX}},
38
+ {.args = {.value = -1}, .expect = {.value = UINT32_C(2147483647), .min = 0, .max = UINT32_MAX}},
39
+ {.args = {.value = -2}, .expect = {.value = UINT32_C(2147483646), .min = 0, .max = UINT32_MAX}},
40
+ {.args = {.value = INT32_C(-2147483647)}, .expect = {.value = 1, .min = 0, .max = UINT32_MAX}},
41
+ {.args = {.value = INT32_MIN}, .expect = {.value = 0, .min = 0, .max = UINT32_MAX}},
42
+ /* Test cases copied from server Int32_NoBounds test ... end */
43
+ /* Test cases copied from server Int32_Bounds test .. begin */
44
+ {.args = {.value = 1, .min = OPT_I32(1), .max = OPT_I32(3)}, .expect = {.value = 0, 0, .max = 2}},
45
+ {.args = {.value = 0, .min = OPT_I32(0), .max = OPT_I32(1)}, .expect = {.value = 0, .min = 0, .max = 1}},
46
+ {.args = {.value = -1, .min = OPT_I32(-1), .max = OPT_I32(0)}, .expect = {.value = 0, .min = 0, .max = 1}},
47
+ {.args = {.value = -2, .min = OPT_I32(-2), .max = OPT_I32(0)}, .expect = {.value = 0, .min = 0, .max = 2}},
48
+ {.args = {.value = INT32_C(-2147483647), .min = OPT_I32(INT32_MIN), .max = OPT_I32(1)},
49
+ .expect = {.value = 1, .min = 0, .max = UINT32_C(2147483649)}},
50
+ {.args = {.value = INT32_MIN, .min = OPT_I32(INT32_MIN), .max = OPT_I32(0)},
51
+ .expect = {.value = 0, .min = 0, .max = UINT32_C(2147483648)}},
52
+ {.args = {.value = 0, .min = OPT_I32(INT32_MIN), .max = OPT_I32(1)},
53
+ .expect = {.value = UINT32_C(2147483648), .min = 0, .max = UINT32_C(2147483649)}},
54
+ {.args = {.value = 1, .min = OPT_I32(INT32_MIN), .max = OPT_I32(2)},
55
+ .expect = {.value = UINT32_C(2147483649), .min = 0, .max = UINT32_C(2147483650)}},
56
+ {.args = {.value = INT32_C(2147483647), .min = OPT_I32(-2147483647), .max = OPT_I32(2147483647)},
57
+ .expect = {.value = UINT32_C(4294967294), .min = 0, .max = UINT32_C(4294967294)}},
58
+ {.args = {.value = INT32_C(2147483647), .min = OPT_I32(INT32_MIN), .max = OPT_I32(2147483647)},
59
+ .expect = {.value = UINT32_C(4294967295), .min = 0, .max = UINT32_C(4294967295)}},
60
+ {.args = {.value = 15, .min = OPT_I32(10), .max = OPT_I32(26)}, .expect = {.value = 5, .min = 0, .max = 16}},
61
+ {.args = {.value = 15, .min = OPT_I32(-10), .max = OPT_I32(55)}, .expect = {.value = 25, .min = 0, .max = 65}},
62
+ /* Test cases copied from server Int32_Bounds test ... end */
63
+ /* Test cases copied from server Int32_Errors test ... begin */
64
+ {.args = {.value = 1, .max = OPT_I32(2)},
65
+ .expectError = "Must specify both a lower and upper bound or no bounds."},
66
+ {.args = {.value = 1, .min = OPT_I32(0)},
67
+ .expectError = "Must specify both a lower and upper bound or no bounds."},
68
+ {.args = {.value = 1, .min = OPT_I32(2), .max = OPT_I32(1)},
69
+ .expectError = "The minimum value must be less than the maximum value"},
70
+ {.args = {.value = 1, .min = OPT_I32(2), .max = OPT_I32(3)},
71
+ .expectError = "Value must be greater than or equal to the minimum "
72
+ "value and less than or equal to the maximum value"},
73
+ {.args = {.value = 4, .min = OPT_I32(2), .max = OPT_I32(3)},
74
+ .expectError = "Value must be greater than or equal to the minimum "
75
+ "value and less than or equal to the maximum value"},
76
+ {.args = {.value = 4, .min = OPT_I32(INT32_MIN), .max = OPT_I32(INT32_MIN)},
77
+ .expectError = "The minimum value must be less than the maximum value"},
78
+ /* Test cases copied from server Int32_Errors test ... end */
79
+ };
80
+
81
+ for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
82
+ Int32Test *test = tests + i;
83
+ mongocrypt_status_t *const status = mongocrypt_status_new();
84
+
85
+ // Print a description of the test case.
86
+ printf("_test_RangeTest_Encode_Int32: value=%" PRId32, test->args.value);
87
+ if (test->args.min.set) {
88
+ printf(" min=%" PRId32, test->args.min.value);
89
+ }
90
+ if (test->args.max.set) {
91
+ printf(" max=%" PRId32, test->args.max.value);
92
+ }
93
+ printf("\n");
94
+ mc_OSTType_Int32 got;
95
+ const bool ok = mc_getTypeInfo32(test->args, &got, status);
96
+ if (test->expectError) {
97
+ ASSERT_OR_PRINT_MSG(!ok, "expected error, but got none");
98
+ ASSERT_STATUS_CONTAINS(status, test->expectError);
99
+ } else {
100
+ ASSERT_OK_STATUS(ok, status);
101
+ ASSERT_CMPUINT32(got.value, ==, test->expect.value);
102
+ ASSERT_CMPUINT32(got.min, ==, test->expect.min);
103
+ ASSERT_CMPUINT32(got.max, ==, test->expect.max);
104
+ }
105
+ mongocrypt_status_destroy(status);
106
+ }
140
107
  }
141
108
 
142
109
  typedef struct {
143
- mc_getTypeInfo64_args_t args;
144
- mc_OSTType_Int64 expect;
145
- const char *expectError;
110
+ mc_getTypeInfo64_args_t args;
111
+ mc_OSTType_Int64 expect;
112
+ const char *expectError;
146
113
  } Int64Test;
147
114
 
148
- static void
149
- _test_RangeTest_Encode_Int64 (_mongocrypt_tester_t *tester)
150
- {
151
- Int64Test tests[] = {
152
- /* Test cases copied from server Int64_NoBounds test ... begin */
153
- {.args = {.value = INT64_C (9223372036854775807)},
154
- .expect = {.value = UINT64_C (18446744073709551615),
155
- .min = 0,
156
- .max = UINT64_MAX}},
157
- {.args = {.value = 1},
158
- .expect = {.value = UINT64_C (9223372036854775809),
159
- .min = 0,
160
- .max = UINT64_MAX}},
161
- {.args = {.value = 0},
162
- .expect = {.value = UINT64_C (9223372036854775808),
163
- .min = 0,
164
- .max = UINT64_MAX}},
165
- {.args = {.value = -1},
166
- .expect = {.value = UINT64_C (9223372036854775807),
167
- .min = 0,
168
- .max = UINT64_MAX}},
169
- {.args = {.value = -2},
170
- .expect = {.value = UINT64_C (9223372036854775806),
171
- .min = 0,
172
- .max = UINT64_MAX}},
173
- {.args = {.value = INT64_C (-9223372036854775807)},
174
- .expect = {.value = 1, .min = 0, .max = UINT64_MAX}},
175
- {.args = {.value = INT64_MIN},
176
- .expect = {.value = 0, .min = 0, .max = UINT64_MAX}},
177
- /* Test cases copied from server Int64_NoBounds test ... end */
178
- /* Test cases copied from server Int64_Bounds test ... begin */
179
- {.args = {.value = 1, .min = OPT_I64 (1), .max = OPT_I64 (2)},
180
- .expect = {.value = 0, .min = 0, .max = 1}},
181
- {.args = {.value = 0, .min = OPT_I64 (0), .max = OPT_I64 (1)},
182
- .expect = {.value = 0, .min = 0, .max = 1}},
183
- {.args = {.value = -1, .min = OPT_I64 (-1), .max = OPT_I64 (0)},
184
- .expect = {.value = 0, .min = 0, .max = 1}},
185
- {.args = {.value = -2, .min = OPT_I64 (-2), .max = OPT_I64 (0)},
186
- .expect = {.value = 0, .min = 0, .max = 2}},
187
- {.args = {.value = INT64_C (-9223372036854775807),
188
- .min = OPT_I64 (INT64_MIN),
189
- .max = OPT_I64 (1)},
190
- .expect = {.value = 1, .min = 0, .max = UINT64_C (9223372036854775809)}},
191
- {.args = {.value = INT64_MIN,
192
- .min = OPT_I64 (INT64_MIN),
193
- .max = OPT_I64 (0)},
194
- .expect = {.value = 0, .min = 0, .max = UINT64_C (9223372036854775808)}},
195
- {.args = {.value = 0, .min = OPT_I64 (INT64_MIN), .max = OPT_I64 (37)},
196
- .expect = {.value = UINT64_C (9223372036854775808),
197
- .min = 0,
198
- .max = UINT64_C (9223372036854775845)}},
199
- {.args = {.value = 1, .min = OPT_I64 (INT64_MIN), .max = OPT_I64 (42)},
200
- .expect = {.value = UINT64_C (9223372036854775809),
201
- .min = 0,
202
- .max = UINT64_C (9223372036854775850)}},
203
- {.args = {.value = INT64_C (9223372036854775807),
204
- .min = OPT_I64 (-9223372036854775807),
205
- .max = OPT_I64 (9223372036854775807)},
206
- .expect = {.value = UINT64_C (18446744073709551614),
207
- .min = 0,
208
- .max = UINT64_C (18446744073709551614)}},
209
- {.args = {.value = INT64_C (9223372036854775807),
210
- .min = OPT_I64 (INT64_MIN),
211
- .max = OPT_I64 (9223372036854775807)},
212
- .expect = {.value = UINT64_C (18446744073709551615),
213
- .min = 0,
214
- .max = UINT64_C (18446744073709551615)}},
215
- {.args = {.value = 15, .min = OPT_I64 (10), .max = OPT_I64 (26)},
216
- .expect = {.value = 5, .min = 0, .max = 16}},
217
- {.args = {.value = 15, .min = OPT_I64 (-10), .max = OPT_I64 (55)},
218
- .expect = {.value = 25, .min = 0, .max = 65}},
219
- /* Test cases copied from server Int64_Bounds test ... end */
220
- /* Test cases copied from server Int64_Errors test ... begin */
221
- {.args = {.value = 1, .max = OPT_I64 (2)},
222
- .expectError =
223
- "Must specify both a lower and upper bound or no bounds."},
224
- {.args = {.value = 1, .min = OPT_I64 (0)},
225
- .expectError =
226
- "Must specify both a lower and upper bound or no bounds."},
227
- {.args = {.value = 1, .min = OPT_I64 (2), .max = OPT_I64 (1)},
228
- .expectError = "The minimum value must be less than the maximum value"},
229
- {.args = {.value = 1, .min = OPT_I64 (2), .max = OPT_I64 (3)},
230
- .expectError = "Value must be greater than or equal to the minimum "
231
- "value and less than or equal to the maximum value"},
232
- {.args = {.value = 4, .min = OPT_I64 (2), .max = OPT_I64 (3)},
233
- .expectError = "Value must be greater than or equal to the minimum "
234
- "value and less than or equal to the maximum value"},
235
- {.args = {.value = 4,
236
- .min = OPT_I64 (INT64_MIN),
237
- .max = OPT_I64 (INT64_MIN)},
238
- .expectError = "The minimum value must be less than the maximum value"},
239
- /* Test cases copied from server Int64_Errors test ... end */
240
- };
241
-
242
- for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) {
243
- Int64Test *test = tests + i;
244
- mongocrypt_status_t *const status = mongocrypt_status_new ();
245
-
246
- // Print a description of the test case.
247
- printf ("_test_RangeTest_Encode_Int64: value=%" PRId64, test->args.value);
248
- if (test->args.min.set) {
249
- printf (" min=%" PRId64, test->args.min.value);
250
- }
251
- if (test->args.max.set) {
252
- printf (" max=%" PRId64, test->args.max.value);
253
- }
254
- printf ("\n");
255
- mc_OSTType_Int64 got;
256
- const bool ok = mc_getTypeInfo64 (test->args, &got, status);
257
- if (test->expectError) {
258
- ASSERT_OR_PRINT_MSG (!ok, "expected error, but got none");
259
- ASSERT_STATUS_CONTAINS (status, test->expectError);
260
- } else {
261
- ASSERT_OK_STATUS (ok, status);
262
- ASSERT_CMPUINT64 (got.value, ==, test->expect.value);
263
- ASSERT_CMPUINT64 (got.min, ==, test->expect.min);
264
- ASSERT_CMPUINT64 (got.max, ==, test->expect.max);
265
- }
266
- mongocrypt_status_destroy (status);
267
- }
115
+ static void _test_RangeTest_Encode_Int64(_mongocrypt_tester_t *tester) {
116
+ Int64Test tests[] = {
117
+ /* Test cases copied from server Int64_NoBounds test ... begin */
118
+ {.args = {.value = INT64_C(9223372036854775807)},
119
+ .expect = {.value = UINT64_C(18446744073709551615), .min = 0, .max = UINT64_MAX}},
120
+ {.args = {.value = 1}, .expect = {.value = UINT64_C(9223372036854775809), .min = 0, .max = UINT64_MAX}},
121
+ {.args = {.value = 0}, .expect = {.value = UINT64_C(9223372036854775808), .min = 0, .max = UINT64_MAX}},
122
+ {.args = {.value = -1}, .expect = {.value = UINT64_C(9223372036854775807), .min = 0, .max = UINT64_MAX}},
123
+ {.args = {.value = -2}, .expect = {.value = UINT64_C(9223372036854775806), .min = 0, .max = UINT64_MAX}},
124
+ {.args = {.value = INT64_C(-9223372036854775807)}, .expect = {.value = 1, .min = 0, .max = UINT64_MAX}},
125
+ {.args = {.value = INT64_MIN}, .expect = {.value = 0, .min = 0, .max = UINT64_MAX}},
126
+ /* Test cases copied from server Int64_NoBounds test ... end */
127
+ /* Test cases copied from server Int64_Bounds test ... begin */
128
+ {.args = {.value = 1, .min = OPT_I64(1), .max = OPT_I64(2)}, .expect = {.value = 0, .min = 0, .max = 1}},
129
+ {.args = {.value = 0, .min = OPT_I64(0), .max = OPT_I64(1)}, .expect = {.value = 0, .min = 0, .max = 1}},
130
+ {.args = {.value = -1, .min = OPT_I64(-1), .max = OPT_I64(0)}, .expect = {.value = 0, .min = 0, .max = 1}},
131
+ {.args = {.value = -2, .min = OPT_I64(-2), .max = OPT_I64(0)}, .expect = {.value = 0, .min = 0, .max = 2}},
132
+ {.args = {.value = INT64_C(-9223372036854775807), .min = OPT_I64(INT64_MIN), .max = OPT_I64(1)},
133
+ .expect = {.value = 1, .min = 0, .max = UINT64_C(9223372036854775809)}},
134
+ {.args = {.value = INT64_MIN, .min = OPT_I64(INT64_MIN), .max = OPT_I64(0)},
135
+ .expect = {.value = 0, .min = 0, .max = UINT64_C(9223372036854775808)}},
136
+ {.args = {.value = 0, .min = OPT_I64(INT64_MIN), .max = OPT_I64(37)},
137
+ .expect = {.value = UINT64_C(9223372036854775808), .min = 0, .max = UINT64_C(9223372036854775845)}},
138
+ {.args = {.value = 1, .min = OPT_I64(INT64_MIN), .max = OPT_I64(42)},
139
+ .expect = {.value = UINT64_C(9223372036854775809), .min = 0, .max = UINT64_C(9223372036854775850)}},
140
+ {.args = {.value = INT64_C(9223372036854775807),
141
+ .min = OPT_I64(-9223372036854775807),
142
+ .max = OPT_I64(9223372036854775807)},
143
+ .expect = {.value = UINT64_C(18446744073709551614), .min = 0, .max = UINT64_C(18446744073709551614)}},
144
+ {.args = {.value = INT64_C(9223372036854775807),
145
+ .min = OPT_I64(INT64_MIN),
146
+ .max = OPT_I64(9223372036854775807)},
147
+ .expect = {.value = UINT64_C(18446744073709551615), .min = 0, .max = UINT64_C(18446744073709551615)}},
148
+ {.args = {.value = 15, .min = OPT_I64(10), .max = OPT_I64(26)}, .expect = {.value = 5, .min = 0, .max = 16}},
149
+ {.args = {.value = 15, .min = OPT_I64(-10), .max = OPT_I64(55)}, .expect = {.value = 25, .min = 0, .max = 65}},
150
+ /* Test cases copied from server Int64_Bounds test ... end */
151
+ /* Test cases copied from server Int64_Errors test ... begin */
152
+ {.args = {.value = 1, .max = OPT_I64(2)},
153
+ .expectError = "Must specify both a lower and upper bound or no bounds."},
154
+ {.args = {.value = 1, .min = OPT_I64(0)},
155
+ .expectError = "Must specify both a lower and upper bound or no bounds."},
156
+ {.args = {.value = 1, .min = OPT_I64(2), .max = OPT_I64(1)},
157
+ .expectError = "The minimum value must be less than the maximum value"},
158
+ {.args = {.value = 1, .min = OPT_I64(2), .max = OPT_I64(3)},
159
+ .expectError = "Value must be greater than or equal to the minimum "
160
+ "value and less than or equal to the maximum value"},
161
+ {.args = {.value = 4, .min = OPT_I64(2), .max = OPT_I64(3)},
162
+ .expectError = "Value must be greater than or equal to the minimum "
163
+ "value and less than or equal to the maximum value"},
164
+ {.args = {.value = 4, .min = OPT_I64(INT64_MIN), .max = OPT_I64(INT64_MIN)},
165
+ .expectError = "The minimum value must be less than the maximum value"},
166
+ /* Test cases copied from server Int64_Errors test ... end */
167
+ };
168
+
169
+ for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
170
+ Int64Test *test = tests + i;
171
+ mongocrypt_status_t *const status = mongocrypt_status_new();
172
+
173
+ // Print a description of the test case.
174
+ printf("_test_RangeTest_Encode_Int64: value=%" PRId64, test->args.value);
175
+ if (test->args.min.set) {
176
+ printf(" min=%" PRId64, test->args.min.value);
177
+ }
178
+ if (test->args.max.set) {
179
+ printf(" max=%" PRId64, test->args.max.value);
180
+ }
181
+ printf("\n");
182
+ mc_OSTType_Int64 got;
183
+ const bool ok = mc_getTypeInfo64(test->args, &got, status);
184
+ if (test->expectError) {
185
+ ASSERT_OR_PRINT_MSG(!ok, "expected error, but got none");
186
+ ASSERT_STATUS_CONTAINS(status, test->expectError);
187
+ } else {
188
+ ASSERT_OK_STATUS(ok, status);
189
+ ASSERT_CMPUINT64(got.value, ==, test->expect.value);
190
+ ASSERT_CMPUINT64(got.min, ==, test->expect.min);
191
+ ASSERT_CMPUINT64(got.max, ==, test->expect.max);
192
+ }
193
+ mongocrypt_status_destroy(status);
194
+ }
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
268
258
  }
269
259
 
270
260
  typedef struct {
271
- double value;
272
- mc_optional_double_t min;
273
- mc_optional_double_t max;
274
- mc_optional_uint32_t precision;
275
- uint64_t expect;
276
- mc_optional_uint64_t expectMax;
277
- const char *expectError;
261
+ double value;
262
+ mc_optional_double_t min;
263
+ mc_optional_double_t max;
264
+ mc_optional_int32_t precision;
265
+ uint64_t expect;
266
+ mc_optional_uint64_t expectMax;
267
+ const char *expectError;
268
+ bool use_range_v1; // By default, use range v2.
278
269
  } DoubleTest;
279
270
 
280
- static void
281
- _test_RangeTest_Encode_Double (_mongocrypt_tester_t *tester)
282
- {
283
- DoubleTest tests[] = {
284
- /* Test cases copied from server Double_Bounds test ... begin */
285
- // Larger numbers map to larger uint64
286
- {.value = -1111, .expect = UINT64_C (4570770991734587392)},
287
- {.value = -111, .expect = UINT64_C (4585860689314185216)},
288
- {.value = -11, .expect = UINT64_C (4600989969312382976)},
289
- {.value = -10, .expect = UINT64_C (4601552919265804288)},
290
- {.value = -3, .expect = UINT64_C (4609434218613702656)},
291
- {.value = -2, .expect = UINT64_C (4611686018427387904)},
292
-
293
- {.value = -1, .expect = UINT64_C (4616189618054758400)},
294
- {.value = 1, .expect = UINT64_C (13830554455654793216)},
295
- {.value = 22, .expect = UINT64_C (13850257704024539136)},
296
- {.value = 333, .expect = UINT64_C (13867937850999177216)},
297
-
298
- // Larger exponents map to larger uint64
299
- {.value = 33E56, .expect = UINT64_C (14690973652625833878)},
300
- {.value = 22E57, .expect = UINT64_C (14703137697061005818)},
301
- {.value = 11E58, .expect = UINT64_C (14713688953586463292)},
302
-
303
- // Smaller exponents map to smaller uint64
304
- {.value = 1E-6, .expect = UINT64_C (13740701229962882445)},
305
- {.value = 1E-7, .expect = UINT64_C (13725520251343122248)},
306
- {.value = 1E-8, .expect = UINT64_C (13710498295186492474)},
307
- {.value = 1E-56, .expect = UINT64_C (12992711961033031890)},
308
- {.value = 1E-57, .expect = UINT64_C (12977434315086142017)},
309
- {.value = 1E-58, .expect = UINT64_C (12962510038552207822)},
310
-
311
- // Smaller negative exponents map to smaller uint64
312
- {.value = -1E-06, .expect = UINT64_C (4706042843746669171)},
313
- {.value = -1E-07, .expect = UINT64_C (4721223822366429368)},
314
- {.value = -1E-08, .expect = UINT64_C (4736245778523059142)},
315
- {.value = -1E-56, .expect = UINT64_C (5454032112676519726)},
316
- {.value = -1E-57, .expect = UINT64_C (5469309758623409599)},
317
- {.value = -1E-58, .expect = UINT64_C (5484234035157343794)},
318
-
319
- // Larger exponents map to larger uint64
320
- {.value = -33E+56, .expect = UINT64_C (3755770421083717738)},
321
- {.value = -22E+57, .expect = UINT64_C (3743606376648545798)},
322
- {.value = -11E+58, .expect = UINT64_C (3733055120123088324)},
323
-
324
- {.value = 0, .expect = UINT64_C (9223372036854775808)},
325
- {.value = -0.0, .expect = UINT64_C (9223372036854775808)},
326
- /* Test cases copied from server Double_Bounds test ... end */
327
- /* Test cases copied from server Double_Errors test ... begin */
328
- {.value = INFINITY,
329
- .expectError = "Infinity and NaN double values are not supported."},
330
- {.value = NAN,
331
- .expectError = "Infinity and NaN double values are not supported."},
332
- /* Test cases copied from server Double_Errors test ... end */
333
-
334
- /* Test cases copied from Double_Bounds_Precision ... begin */
335
- {.value = 3.141592653589,
336
- .precision = OPT_U32_C (1),
337
- .min = OPT_DOUBLE_C (-100000),
338
- .max = OPT_DOUBLE_C (100000),
339
- .expect = UINT64_C (1000031),
340
- .expectMax = OPT_U64_C (2097151)},
341
- {.value = 3.141592653589,
342
- .precision = OPT_U32_C (2),
343
- .min = OPT_DOUBLE_C (-100000),
344
- .max = OPT_DOUBLE_C (100000),
345
- .expect = 10000314,
346
- .expectMax = OPT_U64_C (33554431)},
347
- {.value = 3.141592653589,
348
- .precision = OPT_U32_C (3),
349
- .min = OPT_DOUBLE_C (-100000),
350
- .max = OPT_DOUBLE_C (100000),
351
- .expect = 100003141,
352
- .expectMax = OPT_U64_C (268435455)},
353
- {.value = 3.141592653589,
354
- .precision = OPT_U32_C (4),
355
- .min = OPT_DOUBLE_C (-100000),
356
- .max = OPT_DOUBLE_C (100000),
357
- .expect = 1000031415,
358
- .expectMax = OPT_U64_C (2147483647)},
359
- {.value = 3.141592653589,
360
- .precision = OPT_U32_C (5),
361
- .min = OPT_DOUBLE_C (-100000),
362
- .max = OPT_DOUBLE_C (100000),
363
- .expect = 10000314159,
364
- .expectMax = OPT_U64_C (34359738367)},
365
- {.value = 3.141592653589,
366
- .precision = OPT_U32_C (6),
367
- .min = OPT_DOUBLE_C (-100000),
368
- .max = OPT_DOUBLE_C (100000),
369
- .expect = 100003141592,
370
- .expectMax = OPT_U64_C (274877906943)},
371
- {.value = 3.141592653589,
372
- .precision = OPT_U32_C (7),
373
- .min = OPT_DOUBLE_C (-100000),
374
- .max = OPT_DOUBLE_C (100000),
375
- .expect = 1000031415926,
376
- .expectMax = OPT_U64_C (2199023255551)},
377
- {.value = 0,
378
- .max = OPT_DOUBLE_C (1),
379
- .min = OPT_DOUBLE_C (-1),
380
- .precision = OPT_U32_C (3),
381
- .expect = 1000,
382
- .expectMax = OPT_U64_C (4095)},
383
- {.value = 0,
384
- .max = OPT_DOUBLE_C (1),
385
- .min = OPT_DOUBLE_C (-1E5),
386
- .precision = OPT_U32_C (3),
387
- .expect = 100000000,
388
- .expectMax = OPT_U64_C (134217727)},
389
- {.value = -1E-33,
390
- .max = OPT_DOUBLE_C (1),
391
- .min = OPT_DOUBLE_C (-1E5),
392
- .precision = OPT_U32_C (3),
393
- .expect = 100000000,
394
- .expectMax = OPT_U64_C (134217727)},
395
- {.value = 0,
396
- .max = OPT_DOUBLE_C (DBL_MAX),
397
- .min = OPT_DOUBLE_C (-DBL_MAX),
398
- .precision = OPT_U32_C (3),
399
- .expect = UINT64_C (9223372036854775808),
400
- // Expect precision not to be used.
401
- .expectMax = OPT_U64_C (UINT64_MAX)},
402
- {.value = 3.141592653589,
403
- .max = OPT_DOUBLE_C (5),
404
- .min = OPT_DOUBLE_C (0),
405
- .precision = OPT_U32_C (0),
406
- .expect = 3,
407
- .expectMax = OPT_U64_C (7)},
408
- {.value = 3.141592653589,
409
- .max = OPT_DOUBLE_C (5),
410
- .min = OPT_DOUBLE_C (0),
411
- .precision = OPT_U32_C (1),
412
- .expect = 31,
413
- .expectMax = OPT_U64_C (63)},
414
- {.value = 3.141592653589,
415
- .max = OPT_DOUBLE_C (5),
416
- .min = OPT_DOUBLE_C (0),
417
- .precision = OPT_U32_C (2),
418
- .expect = 314,
419
- .expectMax = OPT_U64_C (1023)},
420
- {.value = 3.141592653589,
421
- .max = OPT_DOUBLE_C (5),
422
- .min = OPT_DOUBLE_C (0),
423
- .precision = OPT_U32_C (3),
424
- .expect = 3141,
425
- .expectMax = OPT_U64_C (8191)},
426
- {.value = 3.141592653589,
427
- .max = OPT_DOUBLE_C (5),
428
- .min = OPT_DOUBLE_C (0),
429
- .precision = OPT_U32_C (16),
430
- .expect = 31415926535890000,
431
- .expectMax = OPT_U64_C (72057594037927935)},
432
- {.value = -5,
433
- .max = OPT_DOUBLE_C (-1),
434
- .min = OPT_DOUBLE_C (-10),
435
- .precision = OPT_U32_C (3),
436
- .expect = 5000,
437
- .expectMax = OPT_U64_C (16383)},
438
- {.value = 1E100,
439
- .max = OPT_DOUBLE_C (DBL_MAX),
440
- .min = OPT_DOUBLE_C (-DBL_MAX),
441
- .precision = OPT_U32_C (3),
442
- .expect = 15326393489903895421ULL,
443
- // Expect precision not to be used.
444
- .expectMax = OPT_U64_C (UINT64_MAX)},
445
- {.value = 1E9,
446
- .max = OPT_DOUBLE_C (1E10),
447
- .min = OPT_DOUBLE_C (0),
448
- .precision = OPT_U32_C (3),
449
- .expect = 1000000000000,
450
- .expectMax = OPT_U64_C (17592186044415)},
451
- {.value = 1E9,
452
- .max = OPT_DOUBLE_C (1E10),
453
- .min = OPT_DOUBLE_C (0),
454
- .precision = OPT_U32_C (0),
455
- .expect = 1000000000,
456
- .expectMax = OPT_U64_C (17179869183)},
457
- {.value = -5,
458
- .max = OPT_DOUBLE_C (10),
459
- .min = OPT_DOUBLE_C (-10),
460
- .precision = OPT_U32_C (0),
461
- .expect = 5,
462
- .expectMax = OPT_U64_C (31)},
463
- {.value = -5,
464
- .max = OPT_DOUBLE_C (10),
465
- .min = OPT_DOUBLE_C (-10),
466
- .precision = OPT_U32_C (2),
467
- .expect = 500,
468
- .expectMax = OPT_U64_C (4095)},
469
- {.value = 1E-30,
470
- .max = OPT_DOUBLE_C (10E-30),
471
- .min = OPT_DOUBLE_C (1E-30),
472
- .precision = OPT_U32_C (35),
473
- .expect = 13381399884061196960ULL,
474
- // Expect precision not to be used.
475
- .expectMax = OPT_U64_C (UINT64_MAX)},
476
- /* Test cases copied from Double_Bounds_Precision ... end */
477
- {.value = -1,
478
- .min = OPT_DOUBLE_C (0),
479
- .max = OPT_DOUBLE_C (200),
480
- .precision = OPT_U32_C (1),
481
- .expectError = "greater than or equal to the minimum value"},
482
- {.value = -1,
483
- .min = OPT_DOUBLE_C (0),
484
- .max = OPT_DOUBLE_C (201),
485
- .precision = OPT_U32_C (1),
486
- .expectError = "less than or equal to the maximum value"}};
487
-
488
- for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) {
489
- DoubleTest *test = tests + i;
490
- mongocrypt_status_t *const status = mongocrypt_status_new ();
491
-
492
- if (test->min.set && test->max.set && test->precision.set) {
493
- printf ("_test_RangeTest_Encode_Double: value=%f, min=%f, max=%f, "
494
- "precision=%" PRIu32 "\n",
495
- test->value,
496
- test->min.value,
497
- test->max.value,
498
- test->precision.value);
499
- } else {
500
- printf ("_test_RangeTest_Encode_Double: value=%f\n", test->value);
501
- }
502
-
503
- mc_OSTType_Double got;
504
- const bool ok = mc_getTypeInfoDouble (
505
- (mc_getTypeInfoDouble_args_t){.value = test->value,
506
- .min = test->min,
507
- .max = test->max,
508
- .precision = test->precision},
509
- &got,
510
- status);
511
- if (test->expectError) {
512
- ASSERT_OR_PRINT_MSG (!ok, "expected error, but got none");
513
- ASSERT_STATUS_CONTAINS (status, test->expectError);
514
- } else {
515
- ASSERT_OK_STATUS (ok, status);
516
- ASSERT_CMPUINT64 (got.value, ==, test->expect);
517
- ASSERT_CMPUINT64 (got.min, ==, 0);
518
- ASSERT_CMPUINT64 (got.max,
519
- ==,
520
- test->expectMax.set ? test->expectMax.value
521
- : UINT64_MAX);
522
- }
523
- mongocrypt_status_destroy (status);
524
- }
525
- }
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
+
275
+ static void _test_RangeTest_Encode_Double(_mongocrypt_tester_t *tester) {
276
+ DoubleTest tests[] = {/* Test cases copied from server Double_Bounds test ... begin */
277
+ // Larger numbers map to larger uint64
278
+ {.value = -1111, .expect = UINT64_C(4570770991734587392)},
279
+ {.value = -111, .expect = UINT64_C(4585860689314185216)},
280
+ {.value = -11, .expect = UINT64_C(4600989969312382976)},
281
+ {.value = -10, .expect = UINT64_C(4601552919265804288)},
282
+ {.value = -3, .expect = UINT64_C(4609434218613702656)},
283
+ {.value = -2, .expect = UINT64_C(4611686018427387904)},
284
+
285
+ {.value = -1, .expect = UINT64_C(4616189618054758400)},
286
+ {.value = 1, .expect = UINT64_C(13830554455654793216)},
287
+ {.value = 22, .expect = UINT64_C(13850257704024539136)},
288
+ {.value = 333, .expect = UINT64_C(13867937850999177216)},
289
+
290
+ // Larger exponents map to larger uint64
291
+ {.value = 33E56, .expect = UINT64_C(14690973652625833878)},
292
+ {.value = 22E57, .expect = UINT64_C(14703137697061005818)},
293
+ {.value = 11E58, .expect = UINT64_C(14713688953586463292)},
526
294
 
295
+ // Smaller exponents map to smaller uint64
296
+ {.value = 1E-6, .expect = UINT64_C(13740701229962882445)},
297
+ {.value = 1E-7, .expect = UINT64_C(13725520251343122248)},
298
+ {.value = 1E-8, .expect = UINT64_C(13710498295186492474)},
299
+ {.value = 1E-56, .expect = UINT64_C(12992711961033031890)},
300
+ {.value = 1E-57, .expect = UINT64_C(12977434315086142017)},
301
+ {.value = 1E-58, .expect = UINT64_C(12962510038552207822)},
302
+
303
+ // Smaller negative exponents map to smaller uint64
304
+ {.value = -1E-06, .expect = UINT64_C(4706042843746669171)},
305
+ {.value = -1E-07, .expect = UINT64_C(4721223822366429368)},
306
+ {.value = -1E-08, .expect = UINT64_C(4736245778523059142)},
307
+ {.value = -1E-56, .expect = UINT64_C(5454032112676519726)},
308
+ {.value = -1E-57, .expect = UINT64_C(5469309758623409599)},
309
+ {.value = -1E-58, .expect = UINT64_C(5484234035157343794)},
310
+
311
+ // Larger exponents map to larger uint64
312
+ {.value = -33E+56, .expect = UINT64_C(3755770421083717738)},
313
+ {.value = -22E+57, .expect = UINT64_C(3743606376648545798)},
314
+ {.value = -11E+58, .expect = UINT64_C(3733055120123088324)},
315
+
316
+ {.value = 0, .expect = UINT64_C(9223372036854775808)},
317
+ {.value = -0.0, .expect = UINT64_C(9223372036854775808)},
318
+ /* Test cases copied from server Double_Bounds test ... end */
319
+ /* Test cases copied from server Double_Errors test ... begin */
320
+ {.value = INFINITY, .expectError = "Infinity and NaN double values are not supported."},
321
+ {.value = NAN, .expectError = "Infinity and NaN double values are not supported."},
322
+ /* Test cases copied from server Double_Errors test ... end */
323
+
324
+ /* Test cases copied from Double_Bounds_Precision ... begin */
325
+ {.value = 3.141592653589,
326
+ .precision = OPT_I32_C(1),
327
+ .min = OPT_DOUBLE_C(-100000),
328
+ .max = OPT_DOUBLE_C(100000),
329
+ .expect = UINT64_C(1000031),
330
+ .expectMax = OPT_U64_C(2097151)},
331
+ {.value = 3.141592653589,
332
+ .precision = OPT_I32_C(2),
333
+ .min = OPT_DOUBLE_C(-100000),
334
+ .max = OPT_DOUBLE_C(100000),
335
+ .expect = 10000314,
336
+ .expectMax = OPT_U64_C(33554431)},
337
+ {.value = 3.141592653589,
338
+ .precision = OPT_I32_C(3),
339
+ .min = OPT_DOUBLE_C(-100000),
340
+ .max = OPT_DOUBLE_C(100000),
341
+ .expect = 100003141,
342
+ .expectMax = OPT_U64_C(268435455)},
343
+ {.value = 3.141592653589,
344
+ .precision = OPT_I32_C(4),
345
+ .min = OPT_DOUBLE_C(-100000),
346
+ .max = OPT_DOUBLE_C(100000),
347
+ .expect = 1000031415,
348
+ .expectMax = OPT_U64_C(2147483647)},
349
+ {.value = 3.141592653589,
350
+ .precision = OPT_I32_C(5),
351
+ .min = OPT_DOUBLE_C(-100000),
352
+ .max = OPT_DOUBLE_C(100000),
353
+ .expect = 10000314159,
354
+ .expectMax = OPT_U64_C(34359738367)},
355
+ {.value = 3.141592653589,
356
+ .precision = OPT_I32_C(6),
357
+ .min = OPT_DOUBLE_C(-100000),
358
+ .max = OPT_DOUBLE_C(100000),
359
+ .expect = 100003141592,
360
+ .expectMax = OPT_U64_C(274877906943)},
361
+ {.value = 3.141592653589,
362
+ .precision = OPT_I32_C(7),
363
+ .min = OPT_DOUBLE_C(-100000),
364
+ .max = OPT_DOUBLE_C(100000),
365
+ .expect = 1000031415926,
366
+ .expectMax = OPT_U64_C(2199023255551)},
367
+ {.value = 0,
368
+ .max = OPT_DOUBLE_C(1),
369
+ .min = OPT_DOUBLE_C(-1),
370
+ .precision = OPT_I32_C(3),
371
+ .expect = 1000,
372
+ .expectMax = OPT_U64_C(4095)},
373
+ {.value = 0,
374
+ .max = OPT_DOUBLE_C(1),
375
+ .min = OPT_DOUBLE_C(-1E5),
376
+ .precision = OPT_I32_C(3),
377
+ .expect = 100000000,
378
+ .expectMax = OPT_U64_C(134217727)},
379
+ {.value = -1E-33,
380
+ .max = OPT_DOUBLE_C(1),
381
+ .min = OPT_DOUBLE_C(-1E5),
382
+ .precision = OPT_I32_C(3),
383
+ .expect = 100000000,
384
+ .expectMax = OPT_U64_C(134217727)},
385
+ {.value = 0,
386
+ .max = OPT_DOUBLE_C(DBL_MAX),
387
+ .min = OPT_DOUBLE_C(-DBL_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."},
399
+ {.value = 3.141592653589,
400
+ .max = OPT_DOUBLE_C(5),
401
+ .min = OPT_DOUBLE_C(0),
402
+ .precision = OPT_I32_C(0),
403
+ .expect = 3,
404
+ .expectMax = OPT_U64_C(7)},
405
+ {.value = 3.141592653589,
406
+ .max = OPT_DOUBLE_C(5),
407
+ .min = OPT_DOUBLE_C(0),
408
+ .precision = OPT_I32_C(1),
409
+ .expect = 31,
410
+ .expectMax = OPT_U64_C(63)},
411
+ {.value = 3.141592653589,
412
+ .max = OPT_DOUBLE_C(5),
413
+ .min = OPT_DOUBLE_C(0),
414
+ .precision = OPT_I32_C(2),
415
+ .expect = 314,
416
+ .expectMax = OPT_U64_C(1023)},
417
+ {.value = 3.141592653589,
418
+ .max = OPT_DOUBLE_C(5),
419
+ .min = OPT_DOUBLE_C(0),
420
+ .precision = OPT_I32_C(3),
421
+ .expect = 3141,
422
+ .expectMax = OPT_U64_C(8191)},
423
+ {.value = 3.141592653589,
424
+ .max = OPT_DOUBLE_C(5),
425
+ .min = OPT_DOUBLE_C(0),
426
+ .precision = OPT_I32_C(16),
427
+ .expectError = "Invalid upper bound for double precision"},
428
+ {.value = -5,
429
+ .max = OPT_DOUBLE_C(-1),
430
+ .min = OPT_DOUBLE_C(-10),
431
+ .precision = OPT_I32_C(3),
432
+ .expect = 5000,
433
+ .expectMax = OPT_U64_C(16383)},
434
+ {.value = 1E100,
435
+ .max = OPT_DOUBLE_C(DBL_MAX),
436
+ .min = OPT_DOUBLE_C(-DBL_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."},
448
+ {.value = 1E9,
449
+ .max = OPT_DOUBLE_C(1E10),
450
+ .min = OPT_DOUBLE_C(0),
451
+ .precision = OPT_I32_C(3),
452
+ .expect = 1000000000000,
453
+ .expectMax = OPT_U64_C(17592186044415)},
454
+ {.value = 1E9,
455
+ .max = OPT_DOUBLE_C(1E10),
456
+ .min = OPT_DOUBLE_C(0),
457
+ .precision = OPT_I32_C(0),
458
+ .expect = 1000000000,
459
+ .expectMax = OPT_U64_C(17179869183)},
460
+ {.value = -5,
461
+ .max = OPT_DOUBLE_C(10),
462
+ .min = OPT_DOUBLE_C(-10),
463
+ .precision = OPT_I32_C(0),
464
+ .expect = 5,
465
+ .expectMax = OPT_U64_C(31)},
466
+ {.value = -5,
467
+ .max = OPT_DOUBLE_C(10),
468
+ .min = OPT_DOUBLE_C(-10),
469
+ .precision = OPT_I32_C(2),
470
+ .expect = 500,
471
+ .expectMax = OPT_U64_C(4095)},
472
+ {.value = 1E-30,
473
+ .max = OPT_DOUBLE_C(10E-30),
474
+ .min = OPT_DOUBLE_C(1E-30),
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"},
524
+ /* Test cases copied from Double_Bounds_Precision ... end */
525
+ {.value = -1,
526
+ .min = OPT_DOUBLE_C(0),
527
+ .max = OPT_DOUBLE_C(200),
528
+ .precision = OPT_I32_C(1),
529
+ .expectError = "greater than or equal to the minimum value"},
530
+ {.value = -1,
531
+ .min = OPT_DOUBLE_C(0),
532
+ .max = OPT_DOUBLE_C(201),
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"}};
548
+
549
+ for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
550
+ DoubleTest *test = tests + i;
551
+ mongocrypt_status_t *const status = mongocrypt_status_new();
552
+
553
+ if (test->min.set && test->max.set && test->precision.set) {
554
+ printf("_test_RangeTest_Encode_Double: value=%f, min=%f, max=%f, "
555
+ "precision=%" PRIu32 "\n",
556
+ test->value,
557
+ test->min.value,
558
+ test->max.value,
559
+ test->precision.value);
560
+ } else {
561
+ printf("_test_RangeTest_Encode_Double: value=%f\n", test->value);
562
+ }
563
+
564
+ const bool use_range_v2 = !test->use_range_v1;
565
+ mc_OSTType_Double got;
566
+ const bool ok = mc_getTypeInfoDouble((mc_getTypeInfoDouble_args_t){.value = test->value,
567
+ .min = test->min,
568
+ .max = test->max,
569
+ .precision = test->precision},
570
+ &got,
571
+ status,
572
+ use_range_v2);
573
+ if (test->expectError) {
574
+ ASSERT_OR_PRINT_MSG(!ok, "expected error, but got none");
575
+ ASSERT_STATUS_CONTAINS(status, test->expectError);
576
+ } else {
577
+ ASSERT_OK_STATUS(ok, status);
578
+ ASSERT_CMPUINT64(got.value, ==, test->expect);
579
+ ASSERT_CMPUINT64(got.min, ==, 0);
580
+ ASSERT_CMPUINT64(got.max, ==, test->expectMax.set ? test->expectMax.value : UINT64_MAX);
581
+ }
582
+ mongocrypt_status_destroy(status);
583
+ }
584
+ }
527
585
 
528
586
  #if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
529
587
  typedef struct {
530
- mc_dec128 value;
531
- mc_optional_dec128_t min;
532
- mc_optional_dec128_t max;
533
- mc_optional_uint32_t precision;
534
- mlib_int128 expect;
535
- const char *expectError;
588
+ mc_dec128 value;
589
+ mc_optional_dec128_t min;
590
+ mc_optional_dec128_t max;
591
+ mc_optional_int32_t precision;
592
+ mlib_int128 expect;
593
+ const char *expectError;
594
+ bool use_range_v1; // By default, use range v2.
536
595
  } Decimal128Test;
537
596
 
538
- static void
539
- _test_RangeTest_Encode_Decimal128 (_mongocrypt_tester_t *tester)
540
- {
541
- Decimal128Test tests[] = {
542
- #define CASE(Value, ExpectStr) \
543
- (Decimal128Test){.value = mc_dec128_from_string (#Value), \
544
- .expect = mlib_int128_from_string (ExpectStr, NULL)}
545
- /* Test cases copied from server Decimal128_Bounds test ... begin */
546
- // Larger numbers map to larger int128
547
- CASE (-1234567890E7, "108549948892579231731687303715884111887"),
548
- CASE (-1234567890E6, "108559948892579231731687303715884111886"),
549
- CASE (-1234567890E5, "108569948892579231731687303715884111885"),
550
- CASE (-1234567890E4, "108579948892579231731687303715884111884"),
551
- CASE (-1234567890E3, "108589948892579231731687303715884111883"),
552
- CASE (-1234567890E2, "108599948892579231731687303715884111882"),
553
- CASE (-1234567890E1, "108609948892579231731687303715884111881"),
554
- CASE (-123456789012345, "108569948892579108281687303715884111885"),
555
- CASE (-12345678901234, "108579948892579108331687303715884111884"),
556
- CASE (-1234567890123, "108589948892579108731687303715884111883"),
557
- CASE (-123456789012, "108599948892579111731687303715884111882"),
558
- CASE (-12345678901, "108609948892579131731687303715884111881"),
559
- CASE (-1234567890, "108619948892579231731687303715884111880"),
560
- CASE (-99999999, "108631183460569231731687303715884111878"),
561
- CASE (-8888888, "108642294572469231731687303715884111877"),
562
- CASE (-777777, "108653405690469231731687303715884111876"),
563
- CASE (-66666, "108664516860469231731687303715884111875"),
564
- CASE (-5555, "108675628460469231731687303715884111874"),
565
- CASE (-444, "108686743460469231731687303715884111873"),
566
- CASE (-334, "108687843460469231731687303715884111873"),
567
- CASE (-333, "108687853460469231731687303715884111873"),
568
- CASE (-44, "108696783460469231731687303715884111872"),
569
- CASE (-33, "108697883460469231731687303715884111872"),
570
- CASE (-22, "108698983460469231731687303715884111872"),
571
- CASE (-5, "108706183460469231731687303715884111871"),
572
- CASE (-4, "108707183460469231731687303715884111871"),
573
- CASE (-3, "108708183460469231731687303715884111871"),
574
- CASE (-2, "108709183460469231731687303715884111871"),
575
- CASE (-1, "108710183460469231731687303715884111871"),
576
- CASE (0, "170141183460469231731687303715884105728"),
577
- CASE (1, "231572183460469231731687303715884099585"),
578
- CASE (2, "231573183460469231731687303715884099585"),
579
- CASE (3, "231574183460469231731687303715884099585"),
580
- CASE (4, "231575183460469231731687303715884099585"),
581
- CASE (5, "231576183460469231731687303715884099585"),
582
- CASE (22, "231583383460469231731687303715884099584"),
583
- CASE (33, "231584483460469231731687303715884099584"),
584
- CASE (44, "231585583460469231731687303715884099584"),
585
- CASE (333, "231594513460469231731687303715884099583"),
586
- CASE (334, "231594523460469231731687303715884099583"),
587
- CASE (444, "231595623460469231731687303715884099583"),
588
- CASE (5555, "231606738460469231731687303715884099582"),
589
- CASE (66666, "231617850060469231731687303715884099581"),
590
- CASE (777777, "231628961230469231731687303715884099580"),
591
- CASE (8888888, "231640072348469231731687303715884099579"),
592
- CASE (33E56, "232144483460469231731687303715884099528"),
593
- CASE (22E57, "232153383460469231731687303715884099527"),
594
- CASE (11E58, "232162283460469231731687303715884099526"),
595
-
596
- // Smaller exponents map to smaller int128
597
- CASE (1E-6, "231512183460469231731687303715884099591"),
598
- CASE (1E-7, "231502183460469231731687303715884099592"),
599
- CASE (1E-8, "231492183460469231731687303715884099593"),
600
- CASE (1E-56, "231012183460469231731687303715884099641"),
601
- CASE (1E-57, "231002183460469231731687303715884099642"),
602
- CASE (1E-58, "230992183460469231731687303715884099643"),
603
-
604
- // Smaller negative exponents map to smaller int128
605
- CASE (-1E-6, "108770183460469231731687303715884111865"),
606
- CASE (-1E-7, "108780183460469231731687303715884111864"),
607
- CASE (-1E-8, "108790183460469231731687303715884111863"),
608
- CASE (-1E-56, "109270183460469231731687303715884111815"),
609
- CASE (-1E-57, "109280183460469231731687303715884111814"),
610
- CASE (-1E-58, "109290183460469231731687303715884111813"),
611
-
612
- // Larger exponents map to larger int128
613
- CASE (-33E56, "108137883460469231731687303715884111928"),
614
- CASE (-22E57, "108128983460469231731687303715884111929"),
615
- CASE (-11E58, "108120083460469231731687303715884111930"),
616
-
617
- (Decimal128Test){.value = MC_DEC128_LARGEST_POSITIVE,
618
- .expect = mlib_int128_from_string (
619
- "293021183460469231731687303715884093440", NULL)},
620
- (Decimal128Test){.value = MC_DEC128_SMALLEST_POSITIVE,
621
- .expect = mlib_int128_from_string (
622
- "170141183460469231731687303715884105729", NULL)},
623
- (Decimal128Test){.value = MC_DEC128_LARGEST_NEGATIVE,
624
- .expect = mlib_int128_from_string (
625
- "47261183460469231731687303715884118016", NULL)},
626
- (Decimal128Test){.value = MC_DEC128_SMALLEST_NEGATIVE,
627
- .expect = mlib_int128_from_string (
628
- "170141183460469231731687303715884105727", NULL)},
629
- (Decimal128Test){.value = MC_DEC128_NORMALIZED_ZERO,
630
- .expect = mlib_int128_from_string (
631
- "170141183460469231731687303715884105728", NULL)},
632
- (Decimal128Test){.value = MC_DEC128_NEGATIVE_EXPONENT_ZERO,
633
- .expect = mlib_int128_from_string (
634
- "170141183460469231731687303715884105728", NULL)},
635
- /* Test cases copied from server Decimal128_Bounds test ... end */
636
-
637
- #define ERROR_CASE(Value, Min, Max, Precision, ErrorString) \
638
- (Decimal128Test){ \
639
- .value = Value, \
640
- .min = Min, \
641
- .max = Max, \
642
- .precision = Precision, \
643
- .expectError = ErrorString, \
644
- }
645
-
646
- ERROR_CASE (
647
- MC_DEC128_C (1),
648
- OPT_NULLOPT,
649
- OPT_MC_DEC128 (MC_DEC128_C (2)),
650
- OPT_U32 (5),
651
- "min, max, and precision must all be set or must all be unset"),
652
- ERROR_CASE (
653
- MC_DEC128_C (1),
654
- OPT_MC_DEC128 (MC_DEC128_C (0)),
655
- OPT_NULLOPT,
656
- OPT_U32 (5),
657
- "min, max, and precision must all be set or must all be unset"),
658
- ERROR_CASE (MC_DEC128_C (1),
659
- OPT_MC_DEC128 (MC_DEC128_C (2)),
660
- OPT_MC_DEC128 (MC_DEC128_C (1)),
661
- OPT_U32 (5),
662
- "The minimum value must be less than the maximum value"),
663
-
664
- ERROR_CASE (MC_DEC128_C (1),
665
- OPT_MC_DEC128 (MC_DEC128_C (2)),
666
- OPT_MC_DEC128 (MC_DEC128_C (3)),
667
- OPT_U32 (5),
668
- "Value must be greater than or equal to the minimum value "
669
- "and less than or equal to the maximum value"),
670
- ERROR_CASE (MC_DEC128_C (4),
671
- OPT_MC_DEC128 (MC_DEC128_C (2)),
672
- OPT_MC_DEC128 (MC_DEC128_C (3)),
673
- OPT_U32 (5),
674
- "Value must be greater than or equal to the minimum value "
675
- "and less than or equal to the maximum value"),
676
-
677
- ERROR_CASE (MC_DEC128_POSITIVE_INFINITY,
678
- OPT_NULLOPT,
679
- OPT_NULLOPT,
680
- OPT_NULLOPT,
681
- "Infinity and Nan Decimal128 values are not supported."),
682
- ERROR_CASE (MC_DEC128_NEGATIVE_INFINITY,
683
- OPT_NULLOPT,
684
- OPT_NULLOPT,
685
- OPT_NULLOPT,
686
- "Infinity and Nan Decimal128 values are not supported."),
687
-
688
- ERROR_CASE (MC_DEC128_POSITIVE_NAN,
689
- OPT_NULLOPT,
690
- OPT_NULLOPT,
691
- OPT_NULLOPT,
692
- "Infinity and Nan Decimal128 values are not supported."),
693
-
694
- ERROR_CASE (MC_DEC128_NEGATIVE_NAN,
695
- OPT_NULLOPT,
696
- OPT_NULLOPT,
697
- OPT_NULLOPT,
698
- "Infinity and Nan Decimal128 values are not supported."),
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
+
673
+ static void _test_RangeTest_Encode_Decimal128(_mongocrypt_tester_t *tester) {
674
+ Decimal128Test tests[] = {
675
+ #define CASE(Value, ExpectStr) \
676
+ (Decimal128Test){.value = mc_dec128_from_string(#Value), .expect = mlib_int128_from_string(ExpectStr, NULL)}
677
+ /* Test cases copied from server Decimal128_Bounds test ... begin */
678
+ // Larger numbers map to larger int128
679
+ CASE(-1234567890E7, "108549948892579231731687303715884111887"),
680
+ CASE(-1234567890E6, "108559948892579231731687303715884111886"),
681
+ CASE(-1234567890E5, "108569948892579231731687303715884111885"),
682
+ CASE(-1234567890E4, "108579948892579231731687303715884111884"),
683
+ CASE(-1234567890E3, "108589948892579231731687303715884111883"),
684
+ CASE(-1234567890E2, "108599948892579231731687303715884111882"),
685
+ CASE(-1234567890E1, "108609948892579231731687303715884111881"),
686
+ CASE(-123456789012345, "108569948892579108281687303715884111885"),
687
+ CASE(-12345678901234, "108579948892579108331687303715884111884"),
688
+ CASE(-1234567890123, "108589948892579108731687303715884111883"),
689
+ CASE(-123456789012, "108599948892579111731687303715884111882"),
690
+ CASE(-12345678901, "108609948892579131731687303715884111881"),
691
+ CASE(-1234567890, "108619948892579231731687303715884111880"),
692
+ CASE(-99999999, "108631183460569231731687303715884111878"),
693
+ CASE(-8888888, "108642294572469231731687303715884111877"),
694
+ CASE(-777777, "108653405690469231731687303715884111876"),
695
+ CASE(-66666, "108664516860469231731687303715884111875"),
696
+ CASE(-5555, "108675628460469231731687303715884111874"),
697
+ CASE(-444, "108686743460469231731687303715884111873"),
698
+ CASE(-334, "108687843460469231731687303715884111873"),
699
+ CASE(-333, "108687853460469231731687303715884111873"),
700
+ CASE(-44, "108696783460469231731687303715884111872"),
701
+ CASE(-33, "108697883460469231731687303715884111872"),
702
+ CASE(-22, "108698983460469231731687303715884111872"),
703
+ CASE(-5, "108706183460469231731687303715884111871"),
704
+ CASE(-4, "108707183460469231731687303715884111871"),
705
+ CASE(-3, "108708183460469231731687303715884111871"),
706
+ CASE(-2, "108709183460469231731687303715884111871"),
707
+ CASE(-1, "108710183460469231731687303715884111871"),
708
+ CASE(0, "170141183460469231731687303715884105728"),
709
+ CASE(1, "231572183460469231731687303715884099585"),
710
+ CASE(2, "231573183460469231731687303715884099585"),
711
+ CASE(3, "231574183460469231731687303715884099585"),
712
+ CASE(4, "231575183460469231731687303715884099585"),
713
+ CASE(5, "231576183460469231731687303715884099585"),
714
+ CASE(22, "231583383460469231731687303715884099584"),
715
+ CASE(33, "231584483460469231731687303715884099584"),
716
+ CASE(44, "231585583460469231731687303715884099584"),
717
+ CASE(333, "231594513460469231731687303715884099583"),
718
+ CASE(334, "231594523460469231731687303715884099583"),
719
+ CASE(444, "231595623460469231731687303715884099583"),
720
+ CASE(5555, "231606738460469231731687303715884099582"),
721
+ CASE(66666, "231617850060469231731687303715884099581"),
722
+ CASE(777777, "231628961230469231731687303715884099580"),
723
+ CASE(8888888, "231640072348469231731687303715884099579"),
724
+ CASE(33E56, "232144483460469231731687303715884099528"),
725
+ CASE(22E57, "232153383460469231731687303715884099527"),
726
+ CASE(11E58, "232162283460469231731687303715884099526"),
727
+
728
+ // Smaller exponents map to smaller int128
729
+ CASE(1E-6, "231512183460469231731687303715884099591"),
730
+ CASE(1E-7, "231502183460469231731687303715884099592"),
731
+ CASE(1E-8, "231492183460469231731687303715884099593"),
732
+ CASE(1E-56, "231012183460469231731687303715884099641"),
733
+ CASE(1E-57, "231002183460469231731687303715884099642"),
734
+ CASE(1E-58, "230992183460469231731687303715884099643"),
735
+
736
+ // Smaller negative exponents map to smaller int128
737
+ CASE(-1E-6, "108770183460469231731687303715884111865"),
738
+ CASE(-1E-7, "108780183460469231731687303715884111864"),
739
+ CASE(-1E-8, "108790183460469231731687303715884111863"),
740
+ CASE(-1E-56, "109270183460469231731687303715884111815"),
741
+ CASE(-1E-57, "109280183460469231731687303715884111814"),
742
+ CASE(-1E-58, "109290183460469231731687303715884111813"),
743
+
744
+ // Larger exponents map to larger int128
745
+ CASE(-33E56, "108137883460469231731687303715884111928"),
746
+ CASE(-22E57, "108128983460469231731687303715884111929"),
747
+ CASE(-11E58, "108120083460469231731687303715884111930"),
748
+
749
+ (Decimal128Test){.value = MC_DEC128_LARGEST_POSITIVE,
750
+ .expect = mlib_int128_from_string("293021183460469231731687303715884093440", NULL)},
751
+ (Decimal128Test){.value = MC_DEC128_SMALLEST_POSITIVE,
752
+ .expect = mlib_int128_from_string("170141183460469231731687303715884105729", NULL)},
753
+ (Decimal128Test){.value = MC_DEC128_LARGEST_NEGATIVE,
754
+ .expect = mlib_int128_from_string("47261183460469231731687303715884118016", NULL)},
755
+ (Decimal128Test){.value = MC_DEC128_SMALLEST_NEGATIVE,
756
+ .expect = mlib_int128_from_string("170141183460469231731687303715884105727", NULL)},
757
+ (Decimal128Test){.value = MC_DEC128_NORMALIZED_ZERO,
758
+ .expect = mlib_int128_from_string("170141183460469231731687303715884105728", NULL)},
759
+ (Decimal128Test){.value = MC_DEC128_NEGATIVE_EXPONENT_ZERO,
760
+ .expect = mlib_int128_from_string("170141183460469231731687303715884105728", NULL)},
761
+ /* Test cases copied from server Decimal128_Bounds test ... end */
762
+
763
+ #define ERROR_CASE(Value, Min, Max, Precision, ErrorString) \
764
+ (Decimal128Test){ \
765
+ .value = Value, \
766
+ .min = Min, \
767
+ .max = Max, \
768
+ .precision = Precision, \
769
+ .expectError = ErrorString, \
770
+ }
771
+
772
+ ERROR_CASE(MC_DEC128_C(1),
773
+ OPT_NULLOPT,
774
+ OPT_MC_DEC128(MC_DEC128_C(2)),
775
+ OPT_I32(5),
776
+ "min, max, and precision must all be set or must all be unset"),
777
+ ERROR_CASE(MC_DEC128_C(1),
778
+ OPT_MC_DEC128(MC_DEC128_C(0)),
779
+ OPT_NULLOPT,
780
+ OPT_I32(5),
781
+ "min, max, and precision must all be set or must all be unset"),
782
+ ERROR_CASE(MC_DEC128_C(1),
783
+ OPT_MC_DEC128(MC_DEC128_C(2)),
784
+ OPT_MC_DEC128(MC_DEC128_C(1)),
785
+ OPT_I32(5),
786
+ "The minimum value must be less than the maximum value"),
787
+
788
+ ERROR_CASE(MC_DEC128_C(1),
789
+ OPT_MC_DEC128(MC_DEC128_C(2)),
790
+ OPT_MC_DEC128(MC_DEC128_C(3)),
791
+ OPT_I32(5),
792
+ "Value must be greater than or equal to the minimum value "
793
+ "and less than or equal to the maximum value"),
794
+ ERROR_CASE(MC_DEC128_C(4),
795
+ OPT_MC_DEC128(MC_DEC128_C(2)),
796
+ OPT_MC_DEC128(MC_DEC128_C(3)),
797
+ OPT_I32(5),
798
+ "Value must be greater than or equal to the minimum value "
799
+ "and less than or equal to the maximum value"),
800
+
801
+ ERROR_CASE(MC_DEC128_POSITIVE_INFINITY,
802
+ OPT_NULLOPT,
803
+ OPT_NULLOPT,
804
+ OPT_NULLOPT,
805
+ "Infinity and Nan Decimal128 values are not supported."),
806
+ ERROR_CASE(MC_DEC128_NEGATIVE_INFINITY,
807
+ OPT_NULLOPT,
808
+ OPT_NULLOPT,
809
+ OPT_NULLOPT,
810
+ "Infinity and Nan Decimal128 values are not supported."),
811
+
812
+ ERROR_CASE(MC_DEC128_POSITIVE_NAN,
813
+ OPT_NULLOPT,
814
+ OPT_NULLOPT,
815
+ OPT_NULLOPT,
816
+ "Infinity and Nan Decimal128 values are not supported."),
817
+
818
+ ERROR_CASE(MC_DEC128_NEGATIVE_NAN,
819
+ OPT_NULLOPT,
820
+ OPT_NULLOPT,
821
+ OPT_NULLOPT,
822
+ "Infinity and Nan Decimal128 values are not supported."),
699
823
 
700
824
  /* Test cases copied from Decimal128_Bounds_Precision ... begin */
701
- #define ASSERT_EIBP(Value, Precision, Expect) \
702
- (Decimal128Test){ \
703
- .value = mc_dec128_from_string (Value), \
704
- .min = OPT_MC_DEC128 (MC_DEC128_C (-100000)), \
705
- .max = OPT_MC_DEC128 (MC_DEC128_C (100000)), \
706
- .precision = OPT_U32 (Precision), \
707
- .expect = MLIB_INT128 (Expect), \
708
- }
709
- ASSERT_EIBP ("3.141592653589E-1", 10, 1000003141592653),
710
- ASSERT_EIBP ("31.41592653589E-2", 10, 1000003141592653),
711
- ASSERT_EIBP ("314.1592653589E-3", 10, 1000003141592653),
712
- ASSERT_EIBP ("3141.592653589E-4", 10, 1000003141592653),
713
- ASSERT_EIBP ("31415.92653589E-5", 10, 1000003141592653),
714
- ASSERT_EIBP ("314159.2653589E-6", 10, 1000003141592653),
715
- ASSERT_EIBP ("3141592.653589E-7", 10, 1000003141592653),
716
- ASSERT_EIBP ("31415926.53589E-8", 10, 1000003141592653),
825
+ #define ASSERT_EIBP(Value, Precision, Expect) \
826
+ (Decimal128Test){ \
827
+ .value = mc_dec128_from_string(Value), \
828
+ .min = OPT_MC_DEC128(MC_DEC128_C(-100000)), \
829
+ .max = OPT_MC_DEC128(MC_DEC128_C(100000)), \
830
+ .precision = OPT_I32(Precision), \
831
+ .expect = MLIB_INT128(Expect), \
832
+ }
833
+ ASSERT_EIBP("3.141592653589E-1", 10, 1000003141592653),
834
+ ASSERT_EIBP("31.41592653589E-2", 10, 1000003141592653),
835
+ ASSERT_EIBP("314.1592653589E-3", 10, 1000003141592653),
836
+ ASSERT_EIBP("3141.592653589E-4", 10, 1000003141592653),
837
+ ASSERT_EIBP("31415.92653589E-5", 10, 1000003141592653),
838
+ ASSERT_EIBP("314159.2653589E-6", 10, 1000003141592653),
839
+ ASSERT_EIBP("3141592.653589E-7", 10, 1000003141592653),
840
+ ASSERT_EIBP("31415926.53589E-8", 10, 1000003141592653),
717
841
  #undef ASSERT_EIBP
718
842
 
719
- #define ASSERT_EIBPL(Value, Precision, Expect) \
720
- (Decimal128Test){ \
721
- .value = mc_dec128_from_string (Value), \
722
- .min = OPT_MC_DEC128 (MC_DEC128_C (-100000)), \
723
- .max = OPT_MC_DEC128 (mc_dec128_from_string ("1E22")), \
724
- .precision = OPT_U32 (Precision), \
725
- .expect = mlib_int128_from_string (Expect, NULL), \
726
- }
727
-
728
- ASSERT_EIBPL ("3.1415926535897932384626433832795E20",
729
- 5,
730
- "31415926535897942384626433"),
731
- ASSERT_EIBPL ("3.1415926535897932384626433832795E20",
732
- 6,
733
- "314159265358979423846264338"),
734
-
735
- ASSERT_EIBPL ("3.1415926535897932384626433832795E20",
736
- 7,
737
- "3141592653589794238462643383"),
738
-
739
- ASSERT_EIBPL ("3.1415926535897932384626433832795E20",
740
- 8,
741
- "31415926535897942384626433832"),
843
+ #define ASSERT_EIBPL(Value, Precision, Expect) \
844
+ (Decimal128Test){ \
845
+ .value = mc_dec128_from_string(Value), \
846
+ .min = OPT_MC_DEC128(MC_DEC128_C(-100000)), \
847
+ .max = OPT_MC_DEC128(mc_dec128_from_string("1E22")), \
848
+ .precision = OPT_I32(Precision), \
849
+ .expect = mlib_int128_from_string(Expect, NULL), \
850
+ }
851
+
852
+ ASSERT_EIBPL("3.1415926535897932384626433832795E20", 5, "31415926535897942384626433"),
853
+ ASSERT_EIBPL("3.1415926535897932384626433832795E20", 6, "314159265358979423846264338"),
854
+
855
+ ASSERT_EIBPL("3.1415926535897932384626433832795E20", 7, "3141592653589794238462643383"),
856
+
857
+ ASSERT_EIBPL("3.1415926535897932384626433832795E20", 8, "31415926535897942384626433832"),
742
858
  #undef ASSERT_EIBPL
743
859
 
744
- #define ASSERT_EIBP(Value, Precision, Expect) \
745
- (Decimal128Test){ \
746
- .value = mc_dec128_from_string (#Value), \
747
- .min = OPT_MC_DEC128 (MC_DEC128_C (-100000)), \
748
- .max = OPT_MC_DEC128 (MC_DEC128_C (100000)), \
749
- .precision = OPT_U32 (Precision), \
750
- .expect = MLIB_INT128_CAST (Expect), \
751
- }
752
- ASSERT_EIBP (3.141592653589, 1, 1000031),
753
- ASSERT_EIBP (3.141592653589, 2, 10000314),
754
- ASSERT_EIBP (3.141592653589, 3, 100003141),
755
- ASSERT_EIBP (3.141592653589, 4, 1000031415),
756
- ASSERT_EIBP (3.141592653589, 5, 10000314159),
757
- ASSERT_EIBP (3.141592653589, 6, 100003141592),
758
- ASSERT_EIBP (3.141592653589, 7, 1000031415926),
860
+ #define ASSERT_EIBP(Value, Precision, Expect) \
861
+ (Decimal128Test){ \
862
+ .value = mc_dec128_from_string(#Value), \
863
+ .min = OPT_MC_DEC128(MC_DEC128_C(-100000)), \
864
+ .max = OPT_MC_DEC128(MC_DEC128_C(100000)), \
865
+ .precision = OPT_I32(Precision), \
866
+ .expect = MLIB_INT128_CAST(Expect), \
867
+ }
868
+ ASSERT_EIBP(3.141592653589, 1, 1000031),
869
+ ASSERT_EIBP(3.141592653589, 2, 10000314),
870
+ ASSERT_EIBP(3.141592653589, 3, 100003141),
871
+ ASSERT_EIBP(3.141592653589, 4, 1000031415),
872
+ ASSERT_EIBP(3.141592653589, 5, 10000314159),
873
+ ASSERT_EIBP(3.141592653589, 6, 100003141592),
874
+ ASSERT_EIBP(3.141592653589, 7, 1000031415926),
759
875
  #undef ASSERT_EIBP
760
876
 
761
- #define ASSERT_EIBB(Val, Max, Min, Precision, Expect) \
762
- (Decimal128Test){ \
763
- .value = mc_dec128_from_string (#Val), \
764
- .min = OPT_MC_DEC128 (mc_dec128_from_string (#Min)), \
765
- .max = OPT_MC_DEC128 (mc_dec128_from_string (#Max)), \
766
- .precision = OPT_U32 (Precision), \
767
- .expect = MLIB_INT128_CAST (Expect), \
768
- }
769
-
770
- #define ASSERT_EIBB_OVERFLOW(Val, Max, Min, Precision, Expect) \
771
- (Decimal128Test) \
772
- { \
773
- .value = mc_dec128_from_string (#Val), \
774
- .min = OPT_MC_DEC128 (mc_dec128_from_string (#Min)), \
775
- .max = OPT_MC_DEC128 (mc_dec128_from_string (#Max)), \
776
- .precision = OPT_U32 (Precision), .expect = Expect, \
777
- }
778
-
779
- ASSERT_EIBB (0, 1, -1, 3, 1000),
780
- ASSERT_EIBB (0, 1, -1E5, 3, 100000000),
781
-
782
- ASSERT_EIBB (-1E-33, 1, -1E5, 3, 100000000),
783
-
784
- ASSERT_EIBB_OVERFLOW (
785
- 0,
786
- MC_DEC128_LARGEST_POSITIVE,
787
- MC_DEC128_LARGEST_NEGATIVE,
788
- 3,
789
- mlib_int128_from_string ("170141183460469231731687303715884105728",
790
- NULL)),
791
- ASSERT_EIBB_OVERFLOW (
792
- 0,
793
- DBL_MAX,
794
- DBL_MIN,
795
- 3,
796
- mlib_int128_from_string ("170141183460469231731687303715884105728",
797
- NULL)),
798
-
799
- ASSERT_EIBB (3.141592653589, 5, 0, 0, 3),
800
- ASSERT_EIBB (3.141592653589, 5, 0, 1, 31),
801
-
802
- ASSERT_EIBB (3.141592653589, 5, 0, 2, 314),
803
-
804
- ASSERT_EIBB (3.141592653589, 5, 0, 3, 3141),
805
- ASSERT_EIBB (3.141592653589, 5, 0, 16, 31415926535890000),
806
-
807
- ASSERT_EIBB (-5, -1, -10, 3, 5000),
808
-
809
- ASSERT_EIBB_OVERFLOW (
810
- 1E100,
811
- DBL_MAX,
812
- DBL_MIN,
813
- 3,
814
- mlib_int128_from_string ("232572183460469231731687303715884099485",
815
- NULL)),
816
-
817
- ASSERT_EIBB (1E9, 1E10, 0, 3, 1000000000000),
818
- ASSERT_EIBB (1E9, 1E10, 0, 0, 1000000000),
819
-
820
-
821
- ASSERT_EIBB (-5, 10, -10, 0, 5),
822
- ASSERT_EIBB (-5, 10, -10, 2, 500),
823
-
824
- ASSERT_EIBB (5E-30, 10E-30, 1E-30, 35, 400000),
825
-
826
- // Test a range that requires > 64 bits.
827
- ASSERT_EIBB (5, 18446744073709551616, .1, 1, 49),
828
- // Test a range that requires > 64 bits.
829
- // min has more places after the decimal than precision.
830
- ASSERT_EIBB (5, 18446744073709551616, .01, 1, 49),
877
+ #define ASSERT_EIBB(Val, Max, Min, Precision, Expect) \
878
+ (Decimal128Test){ \
879
+ .value = mc_dec128_from_string(#Val), \
880
+ .min = OPT_MC_DEC128(mc_dec128_from_string(#Min)), \
881
+ .max = OPT_MC_DEC128(mc_dec128_from_string(#Max)), \
882
+ .precision = OPT_I32(Precision), \
883
+ .expect = MLIB_INT128_CAST(Expect), \
884
+ }
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.
889
+ #define ASSERT_EIBB_OVERFLOW(Val, Max, Min, Precision, Expect) \
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) { \
899
+ .value = mc_dec128_from_string(#Val), .min = OPT_MC_DEC128(mc_dec128_from_string(#Min)), \
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 \
917
+ }
918
+
919
+ ASSERT_EIBB(0, 1, -1, 3, 1000),
920
+ ASSERT_EIBB(0, 1, -1E5, 3, 100000000),
921
+
922
+ ASSERT_EIBB(-1E-33, 1, -1E5, 3, 100000000),
923
+
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."),
937
+
938
+ ASSERT_EIBB(3.141592653589, 5, 0, 0, 3),
939
+ ASSERT_EIBB(3.141592653589, 5, 0, 1, 31),
940
+
941
+ ASSERT_EIBB(3.141592653589, 5, 0, 2, 314),
942
+
943
+ ASSERT_EIBB(3.141592653589, 5, 0, 3, 3141),
944
+ ASSERT_EIBB(3.141592653589, 5, 0, 16, 31415926535890000),
945
+
946
+ ASSERT_EIBB(-5, -1, -10, 3, 5000),
947
+
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."),
954
+
955
+ ASSERT_EIBB(1E9, 1E10, 0, 3, 1000000000000),
956
+ ASSERT_EIBB(1E9, 1E10, 0, 0, 1000000000),
957
+
958
+ ASSERT_EIBB(-5, 10, -10, 0, 5),
959
+ ASSERT_EIBB(-5, 10, -10, 2, 500),
960
+
961
+ ASSERT_EIBB(5E-30, 10E-30, 1E-30, 35, 400000),
962
+
963
+ // Test a range that requires > 64 bits.
964
+ ASSERT_EIBB(5, 18446744073709551616, .1, 1, 49),
831
965
 
832
966
  #undef ASSERT_EIBB
833
967
  #undef ASSERT_EIBB_OVERFLOW
968
+ #undef ASSERT_EIBB_ERROR
969
+
970
+ /* Test cases copied from Decimal128_Bounds_Precision ... end */
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"}};
983
+
984
+ for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
985
+ Decimal128Test *test = tests + i;
986
+ mongocrypt_status_t *const status = mongocrypt_status_new();
987
+
988
+ if (test->min.set && test->max.set && test->precision.set) {
989
+ printf("_test_RangeTest_Encode_Decimal128: value=%s, min=%s, max=%s, "
990
+ "precision=%" PRIu32 "\n",
991
+ mc_dec128_to_string(test->value).str,
992
+ mc_dec128_to_string(test->min.value).str,
993
+ mc_dec128_to_string(test->max.value).str,
994
+ test->precision.value);
995
+ } else {
996
+ printf("_test_RangeTest_Encode_Decimal128: value=%s\n", mc_dec128_to_string(test->value).str);
997
+ }
998
+ fflush(stdout);
999
+ mc_OSTType_Decimal128 got;
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);
1011
+ if (test->expectError) {
1012
+ ASSERT_OR_PRINT_MSG(!ok, "expected error, but got none");
1013
+ ASSERT_STATUS_CONTAINS(status, test->expectError);
1014
+ } else {
1015
+ ASSERT_OK_STATUS(ok, status);
834
1016
 
835
- /* Test cases copied from Decimal128_Bounds_Precision ... end */
836
- };
837
-
838
- for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) {
839
- Decimal128Test *test = tests + i;
840
- mongocrypt_status_t *const status = mongocrypt_status_new ();
841
-
842
- if (test->min.set && test->max.set && test->precision.set) {
843
- printf ("_test_RangeTest_Encode_Decimal128: value=%s, min=%s, max=%s, "
844
- "precision=%" PRIu32 "\n",
845
- mc_dec128_to_string (test->value).str,
846
- mc_dec128_to_string (test->min.value).str,
847
- mc_dec128_to_string (test->max.value).str,
848
- test->precision.value);
849
- } else {
850
- printf ("_test_RangeTest_Encode_Decimal128: value=%s\n",
851
- mc_dec128_to_string (test->value).str);
852
- }
853
- fflush (stdout);
854
- mc_OSTType_Decimal128 got;
855
- const bool ok = mc_getTypeInfoDecimal128 (
856
- (mc_getTypeInfoDecimal128_args_t){.value = test->value,
857
- .min = test->min,
858
- .max = test->max,
859
- .precision = test->precision},
860
- &got,
861
- status);
862
- if (test->expectError) {
863
- ASSERT_OR_PRINT_MSG (!ok, "expected error, but got none");
864
- ASSERT_STATUS_CONTAINS (status, test->expectError);
865
- } else {
866
- ASSERT_OK_STATUS (ok, status);
867
-
868
- ASSERT_CMPINT128_EQ (got.value, test->expect);
869
- ASSERT_CMPINT128_EQ (got.min, MLIB_INT128 (0));
870
- }
871
- mongocrypt_status_destroy (status);
872
- }
1017
+ ASSERT_CMPINT128_EQ(got.value, test->expect);
1018
+ ASSERT_CMPINT128_EQ(got.min, MLIB_INT128(0));
1019
+ }
1020
+ mongocrypt_status_destroy(status);
1021
+ }
873
1022
  }
874
1023
 
875
1024
  #endif // MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
876
1025
 
877
- void
878
- _mongocrypt_tester_install_range_encoding (_mongocrypt_tester_t *tester)
879
- {
880
- INSTALL_TEST (_test_RangeTest_Encode_Int32);
881
- INSTALL_TEST (_test_RangeTest_Encode_Int64);
882
- INSTALL_TEST (_test_RangeTest_Encode_Double);
1026
+ void _mongocrypt_tester_install_range_encoding(_mongocrypt_tester_t *tester) {
1027
+ INSTALL_TEST(_test_RangeTest_Encode_Int32);
1028
+ INSTALL_TEST(_test_RangeTest_Encode_Int64);
1029
+ INSTALL_TEST(_test_canUsePrecisionModeDouble);
1030
+ INSTALL_TEST(_test_RangeTest_Encode_Double);
883
1031
  #if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
884
- INSTALL_TEST (_test_RangeTest_Encode_Decimal128);
1032
+ INSTALL_TEST(_test_canUsePrecisionModeDecimal);
1033
+ INSTALL_TEST(_test_RangeTest_Encode_Decimal128);
885
1034
  #endif
886
1035
  }