libmongocrypt-helper 1.7.4.0.1001 → 1.8.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (398) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/libmongocrypt/extconf.rb +2 -2
  4. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
  5. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
  6. data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
  7. data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
  8. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
  14. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
  15. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
  16. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
  17. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
  19. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
  20. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
  21. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
  22. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
  23. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
  24. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
  25. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
  26. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
  27. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
  28. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
  31. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
  32. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
  33. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
  34. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
  35. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
  36. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
  37. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
  38. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
  39. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
  41. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
  42. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
  44. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
  45. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
  46. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
  61. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
  62. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
  63. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
  64. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  65. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  66. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
  67. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  68. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  69. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  70. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  71. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  72. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  73. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  74. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  75. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  76. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  77. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  78. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
  79. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  80. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  81. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  82. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  83. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  84. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  85. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  86. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
  87. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
  88. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  89. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
  90. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
  91. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  92. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  93. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  94. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  95. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
  96. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
  97. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
  98. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  99. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
  100. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
  101. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
  102. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  103. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  104. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  105. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  106. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
  107. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  108. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  109. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  110. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  111. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  112. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  113. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  114. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
  115. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
  116. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
  117. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
  118. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
  119. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
  120. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
  121. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
  122. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
  123. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
  124. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
  125. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
  126. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  127. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  128. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
  129. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
  130. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  131. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  132. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  133. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  134. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  135. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
  136. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
  137. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  138. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  139. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  140. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  141. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  142. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  143. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  144. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
  145. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  146. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  147. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
  148. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  149. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  150. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  151. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
  152. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
  153. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
  154. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  155. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  156. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  157. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  158. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  159. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  160. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
  161. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
  162. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  163. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
  164. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
  165. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  166. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
  194. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
  195. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
  196. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  197. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
  198. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  199. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  200. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  202. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
  203. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  231. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  243. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  244. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  245. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  246. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  247. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  248. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  249. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  250. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  251. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  252. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  253. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  261. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  262. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  263. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  271. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  272. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  276. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  277. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  281. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  282. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  283. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  284. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  285. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  286. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  288. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  289. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  303. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
  314. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  315. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
  316. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  317. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  318. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  319. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
  320. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  323. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  324. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
  325. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  326. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  327. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  328. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  329. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
  330. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
  331. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
  332. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
  333. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  334. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
  335. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  336. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
  337. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
  338. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  339. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  340. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
  341. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  342. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  343. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
  344. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
  345. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
  346. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
  347. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  348. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  349. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
  350. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
  351. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  352. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
  353. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
  354. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  355. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  356. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  357. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  358. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  359. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  360. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
  361. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  362. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  363. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  364. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
  365. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  366. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
  367. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
  368. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
  369. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
  370. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
  371. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
  372. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
  373. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  374. data/lib/libmongocrypt_helper/version.rb +2 -2
  375. data/lib/libmongocrypt_helper.rb +2 -2
  376. data.tar.gz.sig +0 -0
  377. metadata +154 -26
  378. metadata.gz.sig +0 -0
  379. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  380. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  381. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  382. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  383. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  384. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  392. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  393. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  394. /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
  395. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  396. /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
  397. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  398. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -31,287 +31,263 @@
31
31
  * Encode a signed 32-bit integer as an unsigned 32-bit integer by adding 2^31.
32
32
  * Some documentation references this as making the value "unbiased".
33
33
  */
34
- static uint32_t
35
- encodeInt32 (int32_t v)
36
- {
37
- // Shift the int32_t range [-2^31, 2^31 - 1] to the uint32_t range [0, 2^32].
38
- // new_zero is the mapped 0 value.
39
- uint32_t new_zero = (UINT32_C (1) << 31);
40
-
41
- if (v < 0) {
42
- // Signed integers have a value that there is no positive equivalent and
43
- // must be handled specially
44
- if (v == INT32_MIN) {
45
- return 0;
46
- }
47
-
48
- int32_t v_pos = v * -1;
49
- uint32_t v_u32 = (uint32_t) v_pos;
50
- return new_zero - v_u32;
51
- }
52
-
53
- uint32_t v_u32 = (uint32_t) v;
54
- return new_zero + v_u32;
34
+ static uint32_t encodeInt32(int32_t v) {
35
+ // Shift the int32_t range [-2^31, 2^31 - 1] to the uint32_t range [0, 2^32].
36
+ // new_zero is the mapped 0 value.
37
+ uint32_t new_zero = (UINT32_C(1) << 31);
38
+
39
+ if (v < 0) {
40
+ // Signed integers have a value that there is no positive equivalent and
41
+ // must be handled specially
42
+ if (v == INT32_MIN) {
43
+ return 0;
44
+ }
45
+
46
+ int32_t v_pos = v * -1;
47
+ uint32_t v_u32 = (uint32_t)v_pos;
48
+ return new_zero - v_u32;
49
+ }
50
+
51
+ uint32_t v_u32 = (uint32_t)v;
52
+ return new_zero + v_u32;
55
53
  }
56
54
 
57
- bool
58
- mc_getTypeInfo32 (mc_getTypeInfo32_args_t args,
59
- mc_OSTType_Int32 *out,
60
- mongocrypt_status_t *status)
61
- {
62
- if (args.min.set != args.max.set) {
63
- CLIENT_ERR ("Must specify both a lower and upper bound or no bounds.");
64
- return false;
65
- }
66
-
67
- if (!args.min.set) {
68
- uint32_t v_u32 = encodeInt32 (args.value);
69
- *out = (mc_OSTType_Int32){v_u32, 0, UINT32_MAX};
70
- return true;
71
- }
72
-
73
- if (args.min.value >= args.max.value) {
74
- CLIENT_ERR ("The minimum value must be less than the maximum value, got "
75
- "min: %" PRId32 ", max: %" PRId32,
76
- args.min.value,
77
- args.max.value);
78
- return false;
79
- }
80
-
81
- if (args.value > args.max.value || args.value < args.min.value) {
82
- CLIENT_ERR (
83
- "Value must be greater than or equal to the minimum value "
84
- "and less than or equal to the maximum value, got min: %" PRId32
85
- ", max: %" PRId32 ", value: %" PRId32,
86
- args.min.value,
87
- args.max.value,
88
- args.value);
89
- return false;
90
- }
91
-
92
- // Convert to unbiased uint32. Then subtract the min value.
93
- uint32_t v_u32 = encodeInt32 (args.value);
94
- uint32_t min_u32 = encodeInt32 (args.min.value);
95
- uint32_t max_u32 = encodeInt32 (args.max.value);
96
-
97
- v_u32 -= min_u32;
98
- max_u32 -= min_u32;
99
-
100
- *out = (mc_OSTType_Int32){v_u32, 0, max_u32};
101
- return true;
55
+ bool mc_getTypeInfo32(mc_getTypeInfo32_args_t args, mc_OSTType_Int32 *out, mongocrypt_status_t *status) {
56
+ if (args.min.set != args.max.set) {
57
+ CLIENT_ERR("Must specify both a lower and upper bound or no bounds.");
58
+ return false;
59
+ }
60
+
61
+ if (!args.min.set) {
62
+ uint32_t v_u32 = encodeInt32(args.value);
63
+ *out = (mc_OSTType_Int32){v_u32, 0, UINT32_MAX};
64
+ return true;
65
+ }
66
+
67
+ if (args.min.value >= args.max.value) {
68
+ CLIENT_ERR("The minimum value must be less than the maximum value, got "
69
+ "min: %" PRId32 ", max: %" PRId32,
70
+ args.min.value,
71
+ args.max.value);
72
+ return false;
73
+ }
74
+
75
+ if (args.value > args.max.value || args.value < args.min.value) {
76
+ CLIENT_ERR("Value must be greater than or equal to the minimum value "
77
+ "and less than or equal to the maximum value, got min: %" PRId32 ", max: %" PRId32
78
+ ", value: %" PRId32,
79
+ args.min.value,
80
+ args.max.value,
81
+ args.value);
82
+ return false;
83
+ }
84
+
85
+ // Convert to unbiased uint32. Then subtract the min value.
86
+ uint32_t v_u32 = encodeInt32(args.value);
87
+ uint32_t min_u32 = encodeInt32(args.min.value);
88
+ uint32_t max_u32 = encodeInt32(args.max.value);
89
+
90
+ v_u32 -= min_u32;
91
+ max_u32 -= min_u32;
92
+
93
+ *out = (mc_OSTType_Int32){v_u32, 0, max_u32};
94
+ return true;
102
95
  }
103
96
 
104
97
  /**
105
98
  * Encode a signed 64-bit integer as an unsigned 64-bit integer by adding 2^63.
106
99
  * Some documentation references this as making the value "unbiased".
107
100
  */
108
- static uint64_t
109
- encodeInt64 (int64_t v)
110
- {
111
- // Shift the int64_t range [-2^63, 2^63 - 1] to the uint64_t range [0, 2^64].
112
- // new_zero is the mapped 0 value.
113
- uint64_t new_zero = (UINT64_C (1) << 63);
114
-
115
- if (v < 0) {
116
- // Signed integers have a value that there is no positive equivalent and
117
- // must be handled specially
118
- if (v == INT64_MIN) {
119
- return 0;
120
- }
121
-
122
- int64_t v_pos = v * -1;
123
- uint64_t v_u64 = (uint64_t) v_pos;
124
- return new_zero - v_u64;
125
- }
126
-
127
- uint64_t v_u64 = (uint64_t) v;
128
- return new_zero + v_u64;
101
+ static uint64_t encodeInt64(int64_t v) {
102
+ // Shift the int64_t range [-2^63, 2^63 - 1] to the uint64_t range [0, 2^64].
103
+ // new_zero is the mapped 0 value.
104
+ uint64_t new_zero = (UINT64_C(1) << 63);
105
+
106
+ if (v < 0) {
107
+ // Signed integers have a value that there is no positive equivalent and
108
+ // must be handled specially
109
+ if (v == INT64_MIN) {
110
+ return 0;
111
+ }
112
+
113
+ int64_t v_pos = v * -1;
114
+ uint64_t v_u64 = (uint64_t)v_pos;
115
+ return new_zero - v_u64;
116
+ }
117
+
118
+ uint64_t v_u64 = (uint64_t)v;
119
+ return new_zero + v_u64;
129
120
  }
130
121
 
131
- bool
132
- mc_getTypeInfo64 (mc_getTypeInfo64_args_t args,
133
- mc_OSTType_Int64 *out,
134
- mongocrypt_status_t *status)
135
- {
136
- if (args.min.set != args.max.set) {
137
- CLIENT_ERR ("Must specify both a lower and upper bound or no bounds.");
138
- return false;
139
- }
140
-
141
- if (!args.min.set) {
142
- uint64_t v_u64 = encodeInt64 (args.value);
143
- *out = (mc_OSTType_Int64){v_u64, 0, UINT64_MAX};
144
- return true;
145
- }
146
-
147
- if (args.min.value >= args.max.value) {
148
- CLIENT_ERR ("The minimum value must be less than the maximum value, got "
149
- "min: %" PRId64 ", max: %" PRId64,
150
- args.min.value,
151
- args.max.value);
152
- return false;
153
- }
154
-
155
- if (args.value > args.max.value || args.value < args.min.value) {
156
- CLIENT_ERR ("Value must be greater than or equal to the minimum value "
157
- "and less than or equal to the maximum value, got "
158
- "min: %" PRId64 ", max: %" PRId64 ", value: %" PRId64,
159
- args.min.value,
160
- args.max.value,
161
- args.value);
162
- return false;
163
- }
164
-
165
- // Convert to unbiased uint64. Then subtract the min value.
166
- uint64_t v_u64 = encodeInt64 (args.value);
167
- uint64_t min_u64 = encodeInt64 (args.min.value);
168
- uint64_t max_u64 = encodeInt64 (args.max.value);
169
-
170
- v_u64 -= min_u64;
171
- max_u64 -= min_u64;
172
-
173
- *out = (mc_OSTType_Int64){v_u64, 0, max_u64};
174
- return true;
122
+ bool mc_getTypeInfo64(mc_getTypeInfo64_args_t args, mc_OSTType_Int64 *out, mongocrypt_status_t *status) {
123
+ if (args.min.set != args.max.set) {
124
+ CLIENT_ERR("Must specify both a lower and upper bound or no bounds.");
125
+ return false;
126
+ }
127
+
128
+ if (!args.min.set) {
129
+ uint64_t v_u64 = encodeInt64(args.value);
130
+ *out = (mc_OSTType_Int64){v_u64, 0, UINT64_MAX};
131
+ return true;
132
+ }
133
+
134
+ if (args.min.value >= args.max.value) {
135
+ CLIENT_ERR("The minimum value must be less than the maximum value, got "
136
+ "min: %" PRId64 ", max: %" PRId64,
137
+ args.min.value,
138
+ args.max.value);
139
+ return false;
140
+ }
141
+
142
+ if (args.value > args.max.value || args.value < args.min.value) {
143
+ CLIENT_ERR("Value must be greater than or equal to the minimum value "
144
+ "and less than or equal to the maximum value, got "
145
+ "min: %" PRId64 ", max: %" PRId64 ", value: %" PRId64,
146
+ args.min.value,
147
+ args.max.value,
148
+ args.value);
149
+ return false;
150
+ }
151
+
152
+ // Convert to unbiased uint64. Then subtract the min value.
153
+ uint64_t v_u64 = encodeInt64(args.value);
154
+ uint64_t min_u64 = encodeInt64(args.min.value);
155
+ uint64_t max_u64 = encodeInt64(args.max.value);
156
+
157
+ v_u64 -= min_u64;
158
+ max_u64 -= min_u64;
159
+
160
+ *out = (mc_OSTType_Int64){v_u64, 0, max_u64};
161
+ return true;
175
162
  }
176
163
 
177
- #define exp10Double(x) pow (10, x)
178
-
179
- bool
180
- mc_getTypeInfoDouble (mc_getTypeInfoDouble_args_t args,
181
- mc_OSTType_Double *out,
182
- mongocrypt_status_t *status)
183
- {
184
- if (args.min.set != args.max.set || args.min.set != args.precision.set) {
185
- CLIENT_ERR (
186
- "min, max, and precision must all be set or must all be unset");
187
- return false;
188
- }
189
-
190
- if (mc_isinf (args.value) || mc_isnan (args.value)) {
191
- CLIENT_ERR ("Infinity and NaN double values are not supported.");
192
- return false;
193
- }
194
-
195
- if (args.min.set) {
196
- if (args.min.value >= args.max.value) {
197
- CLIENT_ERR (
198
- "The minimum value must be less than the maximum value, got "
199
- "min: %g, max: %g",
200
- args.min.value,
201
- args.max.value);
202
- return false;
203
- }
204
-
205
- if (args.value > args.max.value || args.value < args.min.value) {
206
- CLIENT_ERR ("Value must be greater than or equal to the minimum value "
207
- "and less than or equal to the maximum value, got "
208
- "min: %g, max: %g, value: %g",
209
- args.min.value,
210
- args.max.value,
211
- args.value);
212
- return false;
213
- }
214
- }
215
-
216
- const bool is_neg = args.value < 0.0;
217
-
218
- // Map negative 0 to zero so sign bit is 0.
219
- if (args.value == 0.0) {
220
- args.value = 0.0;
221
- }
222
-
223
- // When we use precision mode, we try to represent as a double value that
224
- // fits in [-2^63, 2^63] (i.e. is a valid int64)
225
- //
226
- // This check determines if we can represent the precision truncated value as
227
- // a 64-bit integer I.e. Is ((ub - lb) * 10^precision) < 64 bits.
228
- //
229
- bool use_precision_mode = false;
230
- uint32_t bits_range;
231
- if (args.precision.set) {
232
- // Subnormal representations can support up to 5x10^-324 as a number
233
- if (args.precision.value > 324) {
234
- CLIENT_ERR (
235
- "Precision must be between 0 and 324 inclusive, got: %" PRIu32,
236
- args.precision.value);
237
- return false;
238
- }
239
-
240
- double range = args.max.value - args.min.value;
241
-
242
- // We can overflow if max = max double and min = min double so make sure
243
- // we have finite number after we do subtraction
244
- // Ignore conversion warnings to fix error with glibc.
245
- if (mc_isfinite (range)) {
246
- // This creates a range which is wider then we permit by our min/max
247
- // bounds check with the +1 but it is as the algorithm is written in
248
- // WRITING-11907.
249
- double rangeAndPrecision =
250
- (range + 1) * exp10Double (args.precision.value);
251
-
252
- if (mc_isfinite (rangeAndPrecision)) {
253
- double bits_range_double = log2 (rangeAndPrecision);
254
- bits_range = (uint32_t) ceil (bits_range_double);
255
-
256
- if (bits_range < 64) {
257
- use_precision_mode = true;
164
+ #define exp10Double(x) pow(10, x)
165
+
166
+ bool mc_getTypeInfoDouble(mc_getTypeInfoDouble_args_t args, mc_OSTType_Double *out, mongocrypt_status_t *status) {
167
+ if (args.min.set != args.max.set || args.min.set != args.precision.set) {
168
+ CLIENT_ERR("min, max, and precision must all be set or must all be unset");
169
+ return false;
170
+ }
171
+
172
+ if (mc_isinf(args.value) || mc_isnan(args.value)) {
173
+ CLIENT_ERR("Infinity and NaN double values are not supported.");
174
+ return false;
175
+ }
176
+
177
+ if (args.min.set) {
178
+ if (args.min.value >= args.max.value) {
179
+ CLIENT_ERR("The minimum value must be less than the maximum value, got "
180
+ "min: %g, max: %g",
181
+ args.min.value,
182
+ args.max.value);
183
+ return false;
184
+ }
185
+
186
+ if (args.value > args.max.value || args.value < args.min.value) {
187
+ CLIENT_ERR("Value must be greater than or equal to the minimum value "
188
+ "and less than or equal to the maximum value, got "
189
+ "min: %g, max: %g, value: %g",
190
+ args.min.value,
191
+ args.max.value,
192
+ args.value);
193
+ return false;
194
+ }
195
+ }
196
+
197
+ const bool is_neg = args.value < 0.0;
198
+
199
+ // Map negative 0 to zero so sign bit is 0.
200
+ if (args.value == 0.0) {
201
+ args.value = 0.0;
202
+ }
203
+
204
+ // When we use precision mode, we try to represent as a double value that
205
+ // fits in [-2^63, 2^63] (i.e. is a valid int64)
206
+ //
207
+ // This check determines if we can represent the precision truncated value as
208
+ // a 64-bit integer I.e. Is ((ub - lb) * 10^precision) < 64 bits.
209
+ //
210
+ bool use_precision_mode = false;
211
+ uint32_t bits_range;
212
+ if (args.precision.set) {
213
+ // Subnormal representations can support up to 5x10^-324 as a number
214
+ if (args.precision.value > 324) {
215
+ CLIENT_ERR("Precision must be between 0 and 324 inclusive, got: %" PRIu32, args.precision.value);
216
+ return false;
217
+ }
218
+
219
+ double range = args.max.value - args.min.value;
220
+
221
+ // We can overflow if max = max double and min = min double so make sure
222
+ // we have finite number after we do subtraction
223
+ // Ignore conversion warnings to fix error with glibc.
224
+ if (mc_isfinite(range)) {
225
+ // This creates a range which is wider then we permit by our min/max
226
+ // bounds check with the +1 but it is as the algorithm is written in
227
+ // WRITING-11907.
228
+ double rangeAndPrecision = (range + 1) * exp10Double(args.precision.value);
229
+
230
+ if (mc_isfinite(rangeAndPrecision)) {
231
+ double bits_range_double = log2(rangeAndPrecision);
232
+ bits_range = (uint32_t)ceil(bits_range_double);
233
+
234
+ if (bits_range < 64) {
235
+ use_precision_mode = true;
236
+ }
258
237
  }
259
- }
260
- }
261
- }
262
-
263
- if (use_precision_mode) {
264
- // Take a number of xxxx.ppppp and truncate it xxxx.ppp if precision = 3.
265
- // We do not change the digits before the decimal place.
266
- double v_prime = trunc (args.value * exp10Double (args.precision.value)) /
267
- exp10Double (args.precision.value);
268
- int64_t v_prime2 = (int64_t) ((v_prime - args.min.value) *
269
- exp10Double (args.precision.value));
270
-
271
- BSON_ASSERT (v_prime2 < INT64_MAX && v_prime2 >= 0);
272
-
273
- uint64_t ret = (uint64_t) v_prime2;
274
-
275
- // Adjust maximum value to be the max bit range. This will be used by
276
- // getEdges/minCover to trim bits.
277
- uint64_t max_value = (UINT64_C (1) << bits_range) - 1;
278
- BSON_ASSERT (ret <= max_value);
279
-
280
- *out = (mc_OSTType_Double){ret, 0, max_value};
281
- return true;
282
- }
283
-
284
- // Translate double to uint64 by modifying the bit representation and copying
285
- // into a uint64. Double is assumed to be a IEEE 754 Binary 64.
286
- // It is bit-encoded as sign, exponent, and fraction:
287
- // s eeeeeeee ffffffffffffffffffffffffffffffffffffffffffffffffffff
288
-
289
- // When we translate the double into "bits", the sign bit means that the
290
- // negative numbers get mapped into the higher 63 bits of a 64-bit integer.
291
- // We want them to map into the lower 64-bits so we invert the sign bit.
292
- args.value *= -1.0;
293
-
294
- // On Endianness, we support two sets of architectures
295
- // 1. Little Endian (ppc64le, x64, aarch64) - in these architectures, int64
296
- // and double are both 64-bits and both arranged in little endian byte order.
297
- // 2. Big Endian (s390x) - in these architectures, int64 and double are both
298
- // 64-bits and both arranged in big endian byte order.
299
- //
300
- // Therefore, since the order of bytes on each platform is consistent with
301
- // itself, the conversion below converts a double into correct 64-bit integer
302
- // that produces the same behavior across plaforms.
303
- uint64_t uv;
304
- memcpy (&uv, &args.value, sizeof (uint64_t));
305
-
306
- if (is_neg) {
307
- uint64_t new_zero = UINT64_C (1) << 63;
308
- BSON_ASSERT (uv <= new_zero);
309
- uv = new_zero - uv;
310
- }
311
-
312
- *out = (mc_OSTType_Double){.min = 0, .max = UINT64_MAX, .value = uv};
313
-
314
- return true;
238
+ }
239
+ }
240
+
241
+ if (use_precision_mode) {
242
+ // Take a number of xxxx.ppppp and truncate it xxxx.ppp if precision = 3.
243
+ // We do not change the digits before the decimal place.
244
+ double v_prime = trunc(args.value * exp10Double(args.precision.value)) / exp10Double(args.precision.value);
245
+ int64_t v_prime2 = (int64_t)((v_prime - args.min.value) * exp10Double(args.precision.value));
246
+
247
+ BSON_ASSERT(v_prime2 < INT64_MAX && v_prime2 >= 0);
248
+
249
+ uint64_t ret = (uint64_t)v_prime2;
250
+
251
+ // Adjust maximum value to be the max bit range. This will be used by
252
+ // getEdges/minCover to trim bits.
253
+ uint64_t max_value = (UINT64_C(1) << bits_range) - 1;
254
+ BSON_ASSERT(ret <= max_value);
255
+
256
+ *out = (mc_OSTType_Double){ret, 0, max_value};
257
+ return true;
258
+ }
259
+
260
+ // Translate double to uint64 by modifying the bit representation and copying
261
+ // into a uint64. Double is assumed to be a IEEE 754 Binary 64.
262
+ // It is bit-encoded as sign, exponent, and fraction:
263
+ // s eeeeeeee ffffffffffffffffffffffffffffffffffffffffffffffffffff
264
+
265
+ // When we translate the double into "bits", the sign bit means that the
266
+ // negative numbers get mapped into the higher 63 bits of a 64-bit integer.
267
+ // We want them to map into the lower 64-bits so we invert the sign bit.
268
+ args.value *= -1.0;
269
+
270
+ // On Endianness, we support two sets of architectures
271
+ // 1. Little Endian (ppc64le, x64, aarch64) - in these architectures, int64
272
+ // and double are both 64-bits and both arranged in little endian byte order.
273
+ // 2. Big Endian (s390x) - in these architectures, int64 and double are both
274
+ // 64-bits and both arranged in big endian byte order.
275
+ //
276
+ // Therefore, since the order of bytes on each platform is consistent with
277
+ // itself, the conversion below converts a double into correct 64-bit integer
278
+ // that produces the same behavior across plaforms.
279
+ uint64_t uv;
280
+ memcpy(&uv, &args.value, sizeof(uint64_t));
281
+
282
+ if (is_neg) {
283
+ uint64_t new_zero = UINT64_C(1) << 63;
284
+ BSON_ASSERT(uv <= new_zero);
285
+ uv = new_zero - uv;
286
+ }
287
+
288
+ *out = (mc_OSTType_Double){.min = 0, .max = UINT64_MAX, .value = uv};
289
+
290
+ return true;
315
291
  }
316
292
 
317
293
  #if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
@@ -322,299 +298,280 @@ mc_getTypeInfoDouble (mc_getTypeInfoDouble_args_t args,
322
298
  * @param dec
323
299
  * @return mlib_int128
324
300
  */
325
- static mlib_int128
326
- dec128_to_int128 (mc_dec128 dec)
327
- {
328
- // Only normal numbers
329
- BSON_ASSERT (mc_dec128_is_finite (dec));
330
- BSON_ASSERT (!mc_dec128_is_nan (dec));
331
- // We don't support negative numbers
332
- BSON_ASSERT (!mc_dec128_is_negative (dec));
333
- // There is no fractional part:
334
- BSON_ASSERT (mc_dec128_is_zero (mc_dec128_modf (dec).frac));
335
-
336
- mlib_int128 ret = mc_dec128_coeff (dec);
337
-
338
- // Scale the resulting number by a power of ten matching the exponent of the
339
- // Decimal128:
340
- int32_t exp =
341
- ((int32_t) mc_dec128_get_biased_exp (dec)) - MC_DEC128_EXPONENT_BIAS;
342
- // We will scale up/down based on whether it is negative:
343
- mlib_int128 e1 = mlib_int128_pow10 ((uint8_t) abs (exp));
344
- if (exp < 0) {
345
- ret = mlib_int128_div (ret, e1);
346
- } else {
347
- ret = mlib_int128_mul (ret, e1);
348
- }
349
-
350
- return ret;
301
+ static mlib_int128 dec128_to_int128(mc_dec128 dec) {
302
+ // Only normal numbers
303
+ BSON_ASSERT(mc_dec128_is_finite(dec));
304
+ BSON_ASSERT(!mc_dec128_is_nan(dec));
305
+ // We don't support negative numbers
306
+ BSON_ASSERT(!mc_dec128_is_negative(dec));
307
+ // There is no fractional part:
308
+ BSON_ASSERT(mc_dec128_is_zero(mc_dec128_modf(dec).frac));
309
+
310
+ mlib_int128 ret = mc_dec128_coeff(dec);
311
+
312
+ // Scale the resulting number by a power of ten matching the exponent of the
313
+ // Decimal128:
314
+ int32_t exp = ((int32_t)mc_dec128_get_biased_exp(dec)) - MC_DEC128_EXPONENT_BIAS;
315
+ // We will scale up/down based on whether it is negative:
316
+ mlib_int128 e1 = mlib_int128_pow10((uint8_t)abs(exp));
317
+ if (exp < 0) {
318
+ ret = mlib_int128_div(ret, e1);
319
+ } else {
320
+ ret = mlib_int128_mul(ret, e1);
321
+ }
322
+
323
+ return ret;
351
324
  }
352
325
 
353
- bool
354
- mc_getTypeInfoDecimal128 (mc_getTypeInfoDecimal128_args_t args,
355
- mc_OSTType_Decimal128 *out,
356
- mongocrypt_status_t *status)
357
- {
358
- /// Basic param checks
359
- if (args.min.set != args.max.set || args.min.set != args.precision.set) {
360
- CLIENT_ERR (
361
- "min, max, and precision must all be set or must all be unset");
362
- return false;
363
- }
364
-
365
- // We only accept normal numbers
366
- if (mc_dec128_is_inf (args.value) || mc_dec128_is_nan (args.value)) {
367
- CLIENT_ERR ("Infinity and Nan Decimal128 values are not supported.");
368
- return false;
369
- }
370
-
371
- // Check boundary if a range is set
372
- if (args.min.set) {
373
- // [min,max] must be valid
374
- if (mc_dec128_greater_equal (args.min.value, args.max.value)) {
375
- CLIENT_ERR (
376
- "The minimum value must be less than the maximum value, got "
377
- "min: %s, max: %s",
378
- mc_dec128_to_string (args.min.value).str,
379
- mc_dec128_to_string (args.max.value).str);
380
- return false;
381
- }
382
-
383
- // Value must be within [min,max)
384
- if (mc_dec128_greater (args.value, args.max.value) ||
385
- mc_dec128_less (args.value, args.min.value)) {
386
- CLIENT_ERR ("Value must be greater than or equal to the minimum value "
387
- "and less than or equal to the maximum value, got "
388
- "min: %s, max: %s, value: %s",
389
- mc_dec128_to_string (args.min.value).str,
390
- mc_dec128_to_string (args.max.value).str,
391
- mc_dec128_to_string (args.value).str);
392
- return false;
393
- }
394
- }
395
-
396
- // Should we use precision mode?
397
- //
398
- // When we use precision mode, we try to represent as a decimal128 value that
399
- // fits in [-2^127, 2^127] (i.e. is a valid int128)
400
- //
401
- // This check determines if we can represent any precision-truncated value as
402
- // a 128-bit integer I.e. Is ((ub - lb) * 10^precision) < 128 bits.
403
- //
404
- // It is important that we determine whether a range and its precision would
405
- // fit, regardless of the value to be encoded, because the encoding for
406
- // precision-truncated-decimal128 is incompatible with the encoding of the
407
- // full range.
408
- bool use_precision_mode = false;
409
- // The number of bits required to hold the result (used for precision mode)
410
- uint8_t bits_range = 0;
411
- if (args.precision.set) {
412
- // Subnormal representations can support up to 5x10^-6182 as a number
413
- if (args.precision.value > 6182) {
414
- CLIENT_ERR (
415
- "Precision must be between 0 and 6182 inclusive, got: %" PRIu32,
416
- args.precision.value);
417
- return false;
418
- }
419
-
420
- // max - min
421
- mc_dec128 bounds_n1 = mc_dec128_sub (args.max.value, args.min.value);
422
- // The size of [min, max]: (max - min) + 1
423
- mc_dec128 bounds = mc_dec128_add (bounds_n1, MC_DEC128_ONE);
424
-
425
- // We can overflow if max = max_dec128 and min = min_dec128 so make sure
426
- // we have finite number after we do subtraction
427
- if (mc_dec128_is_finite (bounds)) {
428
- // This creates a range which is wider then we permit by our min/max
429
- // bounds check with the +1 but it is as the algorithm is written in
430
- // WRITING-11907.
431
- mc_dec128 precision_scaled_bounds =
432
- mc_dec128_scale (bounds, args.precision.value);
433
- /// The number of bits required to hold the result for the given
434
- /// precision (as decimal)
435
- mc_dec128 bits_range_dec = mc_dec128_log2 (precision_scaled_bounds);
436
-
437
- if (mc_dec128_is_finite (bits_range_dec) &&
438
- mc_dec128_less (bits_range_dec, MC_DEC128 (128))) {
439
- // We need fewer than 128 bits to hold the result. But round up,
440
- // just to be sure:
441
- int64_t r = mc_dec128_to_int64 (mc_dec128_round_integral_ex (
442
- bits_range_dec, MC_DEC128_ROUND_UPWARD, NULL));
443
- BSON_ASSERT (r >= 0);
444
- BSON_ASSERT (r <= UINT8_MAX);
445
- // We've computed the proper 'bits_range'
446
- bits_range = (uint8_t) r;
447
-
448
- if (bits_range < 128) {
449
- use_precision_mode = true;
326
+ bool mc_getTypeInfoDecimal128(mc_getTypeInfoDecimal128_args_t args,
327
+ mc_OSTType_Decimal128 *out,
328
+ mongocrypt_status_t *status) {
329
+ /// Basic param checks
330
+ if (args.min.set != args.max.set || args.min.set != args.precision.set) {
331
+ CLIENT_ERR("min, max, and precision must all be set or must all be unset");
332
+ return false;
333
+ }
334
+
335
+ // We only accept normal numbers
336
+ if (mc_dec128_is_inf(args.value) || mc_dec128_is_nan(args.value)) {
337
+ CLIENT_ERR("Infinity and Nan Decimal128 values are not supported.");
338
+ return false;
339
+ }
340
+
341
+ // Check boundary if a range is set
342
+ if (args.min.set) {
343
+ // [min,max] must be valid
344
+ if (mc_dec128_greater_equal(args.min.value, args.max.value)) {
345
+ CLIENT_ERR("The minimum value must be less than the maximum value, got "
346
+ "min: %s, max: %s",
347
+ mc_dec128_to_string(args.min.value).str,
348
+ mc_dec128_to_string(args.max.value).str);
349
+ return false;
350
+ }
351
+
352
+ // Value must be within [min,max)
353
+ if (mc_dec128_greater(args.value, args.max.value) || mc_dec128_less(args.value, args.min.value)) {
354
+ CLIENT_ERR("Value must be greater than or equal to the minimum value "
355
+ "and less than or equal to the maximum value, got "
356
+ "min: %s, max: %s, value: %s",
357
+ mc_dec128_to_string(args.min.value).str,
358
+ mc_dec128_to_string(args.max.value).str,
359
+ mc_dec128_to_string(args.value).str);
360
+ return false;
361
+ }
362
+ }
363
+
364
+ // Should we use precision mode?
365
+ //
366
+ // When we use precision mode, we try to represent as a decimal128 value that
367
+ // fits in [-2^127, 2^127] (i.e. is a valid int128)
368
+ //
369
+ // This check determines if we can represent any precision-truncated value as
370
+ // a 128-bit integer I.e. Is ((ub - lb) * 10^precision) < 128 bits.
371
+ //
372
+ // It is important that we determine whether a range and its precision would
373
+ // fit, regardless of the value to be encoded, because the encoding for
374
+ // precision-truncated-decimal128 is incompatible with the encoding of the
375
+ // full range.
376
+ bool use_precision_mode = false;
377
+ // The number of bits required to hold the result (used for precision mode)
378
+ uint8_t bits_range = 0;
379
+ if (args.precision.set) {
380
+ // Subnormal representations can support up to 5x10^-6182 as a number
381
+ if (args.precision.value > 6182) {
382
+ CLIENT_ERR("Precision must be between 0 and 6182 inclusive, got: %" PRIu32, args.precision.value);
383
+ return false;
384
+ }
385
+
386
+ // max - min
387
+ mc_dec128 bounds_n1 = mc_dec128_sub(args.max.value, args.min.value);
388
+ // The size of [min, max]: (max - min) + 1
389
+ mc_dec128 bounds = mc_dec128_add(bounds_n1, MC_DEC128_ONE);
390
+
391
+ // We can overflow if max = max_dec128 and min = min_dec128 so make sure
392
+ // we have finite number after we do subtraction
393
+ if (mc_dec128_is_finite(bounds)) {
394
+ // This creates a range which is wider then we permit by our min/max
395
+ // bounds check with the +1 but it is as the algorithm is written in
396
+ // WRITING-11907.
397
+ mc_dec128 precision_scaled_bounds = mc_dec128_scale(bounds, args.precision.value);
398
+ /// The number of bits required to hold the result for the given
399
+ /// precision (as decimal)
400
+ mc_dec128 bits_range_dec = mc_dec128_log2(precision_scaled_bounds);
401
+
402
+ if (mc_dec128_is_finite(bits_range_dec) && mc_dec128_less(bits_range_dec, MC_DEC128(128))) {
403
+ // We need fewer than 128 bits to hold the result. But round up,
404
+ // just to be sure:
405
+ int64_t r =
406
+ mc_dec128_to_int64(mc_dec128_round_integral_ex(bits_range_dec, MC_DEC128_ROUND_UPWARD, NULL));
407
+ BSON_ASSERT(r >= 0);
408
+ BSON_ASSERT(r <= UINT8_MAX);
409
+ // We've computed the proper 'bits_range'
410
+ bits_range = (uint8_t)r;
411
+
412
+ if (bits_range < 128) {
413
+ use_precision_mode = true;
414
+ }
450
415
  }
451
- }
452
- }
453
- }
454
-
455
- // Constant zero
456
- const mlib_int128 i128_zero = MLIB_INT128 (0);
457
- // Constant 1
458
- const mlib_int128 i128_one = MLIB_INT128 (1);
459
- // Constant 10
460
- const mlib_int128 i128_ten = MLIB_INT128 (10);
461
- // Constant: 2^127
462
- const mlib_int128 i128_2pow127 = mlib_int128_lshift (i128_one, 127);
463
- // Coincidentally has the same bit pattern as INT128_SMIN, but we're
464
- // treating it as an unsigned number here, so don't get confused!
465
-
466
- if (use_precision_mode) {
467
- BSON_ASSERT (args.precision.set);
468
- // Example value: 31.4159
469
- // Example Precision = 2
470
-
471
- // Shift the number up
472
- // Returns: 3141.9
473
- mc_dec128 valScaled = mc_dec128_scale (args.value, args.precision.value);
474
-
475
- // Round the number down
476
- // Returns 3141.0
477
- mc_dec128 valTrunc = mc_dec128_round_integral_ex (
478
- valScaled, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
479
-
480
- // Shift the number down
481
- // Returns: 31.41
482
- mc_dec128 v_prime =
483
- mc_dec128_scale (valTrunc, -(int32_t) args.precision.value);
484
-
485
- // Adjust the number by the lower bound
486
- // Make it an integer by scaling the number
487
- //
488
- // Returns 3141.0
489
- mc_dec128 v_prime2 = mc_dec128_scale (
490
- mc_dec128_sub (v_prime, args.min.value), args.precision.value);
491
- // Round the number down again. min may have a fractional value with more
492
- // decimal places than the precision (e.g. .001). Subtracting min may have
493
- // resulted in v_prime2 with a non-zero fraction. v_prime2 is expected to
494
- // have no fractional value when converting to int128.
495
- v_prime2 = mc_dec128_round_integral_ex (
496
- v_prime2, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
497
-
498
- BSON_ASSERT (mc_dec128_less (mc_dec128_log2 (v_prime2), MC_DEC128 (128)));
499
-
500
- // Resulting OST maximum
501
- mlib_int128 ost_max =
502
- mlib_int128_sub (mlib_int128_pow2 (bits_range), i128_one);
503
-
504
- // Now we need to get the Decimal128 out as a 128-bit integer
505
- // But Decimal128 does not support conversion to Int128.
506
- //
507
- // If we think the Decimal128 fits in the range, based on the maximum
508
- // value, we try to convert to int64 directly.
509
- if (bits_range < 64) {
510
- // Try conversion to int64, it may fail but since it is easy we try
511
- // this first.
512
- mc_dec128_flagset flags = {0};
513
- int64_t as64 = mc_dec128_to_int64_ex (v_prime2, &flags);
514
- if (flags.bits == 0) {
515
- // No error. It fits
516
- *out = (mc_OSTType_Decimal128){
517
- .value = MLIB_INT128_CAST (as64),
518
- .min = i128_zero,
519
- .max = ost_max,
520
- };
521
- return true;
522
- } else {
523
- // Conversion failure to 64-bit. Possible overflow, imprecision,
524
- // etc. Fallback to slower dec128_to_int128
525
- }
526
- }
527
-
528
- mlib_int128 u_ret = dec128_to_int128 (v_prime2);
529
-
530
- *out = (mc_OSTType_Decimal128){
531
- .value = u_ret,
532
- .min = i128_zero,
533
- .max = ost_max,
534
- };
535
-
536
- return true;
537
- }
538
-
539
- // The coefficient of the number, without exponent/sign
540
- const mlib_int128 coeff = mc_dec128_coeff (args.value);
541
-
542
- if (mlib_int128_eq (coeff, i128_zero)) {
543
- // If the coefficient is zero, the result is encoded as the midpoint
544
- // between zero and 2^128-1
545
- *out = (mc_OSTType_Decimal128){
546
- .value = i128_2pow127,
547
- .min = i128_zero,
548
- .max = MLIB_INT128_UMAX,
549
- };
550
- return true;
551
- }
552
-
553
- // Coefficient is an unsigned value. We'll later scale our answer based on
554
- // the sign of the actual Decimal128
555
- const bool isNegative = mc_dec128_is_negative (args.value);
556
-
557
- // cMax = 10^34 - 1 (The largest integer representable in Decimal128)
558
- const mlib_int128 cMax =
559
- mlib_int128_sub (mlib_int128_pow10 (34), MLIB_INT128_CAST (1));
560
- const mlib_int128 cMax_div_ten = mlib_int128_div (cMax, i128_ten);
561
-
562
- // The biased exponent from the decimal number. The paper refers to the
563
- // expression (e - e_min), which is the value of the biased exponent.
564
- const uint32_t exp_biased = mc_dec128_get_biased_exp (args.value);
565
-
566
- // ρ (rho) is the greatest integer such that: coeff×10^ρ <= cMax
567
- unsigned rho = 0;
568
- // Keep track of the subexpression coeff×10^ρ rather than recalculating it
569
- // time.
570
- // Initially: (ρ = 0) -> (10^ρ = 1) -> (coeff×10^ρ = coeff×1 = coeff):
571
- mlib_int128 coeff_scaled = coeff;
572
- // Calculate ρ: This could be done using a log10 with a division, but that
573
- // is far more work than just a few multiplications.
574
- // While: coeff×ten^ρ < cMax/10:
575
- while (mlib_int128_ucmp (coeff_scaled, cMax_div_ten) < 0) {
576
- // Increase rho until we pass cMax/10
577
- rho++;
578
- // Scale our computed subexpression rather than fully recomputing it
579
- coeff_scaled = mlib_int128_mul (coeff_scaled, i128_ten);
580
- }
581
-
582
- // No multiplication by 10 should ever send us from N < cMax/10 to N > cMax
583
- BSON_ASSERT (mlib_int128_ucmp (coeff_scaled, cMax) <= 0);
584
-
585
- mlib_int128 result;
586
- if (rho <= exp_biased) {
587
- // ρ is less-than/equal to the exponent with bias.
588
-
589
- // Diff between the biased exponent and ρ.
590
- // Value in paper is spelled "e - e_min - ρ"
591
- const uint32_t exp_diff = exp_biased - (uint32_t) rho;
592
- // cMax * (exp_diff)
593
- const mlib_int128 cmax_scaled =
594
- mlib_int128_mul (cMax, MLIB_INT128_CAST (exp_diff));
595
- // coeff * 10^rho * cMax * (exp_biased - rho)
596
- result = mlib_int128_add (coeff_scaled, cmax_scaled);
597
- } else {
598
- const mlib_int128 biased_scale = mlib_int128_pow10 ((uint8_t) exp_biased);
599
- result = mlib_int128_mul (biased_scale, coeff);
600
- }
601
-
602
- // Always add 2^127:
603
- result = mlib_int128_add (result, i128_2pow127);
604
-
605
- if (isNegative) {
606
- // We calculated the value of the positive coefficient, but the decimal is
607
- // negative. That's okay: Just flip the sign of the encoded result:
608
- result = mlib_int128_negate (result);
609
- }
610
-
611
- *out = (mc_OSTType_Decimal128){
612
- .value = result,
613
- .min = i128_zero,
614
- .max = MLIB_INT128_UMAX,
615
- };
616
-
617
- return true;
416
+ }
417
+ }
418
+
419
+ // Constant zero
420
+ const mlib_int128 i128_zero = MLIB_INT128(0);
421
+ // Constant 1
422
+ const mlib_int128 i128_one = MLIB_INT128(1);
423
+ // Constant 10
424
+ const mlib_int128 i128_ten = MLIB_INT128(10);
425
+ // Constant: 2^127
426
+ const mlib_int128 i128_2pow127 = mlib_int128_lshift(i128_one, 127);
427
+ // Coincidentally has the same bit pattern as INT128_SMIN, but we're
428
+ // treating it as an unsigned number here, so don't get confused!
429
+
430
+ if (use_precision_mode) {
431
+ BSON_ASSERT(args.precision.set);
432
+ // Example value: 31.4159
433
+ // Example Precision = 2
434
+
435
+ // Shift the number up
436
+ // Returns: 3141.9
437
+ mc_dec128 valScaled = mc_dec128_scale(args.value, args.precision.value);
438
+
439
+ // Round the number down
440
+ // Returns 3141.0
441
+ mc_dec128 valTrunc = mc_dec128_round_integral_ex(valScaled, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
442
+
443
+ // Shift the number down
444
+ // Returns: 31.41
445
+ mc_dec128 v_prime = mc_dec128_scale(valTrunc, -(int32_t)args.precision.value);
446
+
447
+ // Adjust the number by the lower bound
448
+ // Make it an integer by scaling the number
449
+ //
450
+ // Returns 3141.0
451
+ mc_dec128 v_prime2 = mc_dec128_scale(mc_dec128_sub(v_prime, args.min.value), args.precision.value);
452
+ // Round the number down again. min may have a fractional value with more
453
+ // decimal places than the precision (e.g. .001). Subtracting min may have
454
+ // resulted in v_prime2 with a non-zero fraction. v_prime2 is expected to
455
+ // have no fractional value when converting to int128.
456
+ v_prime2 = mc_dec128_round_integral_ex(v_prime2, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
457
+
458
+ BSON_ASSERT(mc_dec128_less(mc_dec128_log2(v_prime2), MC_DEC128(128)));
459
+
460
+ // Resulting OST maximum
461
+ mlib_int128 ost_max = mlib_int128_sub(mlib_int128_pow2(bits_range), i128_one);
462
+
463
+ // Now we need to get the Decimal128 out as a 128-bit integer
464
+ // But Decimal128 does not support conversion to Int128.
465
+ //
466
+ // If we think the Decimal128 fits in the range, based on the maximum
467
+ // value, we try to convert to int64 directly.
468
+ if (bits_range < 64) {
469
+ // Try conversion to int64, it may fail but since it is easy we try
470
+ // this first.
471
+ mc_dec128_flagset flags = {0};
472
+ int64_t as64 = mc_dec128_to_int64_ex(v_prime2, &flags);
473
+ if (flags.bits == 0) {
474
+ // No error. It fits
475
+ *out = (mc_OSTType_Decimal128){
476
+ .value = MLIB_INT128_CAST(as64),
477
+ .min = i128_zero,
478
+ .max = ost_max,
479
+ };
480
+ return true;
481
+ } else {
482
+ // Conversion failure to 64-bit. Possible overflow, imprecision,
483
+ // etc. Fallback to slower dec128_to_int128
484
+ }
485
+ }
486
+
487
+ mlib_int128 u_ret = dec128_to_int128(v_prime2);
488
+
489
+ *out = (mc_OSTType_Decimal128){
490
+ .value = u_ret,
491
+ .min = i128_zero,
492
+ .max = ost_max,
493
+ };
494
+
495
+ return true;
496
+ }
497
+
498
+ // The coefficient of the number, without exponent/sign
499
+ const mlib_int128 coeff = mc_dec128_coeff(args.value);
500
+
501
+ if (mlib_int128_eq(coeff, i128_zero)) {
502
+ // If the coefficient is zero, the result is encoded as the midpoint
503
+ // between zero and 2^128-1
504
+ *out = (mc_OSTType_Decimal128){
505
+ .value = i128_2pow127,
506
+ .min = i128_zero,
507
+ .max = MLIB_INT128_UMAX,
508
+ };
509
+ return true;
510
+ }
511
+
512
+ // Coefficient is an unsigned value. We'll later scale our answer based on
513
+ // the sign of the actual Decimal128
514
+ const bool isNegative = mc_dec128_is_negative(args.value);
515
+
516
+ // cMax = 10^34 - 1 (The largest integer representable in Decimal128)
517
+ const mlib_int128 cMax = mlib_int128_sub(mlib_int128_pow10(34), MLIB_INT128_CAST(1));
518
+ const mlib_int128 cMax_div_ten = mlib_int128_div(cMax, i128_ten);
519
+
520
+ // The biased exponent from the decimal number. The paper refers to the
521
+ // expression (e - e_min), which is the value of the biased exponent.
522
+ const uint32_t exp_biased = mc_dec128_get_biased_exp(args.value);
523
+
524
+ // ρ (rho) is the greatest integer such that: coeff×10^ρ <= cMax
525
+ unsigned rho = 0;
526
+ // Keep track of the subexpression coeff×10^ρ rather than recalculating it
527
+ // time.
528
+ // Initially: (ρ = 0) -> (10^ρ = 1) -> (coeff×10^ρ = coeff×1 = coeff):
529
+ mlib_int128 coeff_scaled = coeff;
530
+ // Calculate ρ: This could be done using a log10 with a division, but that
531
+ // is far more work than just a few multiplications.
532
+ // While: coeff×ten^ρ < cMax/10:
533
+ while (mlib_int128_ucmp(coeff_scaled, cMax_div_ten) < 0) {
534
+ // Increase rho until we pass cMax/10
535
+ rho++;
536
+ // Scale our computed subexpression rather than fully recomputing it
537
+ coeff_scaled = mlib_int128_mul(coeff_scaled, i128_ten);
538
+ }
539
+
540
+ // No multiplication by 10 should ever send us from N < cMax/10 to N > cMax
541
+ BSON_ASSERT(mlib_int128_ucmp(coeff_scaled, cMax) <= 0);
542
+
543
+ mlib_int128 result;
544
+ if (rho <= exp_biased) {
545
+ // ρ is less-than/equal to the exponent with bias.
546
+
547
+ // Diff between the biased exponent and ρ.
548
+ // Value in paper is spelled "e - e_min - ρ"
549
+ const uint32_t exp_diff = exp_biased - (uint32_t)rho;
550
+ // cMax * (exp_diff)
551
+ const mlib_int128 cmax_scaled = mlib_int128_mul(cMax, MLIB_INT128_CAST(exp_diff));
552
+ // coeff * 10^rho * cMax * (exp_biased - rho)
553
+ result = mlib_int128_add(coeff_scaled, cmax_scaled);
554
+ } else {
555
+ const mlib_int128 biased_scale = mlib_int128_pow10((uint8_t)exp_biased);
556
+ result = mlib_int128_mul(biased_scale, coeff);
557
+ }
558
+
559
+ // Always add 2^127:
560
+ result = mlib_int128_add(result, i128_2pow127);
561
+
562
+ if (isNegative) {
563
+ // We calculated the value of the positive coefficient, but the decimal is
564
+ // negative. That's okay: Just flip the sign of the encoded result:
565
+ result = mlib_int128_negate(result);
566
+ }
567
+
568
+ *out = (mc_OSTType_Decimal128){
569
+ .value = result,
570
+ .min = i128_zero,
571
+ .max = MLIB_INT128_UMAX,
572
+ };
573
+
574
+ return true;
618
575
  }
619
576
 
620
577
  #endif // defined MONGOCRYPT_HAVE_DECIMAL128_SUPPORT