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
@@ -14,760 +14,883 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ #include "mc-fle-blob-subtype-private.h"
18
+ #include "mc-fle2-insert-update-payload-private-v2.h"
19
+ #include "mc-fle2-insert-update-payload-private.h"
20
+ #include "mc-fle2-payload-iev-private-v2.h"
21
+ #include "mc-fle2-payload-iev-private.h"
22
+ #include "mc-fle2-payload-uev-private.h"
23
+ #include "mc-fle2-payload-uev-v2-private.h"
17
24
  #include "mongocrypt-ciphertext-private.h"
18
25
  #include "mongocrypt-crypto-private.h"
19
26
  #include "mongocrypt-ctx-private.h"
20
27
  #include "mongocrypt-traverse-util-private.h"
21
- #include "mc-fle2-payload-iev-private.h"
22
- #include "mc-fle-blob-subtype-private.h"
23
- #include "mc-fle2-payload-uev-private.h"
24
- #include "mc-fle2-insert-update-payload-private.h"
25
28
 
26
- static bool
27
- _replace_FLE2IndexedEncryptedValue_with_plaintext (void *ctx,
28
- _mongocrypt_buffer_t *in,
29
- bson_value_t *out,
30
- mongocrypt_status_t *status)
31
- {
32
- bool ret = false;
33
- _mongocrypt_key_broker_t *kb = ctx;
34
- mc_FLE2IndexedEncryptedValue_t *iev = mc_FLE2IndexedEncryptedValue_new ();
35
- _mongocrypt_buffer_t S_Key = {0};
36
- _mongocrypt_buffer_t K_Key = {0};
37
-
38
- BSON_ASSERT_PARAM (ctx);
39
- BSON_ASSERT_PARAM (in);
40
- BSON_ASSERT_PARAM (out);
41
-
42
- if (!mc_FLE2IndexedEncryptedValue_parse (iev, in, status)) {
43
- goto fail;
44
- }
45
-
46
- const _mongocrypt_buffer_t *S_KeyId =
47
- mc_FLE2IndexedEncryptedValue_get_S_KeyId (iev, status);
48
- if (!S_KeyId) {
49
- goto fail;
50
- }
51
-
52
- if (!_mongocrypt_key_broker_decrypted_key_by_id (kb, S_KeyId, &S_Key)) {
53
- _mongocrypt_key_broker_status (kb, status);
54
- goto fail;
55
- }
56
-
57
- /* Decrypt InnerEncrypted to get K_KeyId. */
58
- if (!mc_FLE2IndexedEncryptedValue_add_S_Key (
59
- kb->crypt->crypto, iev, &S_Key, status)) {
60
- goto fail;
61
- }
62
-
63
- const _mongocrypt_buffer_t *K_KeyId =
64
- mc_FLE2IndexedEncryptedValue_get_K_KeyId (iev, status);
65
- if (!K_KeyId) {
66
- goto fail;
67
- }
68
-
69
- if (!_mongocrypt_key_broker_decrypted_key_by_id (kb, K_KeyId, &K_Key)) {
70
- _mongocrypt_key_broker_status (kb, status);
71
- goto fail;
72
- }
73
-
74
- /* Decrypt ClientEncryptedValue. */
75
- if (!mc_FLE2IndexedEqualityEncryptedValue_add_K_Key (
76
- kb->crypt->crypto, iev, &K_Key, status)) {
77
- goto fail;
78
- }
79
-
80
- const _mongocrypt_buffer_t *clientValue =
81
- mc_FLE2IndexedEncryptedValue_get_ClientValue (iev, status);
82
- if (!clientValue) {
83
- goto fail;
84
- }
85
-
86
- uint8_t original_bson_type =
87
- (uint8_t) mc_FLE2IndexedEncryptedValue_get_original_bson_type (iev,
88
- status);
89
- if (0 == original_bson_type) {
90
- goto fail;
91
- }
92
-
93
- if (!_mongocrypt_buffer_to_bson_value (
94
- (_mongocrypt_buffer_t *) clientValue, original_bson_type, out)) {
95
- CLIENT_ERR ("decrypted clientValue is not valid BSON");
96
- goto fail;
97
- }
98
-
99
- ret = true;
29
+ #define CHECK_AND_RETURN(cond) \
30
+ if (!(cond)) { \
31
+ goto fail; \
32
+ }
33
+
34
+ #define CHECK_AND_RETURN_STATUS(cond, msg) \
35
+ if (!(cond)) { \
36
+ CLIENT_ERR(msg); \
37
+ goto fail; \
38
+ }
39
+
40
+ #define CHECK_AND_RETURN_KB_STATUS(cond) \
41
+ if (!(cond)) { \
42
+ _mongocrypt_key_broker_status(kb, status); \
43
+ goto fail; \
44
+ }
45
+
46
+ static bool _replace_FLE2IndexedEncryptedValue_with_plaintext(void *ctx,
47
+ _mongocrypt_buffer_t *in,
48
+ bson_value_t *out,
49
+ mongocrypt_status_t *providedStatus) {
50
+ bool ret = false;
51
+ _mongocrypt_key_broker_t *kb = ctx;
52
+ mc_FLE2IndexedEncryptedValue_t *iev = mc_FLE2IndexedEncryptedValue_new();
53
+ _mongocrypt_buffer_t S_Key = {0};
54
+ _mongocrypt_buffer_t K_Key = {0};
55
+ mongocrypt_status_t *status = providedStatus;
56
+
57
+ BSON_ASSERT_PARAM(ctx);
58
+ BSON_ASSERT_PARAM(in);
59
+ BSON_ASSERT_PARAM(out);
60
+
61
+ if (providedStatus == NULL) {
62
+ // We accept a NULL status, but add_[SK]_Key require non-NULL.
63
+ // Make a temporary status object as needed.
64
+ status = mongocrypt_status_new();
65
+ }
66
+
67
+ // Parse the IEV payload to get S_KeyId.
68
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValue_parse(iev, in, status));
69
+ const _mongocrypt_buffer_t *S_KeyId = mc_FLE2IndexedEncryptedValue_get_S_KeyId(iev, status);
70
+ CHECK_AND_RETURN(S_KeyId);
71
+
72
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, S_KeyId, &S_Key));
73
+
74
+ // Use S_Key to decrypt envelope and get to K_KeyId.
75
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValue_add_S_Key(kb->crypt->crypto, iev, &S_Key, status));
76
+ const _mongocrypt_buffer_t *K_KeyId = mc_FLE2IndexedEncryptedValue_get_K_KeyId(iev, status);
77
+ CHECK_AND_RETURN(K_KeyId);
78
+
79
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, K_KeyId, &K_Key));
80
+
81
+ // Decrypt the actual data value using K_Key.
82
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValue_add_K_Key(kb->crypt->crypto, iev, &K_Key, status));
83
+ const _mongocrypt_buffer_t *clientValue = mc_FLE2IndexedEncryptedValue_get_ClientValue(iev, status);
84
+ CHECK_AND_RETURN(clientValue);
85
+
86
+ // Marshal BSON value and type into a usable bson_value_t.
87
+ bson_type_t original_bson_type = mc_FLE2IndexedEncryptedValue_get_original_bson_type(iev, status);
88
+ CHECK_AND_RETURN(original_bson_type != BSON_TYPE_EOD);
89
+ CHECK_AND_RETURN_STATUS(
90
+ _mongocrypt_buffer_to_bson_value((_mongocrypt_buffer_t *)clientValue, (uint8_t)original_bson_type, out),
91
+ "decrypted clientValue is not valid BSON");
92
+
93
+ ret = true;
100
94
  fail:
101
- _mongocrypt_buffer_cleanup (&K_Key);
102
- _mongocrypt_buffer_cleanup (&S_Key);
103
- mc_FLE2IndexedEncryptedValue_destroy (iev);
104
- return ret;
95
+ if (status != providedStatus) {
96
+ mongocrypt_status_destroy(status);
97
+ }
98
+ _mongocrypt_buffer_cleanup(&K_Key);
99
+ _mongocrypt_buffer_cleanup(&S_Key);
100
+ mc_FLE2IndexedEncryptedValue_destroy(iev);
101
+ return ret;
105
102
  }
106
103
 
107
- static bool
108
- _replace_FLE2UnindexedEncryptedValue_with_plaintext (
109
- void *ctx,
110
- _mongocrypt_buffer_t *in,
111
- bson_value_t *out,
112
- mongocrypt_status_t *status)
113
- {
114
- bool ret = false;
115
- _mongocrypt_key_broker_t *kb = ctx;
116
- mc_FLE2UnindexedEncryptedValue_t *uev =
117
- mc_FLE2UnindexedEncryptedValue_new ();
118
- _mongocrypt_buffer_t key = {0};
119
-
120
- BSON_ASSERT_PARAM (ctx);
121
- BSON_ASSERT_PARAM (in);
122
- BSON_ASSERT_PARAM (out);
123
-
124
- if (!mc_FLE2UnindexedEncryptedValue_parse (uev, in, status)) {
125
- goto fail;
126
- }
127
-
128
- const _mongocrypt_buffer_t *key_uuid =
129
- mc_FLE2UnindexedEncryptedValue_get_key_uuid (uev, status);
130
- if (!key_uuid) {
131
- goto fail;
132
- }
133
-
134
- if (!_mongocrypt_key_broker_decrypted_key_by_id (kb, key_uuid, &key)) {
135
- _mongocrypt_key_broker_status (kb, status);
136
- goto fail;
137
- }
138
-
139
- /* Decrypt ciphertext. */
140
- const _mongocrypt_buffer_t *plaintext =
141
- mc_FLE2UnindexedEncryptedValue_decrypt (
142
- kb->crypt->crypto, uev, &key, status);
143
- if (!plaintext) {
144
- goto fail;
145
- }
146
-
147
- uint8_t original_bson_type =
148
- (uint8_t) mc_FLE2UnindexedEncryptedValue_get_original_bson_type (uev,
149
- status);
150
- if (0 == original_bson_type) {
151
- goto fail;
152
- }
153
-
154
- if (!_mongocrypt_buffer_to_bson_value (
155
- (_mongocrypt_buffer_t *) plaintext, original_bson_type, out)) {
156
- CLIENT_ERR ("decrypted plaintext is not valid BSON");
157
- goto fail;
158
- }
159
-
160
- ret = true;
104
+ static bool _replace_FLE2IndexedEncryptedValueV2_with_plaintext(void *ctx,
105
+ _mongocrypt_buffer_t *in,
106
+ bson_value_t *out,
107
+ mongocrypt_status_t *providedStatus) {
108
+ bool ret = false;
109
+ _mongocrypt_key_broker_t *kb = ctx;
110
+ mc_FLE2IndexedEncryptedValueV2_t *iev = mc_FLE2IndexedEncryptedValueV2_new();
111
+ _mongocrypt_buffer_t S_Key = {0};
112
+ _mongocrypt_buffer_t K_Key = {0};
113
+ mongocrypt_status_t *status = providedStatus;
114
+
115
+ BSON_ASSERT_PARAM(ctx);
116
+ BSON_ASSERT_PARAM(in);
117
+ BSON_ASSERT_PARAM(out);
118
+
119
+ if (providedStatus == NULL) {
120
+ // We accept a NULL status, but add_[SK]_Key require non-NULL.
121
+ // Make a temporary status object as needed.
122
+ status = mongocrypt_status_new();
123
+ }
124
+
125
+ // Parse the IEV payload to get S_KeyId.
126
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValueV2_parse(iev, in, status));
127
+ const _mongocrypt_buffer_t *S_KeyId = mc_FLE2IndexedEncryptedValueV2_get_S_KeyId(iev, status);
128
+ CHECK_AND_RETURN(S_KeyId);
129
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, S_KeyId, &S_Key));
130
+
131
+ // Use S_Key to decrypt envelope and get to K_KeyId.
132
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValueV2_add_S_Key(kb->crypt->crypto, iev, &S_Key, status));
133
+ const _mongocrypt_buffer_t *K_KeyId = mc_FLE2IndexedEncryptedValueV2_get_K_KeyId(iev, status);
134
+ CHECK_AND_RETURN(K_KeyId);
135
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, K_KeyId, &K_Key));
136
+
137
+ // Decrypt the actual data value using K_Key.
138
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValueV2_add_K_Key(kb->crypt->crypto, iev, &K_Key, status));
139
+ const _mongocrypt_buffer_t *clientValue = mc_FLE2IndexedEncryptedValueV2_get_ClientValue(iev, status);
140
+ CHECK_AND_RETURN(clientValue);
141
+
142
+ // Marshal BSON value and type into a usable bson_value_t.
143
+ bson_type_t bson_type = mc_FLE2IndexedEncryptedValueV2_get_bson_value_type(iev, status);
144
+ CHECK_AND_RETURN(bson_type != BSON_TYPE_EOD);
145
+ CHECK_AND_RETURN_STATUS(
146
+ _mongocrypt_buffer_to_bson_value((_mongocrypt_buffer_t *)clientValue, (uint8_t)bson_type, out),
147
+ "decrypted clientValue is not valid BSON");
148
+
149
+ ret = true;
161
150
  fail:
162
- _mongocrypt_buffer_cleanup (&key);
163
- mc_FLE2UnindexedEncryptedValue_destroy (uev);
164
- return ret;
151
+ if (status != providedStatus) {
152
+ mongocrypt_status_destroy(status);
153
+ }
154
+ _mongocrypt_buffer_cleanup(&K_Key);
155
+ _mongocrypt_buffer_cleanup(&S_Key);
156
+ mc_FLE2IndexedEncryptedValueV2_destroy(iev);
157
+ return ret;
165
158
  }
166
159
 
167
- static bool
168
- _replace_FLE2InsertUpdatePayload_with_plaintext (void *ctx,
169
- _mongocrypt_buffer_t *in,
170
- bson_value_t *out,
171
- mongocrypt_status_t *status)
172
- {
173
- bool ret = false;
174
- _mongocrypt_key_broker_t *kb = ctx;
175
- mc_FLE2InsertUpdatePayload_t iup;
176
- _mongocrypt_buffer_t key = {0};
177
-
178
- BSON_ASSERT_PARAM (ctx);
179
- BSON_ASSERT_PARAM (in);
180
- BSON_ASSERT_PARAM (out);
181
-
182
- mc_FLE2InsertUpdatePayload_init (&iup);
183
-
184
- if (!mc_FLE2InsertUpdatePayload_parse (&iup, in, status)) {
185
- goto fail;
186
- }
187
-
188
- if (!_mongocrypt_key_broker_decrypted_key_by_id (kb, &iup.userKeyId, &key)) {
189
- _mongocrypt_key_broker_status (kb, status);
190
- goto fail;
191
- }
192
-
193
- /* Decrypt ciphertext. */
194
- const _mongocrypt_buffer_t *plaintext = mc_FLE2InsertUpdatePayload_decrypt (
195
- kb->crypt->crypto, &iup, &key, status);
196
- if (!plaintext) {
197
- goto fail;
198
- }
199
-
200
- uint8_t original_bson_type = (uint8_t) iup.valueType;
201
-
202
- if (!_mongocrypt_buffer_to_bson_value (
203
- (_mongocrypt_buffer_t *) plaintext, original_bson_type, out)) {
204
- CLIENT_ERR ("decrypted plaintext is not valid BSON");
205
- goto fail;
206
- }
207
-
208
- ret = true;
160
+ static bool _replace_FLE2UnindexedEncryptedValue_with_plaintext(void *ctx,
161
+ _mongocrypt_buffer_t *in,
162
+ bson_value_t *out,
163
+ mongocrypt_status_t *status) {
164
+ bool ret = false;
165
+ _mongocrypt_key_broker_t *kb = ctx;
166
+ mc_FLE2UnindexedEncryptedValue_t *uev = mc_FLE2UnindexedEncryptedValue_new();
167
+ _mongocrypt_buffer_t key = {0};
168
+
169
+ BSON_ASSERT_PARAM(ctx);
170
+ BSON_ASSERT_PARAM(in);
171
+ BSON_ASSERT_PARAM(out);
172
+
173
+ // Parse the UEV payload to get the encryption key.
174
+ CHECK_AND_RETURN(mc_FLE2UnindexedEncryptedValue_parse(uev, in, status));
175
+
176
+ const _mongocrypt_buffer_t *key_uuid = mc_FLE2UnindexedEncryptedValue_get_key_uuid(uev, status);
177
+ CHECK_AND_RETURN(key_uuid);
178
+
179
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, key_uuid, &key));
180
+
181
+ // Decrypt the actual data value using encryption key.
182
+ const _mongocrypt_buffer_t *plaintext =
183
+ mc_FLE2UnindexedEncryptedValue_decrypt(kb->crypt->crypto, uev, &key, status);
184
+ CHECK_AND_RETURN(plaintext);
185
+
186
+ // Marshal BSON value and type into a usable bson_value_t.
187
+ bson_type_t original_bson_type = mc_FLE2UnindexedEncryptedValue_get_original_bson_type(uev, status);
188
+ CHECK_AND_RETURN(original_bson_type != BSON_TYPE_EOD);
189
+
190
+ CHECK_AND_RETURN_STATUS(
191
+ _mongocrypt_buffer_to_bson_value((_mongocrypt_buffer_t *)plaintext, (uint8_t)original_bson_type, out),
192
+ "decrypted plaintext is not valid BSON");
193
+
194
+ ret = true;
209
195
  fail:
210
- _mongocrypt_buffer_cleanup (&key);
211
- mc_FLE2InsertUpdatePayload_cleanup (&iup);
212
- return ret;
196
+ _mongocrypt_buffer_cleanup(&key);
197
+ mc_FLE2UnindexedEncryptedValue_destroy(uev);
198
+ return ret;
213
199
  }
214
200
 
215
- static bool
216
- _replace_ciphertext_with_plaintext (void *ctx,
217
- _mongocrypt_buffer_t *in,
218
- bson_value_t *out,
219
- mongocrypt_status_t *status)
220
- {
221
- _mongocrypt_key_broker_t *kb;
222
- _mongocrypt_ciphertext_t ciphertext;
223
- _mongocrypt_buffer_t plaintext;
224
- _mongocrypt_buffer_t key_material;
225
- _mongocrypt_buffer_t associated_data;
226
- uint32_t bytes_written;
227
- bool ret = false;
228
-
229
- BSON_ASSERT_PARAM (ctx);
230
- BSON_ASSERT_PARAM (in);
231
- BSON_ASSERT_PARAM (out);
232
- BSON_ASSERT (in->data);
233
-
234
- if (in->data[0] == MC_SUBTYPE_FLE2IndexedEqualityEncryptedValue ||
235
- in->data[0] == MC_SUBTYPE_FLE2IndexedRangeEncryptedValue) {
236
- return _replace_FLE2IndexedEncryptedValue_with_plaintext (
237
- ctx, in, out, status);
238
- }
239
-
240
- if (in->data[0] == MC_SUBTYPE_FLE2UnindexedEncryptedValue) {
241
- return _replace_FLE2UnindexedEncryptedValue_with_plaintext (
242
- ctx, in, out, status);
243
- }
244
-
245
- if (in->data[0] == MC_SUBTYPE_FLE2InsertUpdatePayload) {
246
- return _replace_FLE2InsertUpdatePayload_with_plaintext (
247
- ctx, in, out, status);
248
- }
249
-
250
- _mongocrypt_buffer_init (&plaintext);
251
- _mongocrypt_buffer_init (&associated_data);
252
- _mongocrypt_buffer_init (&key_material);
253
- kb = (_mongocrypt_key_broker_t *) ctx;
254
-
255
- if (!_mongocrypt_ciphertext_parse_unowned (in, &ciphertext, status)) {
256
- goto fail;
257
- }
258
-
259
- /* look up the key */
260
- if (!_mongocrypt_key_broker_decrypted_key_by_id (
261
- kb, &ciphertext.key_id, &key_material)) {
262
- CLIENT_ERR ("key not found");
263
- goto fail;
264
- }
265
-
266
- plaintext.len =
267
- _mongocrypt_calculate_plaintext_len (ciphertext.data.len, status);
268
- if (plaintext.len == 0) {
269
- goto fail;
270
- }
271
- plaintext.data = bson_malloc0 (plaintext.len);
272
- BSON_ASSERT (plaintext.data);
273
-
274
- plaintext.owned = true;
275
-
276
- if (!_mongocrypt_ciphertext_serialize_associated_data (&ciphertext,
277
- &associated_data)) {
278
- CLIENT_ERR ("could not serialize associated data");
279
- goto fail;
280
- }
281
-
282
- if (!_mongocrypt_do_decryption (kb->crypt->crypto,
283
- &associated_data,
284
- &key_material,
285
- &ciphertext.data,
286
- &plaintext,
287
- &bytes_written,
288
- status)) {
289
- goto fail;
290
- }
291
-
292
- plaintext.len = bytes_written;
293
-
294
- if (!_mongocrypt_buffer_to_bson_value (
295
- &plaintext, ciphertext.original_bson_type, out)) {
296
- CLIENT_ERR ("malformed encrypted bson");
297
- goto fail;
298
- }
299
- ret = true;
201
+ static bool _replace_FLE2UnindexedEncryptedValueV2_with_plaintext(void *ctx,
202
+ _mongocrypt_buffer_t *in,
203
+ bson_value_t *out,
204
+ mongocrypt_status_t *status) {
205
+ bool ret = false;
206
+ _mongocrypt_key_broker_t *kb = ctx;
207
+ mc_FLE2UnindexedEncryptedValueV2_t *uev = mc_FLE2UnindexedEncryptedValueV2_new();
208
+ _mongocrypt_buffer_t key = {0};
209
+
210
+ BSON_ASSERT_PARAM(ctx);
211
+ BSON_ASSERT_PARAM(in);
212
+ BSON_ASSERT_PARAM(out);
213
+
214
+ // Parse the UEV payload to get the encryption key.
215
+ CHECK_AND_RETURN(mc_FLE2UnindexedEncryptedValueV2_parse(uev, in, status));
216
+
217
+ const _mongocrypt_buffer_t *key_uuid = mc_FLE2UnindexedEncryptedValueV2_get_key_uuid(uev, status);
218
+ CHECK_AND_RETURN(key_uuid);
219
+
220
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, key_uuid, &key));
221
+
222
+ // Decrypt the actual data value using encryption key.
223
+ const _mongocrypt_buffer_t *plaintext =
224
+ mc_FLE2UnindexedEncryptedValueV2_decrypt(kb->crypt->crypto, uev, &key, status);
225
+ CHECK_AND_RETURN(plaintext);
226
+
227
+ // Marshal BSON value and type into a usable bson_value_t.
228
+ bson_type_t original_bson_type = mc_FLE2UnindexedEncryptedValueV2_get_original_bson_type(uev, status);
229
+ CHECK_AND_RETURN(original_bson_type != BSON_TYPE_EOD);
230
+
231
+ CHECK_AND_RETURN_STATUS(
232
+ _mongocrypt_buffer_to_bson_value((_mongocrypt_buffer_t *)plaintext, (uint8_t)original_bson_type, out),
233
+ "decrypted plaintext is not valid BSON");
300
234
 
235
+ ret = true;
301
236
  fail:
302
- _mongocrypt_buffer_cleanup (&plaintext);
303
- _mongocrypt_buffer_cleanup (&associated_data);
304
- _mongocrypt_buffer_cleanup (&key_material);
305
- return ret;
237
+ _mongocrypt_buffer_cleanup(&key);
238
+ mc_FLE2UnindexedEncryptedValueV2_destroy(uev);
239
+ return ret;
306
240
  }
307
241
 
242
+ static bool _replace_FLE2InsertUpdatePayload_with_plaintext(void *ctx,
243
+ _mongocrypt_buffer_t *in,
244
+ bson_value_t *out,
245
+ mongocrypt_status_t *status) {
246
+ bool ret = false;
247
+ _mongocrypt_key_broker_t *kb = ctx;
248
+ mc_FLE2InsertUpdatePayload_t iup;
249
+ _mongocrypt_buffer_t key = {0};
308
250
 
309
- static bool
310
- _finalize (mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out)
311
- {
312
- bson_t as_bson, final_bson;
313
- bson_iter_t iter;
314
- _mongocrypt_ctx_decrypt_t *dctx;
315
- bool res;
316
-
317
- if (!ctx) {
318
- return false;
319
- }
320
-
321
- if (!out) {
322
- return _mongocrypt_ctx_fail_w_msg (ctx, "null out parameter");
323
- }
324
-
325
- dctx = (_mongocrypt_ctx_decrypt_t *) ctx;
326
-
327
- if (ctx->nothing_to_do) {
328
- _mongocrypt_buffer_to_binary (&dctx->original_doc, out);
329
- ctx->state = MONGOCRYPT_CTX_DONE;
330
- return true;
331
- }
332
-
333
- if (!_mongocrypt_buffer_to_bson (&dctx->original_doc, &as_bson)) {
334
- return _mongocrypt_ctx_fail_w_msg (ctx, "malformed bson");
335
- }
336
-
337
- bson_iter_init (&iter, &as_bson);
338
- bson_init (&final_bson);
339
- res =
340
- _mongocrypt_transform_binary_in_bson (_replace_ciphertext_with_plaintext,
341
- &ctx->kb,
342
- TRAVERSE_MATCH_CIPHERTEXT,
343
- &iter,
344
- &final_bson,
345
- ctx->status);
346
- if (!res) {
347
- bson_destroy (&final_bson);
348
- return _mongocrypt_ctx_fail (ctx);
349
- }
350
-
351
- _mongocrypt_buffer_steal_from_bson (&dctx->decrypted_doc, &final_bson);
352
- out->data = dctx->decrypted_doc.data;
353
- out->len = dctx->decrypted_doc.len;
354
- ctx->state = MONGOCRYPT_CTX_DONE;
355
- return true;
251
+ BSON_ASSERT_PARAM(ctx);
252
+ BSON_ASSERT_PARAM(in);
253
+ BSON_ASSERT_PARAM(out);
254
+
255
+ mc_FLE2InsertUpdatePayload_init(&iup);
256
+
257
+ // Parse the IUP payload to get the encryption key.
258
+ CHECK_AND_RETURN(mc_FLE2InsertUpdatePayload_parse(&iup, in, status));
259
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, &iup.userKeyId, &key));
260
+
261
+ // Decrypt the actual data value using encryption key.
262
+ const _mongocrypt_buffer_t *plaintext = mc_FLE2InsertUpdatePayload_decrypt(kb->crypt->crypto, &iup, &key, status);
263
+ CHECK_AND_RETURN(plaintext);
264
+
265
+ // Marshal BSON value and type into a usable bson_value_t.
266
+ bson_type_t original_bson_type = iup.valueType;
267
+ CHECK_AND_RETURN_STATUS(
268
+ _mongocrypt_buffer_to_bson_value((_mongocrypt_buffer_t *)plaintext, (uint8_t)original_bson_type, out),
269
+ "decrypted plaintext is not valid BSON");
270
+
271
+ ret = true;
272
+ fail:
273
+ _mongocrypt_buffer_cleanup(&key);
274
+ mc_FLE2InsertUpdatePayload_cleanup(&iup);
275
+ return ret;
356
276
  }
357
277
 
358
- // TODO: rename to _collect_S_KeyID_from_FLE2IndexedEncryptedValue
359
- static bool
360
- _collect_S_KeyID_from_FLE2IndexedEncryptedValue (void *ctx,
361
- _mongocrypt_buffer_t *in,
362
- mongocrypt_status_t *status)
363
- {
364
- bool ret = false;
365
- _mongocrypt_key_broker_t *kb = ctx;
366
- mc_FLE2IndexedEncryptedValue_t *iev;
367
-
368
- BSON_ASSERT_PARAM (ctx);
369
- BSON_ASSERT_PARAM (in);
370
-
371
- iev = mc_FLE2IndexedEncryptedValue_new ();
372
-
373
- if (!mc_FLE2IndexedEncryptedValue_parse (iev, in, status)) {
374
- goto fail;
375
- }
376
-
377
- const _mongocrypt_buffer_t *S_KeyId =
378
- mc_FLE2IndexedEncryptedValue_get_S_KeyId (iev, status);
379
- if (!S_KeyId) {
380
- goto fail;
381
- }
382
-
383
- if (!_mongocrypt_key_broker_request_id (kb, S_KeyId)) {
384
- _mongocrypt_key_broker_status (kb, status);
385
- goto fail;
386
- }
387
-
388
- ret = true;
278
+ static bool _replace_FLE2InsertUpdatePayloadV2_with_plaintext(void *ctx,
279
+ _mongocrypt_buffer_t *in,
280
+ bson_value_t *out,
281
+ mongocrypt_status_t *status) {
282
+ bool ret = false;
283
+ _mongocrypt_key_broker_t *kb = ctx;
284
+ mc_FLE2InsertUpdatePayloadV2_t iup;
285
+ _mongocrypt_buffer_t key = {0};
286
+
287
+ BSON_ASSERT_PARAM(ctx);
288
+ BSON_ASSERT_PARAM(in);
289
+ BSON_ASSERT_PARAM(out);
290
+
291
+ mc_FLE2InsertUpdatePayloadV2_init(&iup);
292
+
293
+ // Parse the IUP payload to get the encryption key.
294
+ CHECK_AND_RETURN(mc_FLE2InsertUpdatePayloadV2_parse(&iup, in, status));
295
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, &iup.userKeyId, &key));
296
+
297
+ // Decrypt the actual data value using encryption key.
298
+ const _mongocrypt_buffer_t *plaintext = mc_FLE2InsertUpdatePayloadV2_decrypt(kb->crypt->crypto, &iup, &key, status);
299
+ CHECK_AND_RETURN(plaintext);
300
+
301
+ // Marshal BSON value and type into a usable bson_value_t.
302
+ bson_type_t original_bson_type = iup.valueType;
303
+ CHECK_AND_RETURN_STATUS(
304
+ _mongocrypt_buffer_to_bson_value((_mongocrypt_buffer_t *)plaintext, (uint8_t)original_bson_type, out),
305
+ "decrypted plaintext is not valid BSON");
306
+
307
+ ret = true;
389
308
  fail:
390
- mc_FLE2IndexedEncryptedValue_destroy (iev);
391
- return ret;
309
+ _mongocrypt_buffer_cleanup(&key);
310
+ mc_FLE2InsertUpdatePayloadV2_cleanup(&iup);
311
+ return ret;
392
312
  }
393
313
 
394
- static bool
395
- _collect_K_KeyID_from_FLE2IndexedEncryptedValue (void *ctx,
396
- _mongocrypt_buffer_t *in,
397
- mongocrypt_status_t *status)
398
- {
399
- bool ret = false;
400
- _mongocrypt_key_broker_t *kb = ctx;
401
- mc_FLE2IndexedEncryptedValue_t *iev;
402
- _mongocrypt_buffer_t S_Key = {0};
403
-
404
- BSON_ASSERT_PARAM (ctx);
405
- BSON_ASSERT_PARAM (in);
406
- BSON_ASSERT (in->data);
407
-
408
- /* Ignore other ciphertext types. */
409
- if (in->data[0] != MC_SUBTYPE_FLE2IndexedEqualityEncryptedValue &&
410
- in->data[0] != MC_SUBTYPE_FLE2IndexedRangeEncryptedValue) {
411
- return true;
412
- }
413
-
414
- iev = mc_FLE2IndexedEncryptedValue_new ();
415
-
416
- if (!mc_FLE2IndexedEncryptedValue_parse (iev, in, status)) {
417
- goto fail;
418
- }
419
-
420
- const _mongocrypt_buffer_t *S_KeyId =
421
- mc_FLE2IndexedEncryptedValue_get_S_KeyId (iev, status);
422
- if (!S_KeyId) {
423
- goto fail;
424
- }
425
-
426
- if (!_mongocrypt_key_broker_decrypted_key_by_id (kb, S_KeyId, &S_Key)) {
427
- _mongocrypt_key_broker_status (kb, status);
428
- goto fail;
429
- }
430
-
431
- /* Decrypt InnerEncrypted to get K_KeyId. */
432
- if (!mc_FLE2IndexedEncryptedValue_add_S_Key (
433
- kb->crypt->crypto, iev, &S_Key, status)) {
434
- goto fail;
435
- }
436
-
437
- /* Add request for K_KeyId. */
438
- const _mongocrypt_buffer_t *K_KeyId =
439
- mc_FLE2IndexedEncryptedValue_get_K_KeyId (iev, status);
440
- if (!K_KeyId) {
441
- goto fail;
442
- }
443
-
444
- if (!_mongocrypt_key_broker_request_id (kb, K_KeyId)) {
445
- _mongocrypt_key_broker_status (kb, status);
446
- goto fail;
447
- }
448
-
449
- ret = true;
314
+ static bool _replace_FLE1Payload_with_plaintext(void *ctx,
315
+ _mongocrypt_buffer_t *in,
316
+ bson_value_t *out,
317
+ mongocrypt_status_t *status) {
318
+ _mongocrypt_key_broker_t *kb;
319
+ _mongocrypt_ciphertext_t ciphertext;
320
+ _mongocrypt_buffer_t plaintext;
321
+ _mongocrypt_buffer_t key_material;
322
+ _mongocrypt_buffer_t associated_data;
323
+ uint32_t bytes_written;
324
+ bool ret = false;
325
+
326
+ BSON_ASSERT_PARAM(ctx);
327
+ BSON_ASSERT_PARAM(in);
328
+ BSON_ASSERT_PARAM(out);
329
+ BSON_ASSERT(in->data);
330
+
331
+ _mongocrypt_buffer_init(&plaintext);
332
+ _mongocrypt_buffer_init(&associated_data);
333
+ _mongocrypt_buffer_init(&key_material);
334
+ kb = (_mongocrypt_key_broker_t *)ctx;
335
+
336
+ CHECK_AND_RETURN(_mongocrypt_ciphertext_parse_unowned(in, &ciphertext, status));
337
+
338
+ /* look up the key */
339
+ CHECK_AND_RETURN_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, &ciphertext.key_id, &key_material),
340
+ "key not found");
341
+
342
+ const _mongocrypt_value_encryption_algorithm_t *fle1alg = _mcFLE1Algorithm();
343
+ plaintext.len = fle1alg->get_plaintext_len(ciphertext.data.len, status);
344
+ CHECK_AND_RETURN(plaintext.len != 0);
345
+ plaintext.data = bson_malloc0(plaintext.len);
346
+ BSON_ASSERT(plaintext.data);
347
+
348
+ plaintext.owned = true;
349
+
350
+ CHECK_AND_RETURN_STATUS(_mongocrypt_ciphertext_serialize_associated_data(&ciphertext, &associated_data),
351
+ "could not serialize associated data");
352
+
353
+ CHECK_AND_RETURN(fle1alg->do_decrypt(kb->crypt->crypto,
354
+ &associated_data,
355
+ &key_material,
356
+ &ciphertext.data,
357
+ &plaintext,
358
+ &bytes_written,
359
+ status));
360
+
361
+ plaintext.len = bytes_written;
362
+
363
+ CHECK_AND_RETURN_STATUS(_mongocrypt_buffer_to_bson_value(&plaintext, ciphertext.original_bson_type, out),
364
+ "malformed encrypted bson");
365
+
366
+ ret = true;
367
+ fail:
368
+ _mongocrypt_buffer_cleanup(&plaintext);
369
+ _mongocrypt_buffer_cleanup(&associated_data);
370
+ _mongocrypt_buffer_cleanup(&key_material);
371
+ return ret;
372
+ }
373
+
374
+ static bool _replace_ciphertext_with_plaintext(void *ctx,
375
+ _mongocrypt_buffer_t *in,
376
+ bson_value_t *out,
377
+ mongocrypt_status_t *status) {
378
+ BSON_ASSERT_PARAM(ctx);
379
+ BSON_ASSERT_PARAM(in);
380
+ BSON_ASSERT_PARAM(out);
381
+ BSON_ASSERT(in->data);
382
+
383
+ switch (in->data[0]) {
384
+ // FLE2v2
385
+ case MC_SUBTYPE_FLE2IndexedEqualityEncryptedValueV2:
386
+ case MC_SUBTYPE_FLE2IndexedRangeEncryptedValueV2:
387
+ return _replace_FLE2IndexedEncryptedValueV2_with_plaintext(ctx, in, out, status);
388
+ case MC_SUBTYPE_FLE2InsertUpdatePayloadV2:
389
+ return _replace_FLE2InsertUpdatePayloadV2_with_plaintext(ctx, in, out, status);
390
+ case MC_SUBTYPE_FLE2UnindexedEncryptedValueV2:
391
+ return _replace_FLE2UnindexedEncryptedValueV2_with_plaintext(ctx, in, out, status);
392
+
393
+ // FLE2v1
394
+ case MC_SUBTYPE_FLE2IndexedEqualityEncryptedValue:
395
+ case MC_SUBTYPE_FLE2IndexedRangeEncryptedValue:
396
+ return _replace_FLE2IndexedEncryptedValue_with_plaintext(ctx, in, out, status);
397
+ case MC_SUBTYPE_FLE2InsertUpdatePayload:
398
+ return _replace_FLE2InsertUpdatePayload_with_plaintext(ctx, in, out, status);
399
+ case MC_SUBTYPE_FLE2UnindexedEncryptedValue:
400
+ return _replace_FLE2UnindexedEncryptedValue_with_plaintext(ctx, in, out, status);
401
+
402
+ // FLE1
403
+ default: return _replace_FLE1Payload_with_plaintext(ctx, in, out, status);
404
+ }
405
+ }
406
+
407
+ static bool _finalize(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *out) {
408
+ bson_t as_bson, final_bson;
409
+ bson_iter_t iter;
410
+ _mongocrypt_ctx_decrypt_t *dctx;
411
+ bool res;
412
+
413
+ if (!ctx) {
414
+ return false;
415
+ }
416
+
417
+ if (!out) {
418
+ return _mongocrypt_ctx_fail_w_msg(ctx, "null out parameter");
419
+ }
420
+
421
+ dctx = (_mongocrypt_ctx_decrypt_t *)ctx;
422
+
423
+ if (ctx->nothing_to_do) {
424
+ _mongocrypt_buffer_to_binary(&dctx->original_doc, out);
425
+ ctx->state = MONGOCRYPT_CTX_DONE;
426
+ return true;
427
+ }
428
+
429
+ if (!_mongocrypt_buffer_to_bson(&dctx->original_doc, &as_bson)) {
430
+ return _mongocrypt_ctx_fail_w_msg(ctx, "malformed bson");
431
+ }
432
+
433
+ bson_iter_init(&iter, &as_bson);
434
+ bson_init(&final_bson);
435
+ res = _mongocrypt_transform_binary_in_bson(_replace_ciphertext_with_plaintext,
436
+ &ctx->kb,
437
+ TRAVERSE_MATCH_CIPHERTEXT,
438
+ &iter,
439
+ &final_bson,
440
+ ctx->status);
441
+ if (!res) {
442
+ bson_destroy(&final_bson);
443
+ return _mongocrypt_ctx_fail(ctx);
444
+ }
445
+
446
+ _mongocrypt_buffer_steal_from_bson(&dctx->decrypted_doc, &final_bson);
447
+ out->data = dctx->decrypted_doc.data;
448
+ out->len = dctx->decrypted_doc.len;
449
+ ctx->state = MONGOCRYPT_CTX_DONE;
450
+ return true;
451
+ }
452
+
453
+ static bool _collect_S_KeyID_from_FLE2IndexedEncryptedValue(void *ctx,
454
+ const _mongocrypt_buffer_t *in,
455
+ mongocrypt_status_t *status) {
456
+ bool ret = false;
457
+ _mongocrypt_key_broker_t *kb = ctx;
458
+ BSON_ASSERT_PARAM(kb);
459
+ BSON_ASSERT_PARAM(in);
460
+
461
+ mc_FLE2IndexedEncryptedValue_t *iev = mc_FLE2IndexedEncryptedValue_new();
462
+ CHECK_AND_RETURN(iev);
463
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValue_parse(iev, in, status));
464
+ const _mongocrypt_buffer_t *S_KeyId = mc_FLE2IndexedEncryptedValue_get_S_KeyId(iev, status);
465
+ CHECK_AND_RETURN(S_KeyId);
466
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_request_id(kb, S_KeyId));
467
+
468
+ ret = true;
469
+ fail:
470
+ mc_FLE2IndexedEncryptedValue_destroy(iev);
471
+ return ret;
472
+ }
473
+
474
+ static bool _collect_S_KeyID_from_FLE2IndexedEncryptedValueV2(void *ctx,
475
+ const _mongocrypt_buffer_t *in,
476
+ mongocrypt_status_t *status) {
477
+ bool ret = false;
478
+ _mongocrypt_key_broker_t *kb = ctx;
479
+ BSON_ASSERT_PARAM(kb);
480
+ BSON_ASSERT_PARAM(in);
481
+
482
+ mc_FLE2IndexedEncryptedValueV2_t *iev = mc_FLE2IndexedEncryptedValueV2_new();
483
+ CHECK_AND_RETURN(iev);
484
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValueV2_parse(iev, in, status));
485
+ const _mongocrypt_buffer_t *S_KeyId = mc_FLE2IndexedEncryptedValueV2_get_S_KeyId(iev, status);
486
+ CHECK_AND_RETURN(S_KeyId);
487
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_request_id(kb, S_KeyId));
488
+
489
+ ret = true;
490
+ fail:
491
+ mc_FLE2IndexedEncryptedValueV2_destroy(iev);
492
+ return ret;
493
+ }
494
+
495
+ static bool _collect_K_KeyID_from_FLE2IndexedEncryptedValueV2(void *ctx,
496
+ const _mongocrypt_buffer_t *in,
497
+ mongocrypt_status_t *status) {
498
+ BSON_ASSERT_PARAM(ctx);
499
+ BSON_ASSERT_PARAM(in);
500
+ BSON_ASSERT(in->data);
501
+ bool ret = false;
502
+
503
+ BSON_ASSERT((in->data[0] == MC_SUBTYPE_FLE2IndexedEqualityEncryptedValueV2)
504
+ || (in->data[0] == MC_SUBTYPE_FLE2IndexedRangeEncryptedValueV2));
505
+
506
+ mc_FLE2IndexedEncryptedValueV2_t *iev = mc_FLE2IndexedEncryptedValueV2_new();
507
+ CHECK_AND_RETURN(iev);
508
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValueV2_parse(iev, in, status));
509
+
510
+ const _mongocrypt_buffer_t *S_KeyId = mc_FLE2IndexedEncryptedValueV2_get_S_KeyId(iev, status);
511
+ CHECK_AND_RETURN(S_KeyId);
512
+
513
+ _mongocrypt_key_broker_t *kb = ctx;
514
+ _mongocrypt_buffer_t S_Key = {0};
515
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, S_KeyId, &S_Key));
516
+
517
+ /* Decrypt InnerEncrypted to get K_KeyId. */
518
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValueV2_add_S_Key(kb->crypt->crypto, iev, &S_Key, status));
519
+
520
+ /* Add request for K_KeyId. */
521
+ const _mongocrypt_buffer_t *K_KeyId = mc_FLE2IndexedEncryptedValueV2_get_K_KeyId(iev, status);
522
+ CHECK_AND_RETURN(K_KeyId);
523
+
524
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_request_id(kb, K_KeyId));
525
+
526
+ ret = true;
450
527
  fail:
451
- _mongocrypt_buffer_cleanup (&S_Key);
452
- mc_FLE2IndexedEncryptedValue_destroy (iev);
453
- return ret;
528
+ _mongocrypt_buffer_cleanup(&S_Key);
529
+ mc_FLE2IndexedEncryptedValueV2_destroy(iev);
530
+ return ret;
454
531
  }
455
532
 
533
+ static bool _collect_K_KeyID_from_FLE2IndexedEncryptedValue(void *ctx,
534
+ const _mongocrypt_buffer_t *in,
535
+ mongocrypt_status_t *status) {
536
+ BSON_ASSERT_PARAM(ctx);
537
+ BSON_ASSERT_PARAM(in);
538
+ BSON_ASSERT(in->data);
539
+ bool ret = false;
540
+
541
+ BSON_ASSERT((in->data[0] == MC_SUBTYPE_FLE2IndexedEqualityEncryptedValue)
542
+ || (in->data[0] == MC_SUBTYPE_FLE2IndexedRangeEncryptedValue));
543
+
544
+ mc_FLE2IndexedEncryptedValue_t *iev = mc_FLE2IndexedEncryptedValue_new();
545
+ CHECK_AND_RETURN(iev);
546
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValue_parse(iev, in, status));
547
+
548
+ const _mongocrypt_buffer_t *S_KeyId = mc_FLE2IndexedEncryptedValue_get_S_KeyId(iev, status);
549
+ CHECK_AND_RETURN(S_KeyId);
550
+
551
+ _mongocrypt_key_broker_t *kb = ctx;
552
+ _mongocrypt_buffer_t S_Key = {0};
553
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_decrypted_key_by_id(kb, S_KeyId, &S_Key));
554
+
555
+ /* Decrypt InnerEncrypted to get K_KeyId. */
556
+ CHECK_AND_RETURN(mc_FLE2IndexedEncryptedValue_add_S_Key(kb->crypt->crypto, iev, &S_Key, status));
557
+
558
+ /* Add request for K_KeyId. */
559
+ const _mongocrypt_buffer_t *K_KeyId = mc_FLE2IndexedEncryptedValue_get_K_KeyId(iev, status);
560
+ CHECK_AND_RETURN(K_KeyId);
561
+
562
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_request_id(kb, K_KeyId));
563
+
564
+ ret = true;
565
+ fail:
566
+ _mongocrypt_buffer_cleanup(&S_Key);
567
+ mc_FLE2IndexedEncryptedValue_destroy(iev);
568
+ return ret;
569
+ }
570
+
571
+ static bool _collect_K_KeyIDs(void *ctx, _mongocrypt_buffer_t *in, mongocrypt_status_t *status) {
572
+ BSON_ASSERT_PARAM(in);
573
+ BSON_ASSERT(in->data);
574
+
575
+ switch (in->data[0]) {
576
+ // FLE2v2
577
+ case MC_SUBTYPE_FLE2IndexedEqualityEncryptedValueV2:
578
+ case MC_SUBTYPE_FLE2IndexedRangeEncryptedValueV2:
579
+ return _collect_K_KeyID_from_FLE2IndexedEncryptedValueV2(ctx, in, status);
580
+
581
+ // FLE2v1
582
+ case MC_SUBTYPE_FLE2IndexedEqualityEncryptedValue:
583
+ case MC_SUBTYPE_FLE2IndexedRangeEncryptedValue:
584
+ return _collect_K_KeyID_from_FLE2IndexedEncryptedValue(ctx, in, status);
585
+
586
+ default:
587
+ // Ignore other types.
588
+ return true;
589
+ }
590
+ }
456
591
 
457
592
  /* _check_for_K_KeyId must be called after requests for all S_KeyId are
458
593
  * satisfied. */
459
- static bool
460
- _check_for_K_KeyId (mongocrypt_ctx_t *ctx)
461
- {
462
- BSON_ASSERT_PARAM (ctx);
463
-
464
- if (ctx->kb.state != KB_DONE) {
465
- return true;
466
- }
467
-
468
- if (!_mongocrypt_key_broker_restart (&ctx->kb)) {
469
- _mongocrypt_key_broker_status (&ctx->kb, ctx->status);
470
- return _mongocrypt_ctx_fail (ctx);
471
- }
472
-
473
- bson_t as_bson;
474
- bson_iter_t iter;
475
- _mongocrypt_ctx_decrypt_t *dctx = (_mongocrypt_ctx_decrypt_t *) ctx;
476
- if (!_mongocrypt_buffer_to_bson (&dctx->original_doc, &as_bson)) {
477
- return _mongocrypt_ctx_fail_w_msg (
478
- ctx, "error converting original_doc to bson");
479
- }
480
- bson_iter_init (&iter, &as_bson);
481
-
482
- if (!_mongocrypt_traverse_binary_in_bson (
483
- _collect_K_KeyID_from_FLE2IndexedEncryptedValue,
484
- &ctx->kb,
485
- TRAVERSE_MATCH_CIPHERTEXT,
486
- &iter,
487
- ctx->status)) {
488
- return _mongocrypt_ctx_fail (ctx);
489
- }
490
-
491
- if (!_mongocrypt_key_broker_requests_done (&ctx->kb)) {
492
- _mongocrypt_key_broker_status (&ctx->kb, ctx->status);
493
- return _mongocrypt_ctx_fail (ctx);
494
- }
495
- return true;
594
+ static bool _check_for_K_KeyId(mongocrypt_ctx_t *ctx) {
595
+ BSON_ASSERT_PARAM(ctx);
596
+
597
+ if (ctx->kb.state != KB_DONE) {
598
+ return true;
599
+ }
600
+
601
+ if (!_mongocrypt_key_broker_restart(&ctx->kb)) {
602
+ _mongocrypt_key_broker_status(&ctx->kb, ctx->status);
603
+ return _mongocrypt_ctx_fail(ctx);
604
+ }
605
+
606
+ bson_t as_bson;
607
+ bson_iter_t iter;
608
+ _mongocrypt_ctx_decrypt_t *dctx = (_mongocrypt_ctx_decrypt_t *)ctx;
609
+ if (!_mongocrypt_buffer_to_bson(&dctx->original_doc, &as_bson)) {
610
+ return _mongocrypt_ctx_fail_w_msg(ctx, "error converting original_doc to bson");
611
+ }
612
+ bson_iter_init(&iter, &as_bson);
613
+
614
+ if (!_mongocrypt_traverse_binary_in_bson(_collect_K_KeyIDs,
615
+ &ctx->kb,
616
+ TRAVERSE_MATCH_CIPHERTEXT,
617
+ &iter,
618
+ ctx->status)) {
619
+ return _mongocrypt_ctx_fail(ctx);
620
+ }
621
+
622
+ if (!_mongocrypt_key_broker_requests_done(&ctx->kb)) {
623
+ _mongocrypt_key_broker_status(&ctx->kb, ctx->status);
624
+ return _mongocrypt_ctx_fail(ctx);
625
+ }
626
+ return true;
496
627
  }
497
628
 
498
- static bool
499
- _collect_key_uuid_from_FLE2UnindexedEncryptedValue (void *ctx,
500
- _mongocrypt_buffer_t *in,
501
- mongocrypt_status_t *status)
502
- {
503
- bool ret = false;
504
- _mongocrypt_key_broker_t *kb = ctx;
505
- mc_FLE2UnindexedEncryptedValue_t *uev;
506
-
507
- BSON_ASSERT_PARAM (ctx);
508
- BSON_ASSERT_PARAM (in);
509
-
510
- uev = mc_FLE2UnindexedEncryptedValue_new ();
511
-
512
- if (!mc_FLE2UnindexedEncryptedValue_parse (uev, in, status)) {
513
- goto fail;
514
- }
515
-
516
- const _mongocrypt_buffer_t *key_uuid =
517
- mc_FLE2UnindexedEncryptedValue_get_key_uuid (uev, status);
518
- if (!key_uuid) {
519
- goto fail;
520
- }
521
-
522
- if (!_mongocrypt_key_broker_request_id (kb, key_uuid)) {
523
- _mongocrypt_key_broker_status (kb, status);
524
- goto fail;
525
- }
526
-
527
- ret = true;
629
+ static bool _collect_key_uuid_from_FLE2UnindexedEncryptedValue(void *ctx,
630
+ const _mongocrypt_buffer_t *in,
631
+ mongocrypt_status_t *status) {
632
+ BSON_ASSERT_PARAM(ctx);
633
+ BSON_ASSERT_PARAM(in);
634
+ bool ret = false;
635
+
636
+ mc_FLE2UnindexedEncryptedValue_t *uev = mc_FLE2UnindexedEncryptedValue_new();
637
+ CHECK_AND_RETURN(uev);
638
+ CHECK_AND_RETURN(mc_FLE2UnindexedEncryptedValue_parse(uev, in, status));
639
+
640
+ const _mongocrypt_buffer_t *key_uuid = mc_FLE2UnindexedEncryptedValue_get_key_uuid(uev, status);
641
+ CHECK_AND_RETURN(key_uuid);
642
+ _mongocrypt_key_broker_t *kb = ctx;
643
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_request_id(kb, key_uuid));
644
+
645
+ ret = true;
528
646
  fail:
529
- mc_FLE2UnindexedEncryptedValue_destroy (uev);
530
- return ret;
647
+ mc_FLE2UnindexedEncryptedValue_destroy(uev);
648
+ return ret;
531
649
  }
532
650
 
533
- static bool
534
- _collect_key_uuid_from_FLE2InsertUpdatePayload (void *ctx,
535
- _mongocrypt_buffer_t *in,
536
- mongocrypt_status_t *status)
537
- {
538
- bool ret = false;
539
- _mongocrypt_key_broker_t *kb = ctx;
540
- mc_FLE2InsertUpdatePayload_t iup;
651
+ static bool _collect_key_uuid_from_FLE2UnindexedEncryptedValueV2(void *ctx,
652
+ const _mongocrypt_buffer_t *in,
653
+ mongocrypt_status_t *status) {
654
+ bool ret = false;
655
+ BSON_ASSERT_PARAM(ctx);
656
+ BSON_ASSERT_PARAM(in);
657
+
658
+ mc_FLE2UnindexedEncryptedValueV2_t *uev = mc_FLE2UnindexedEncryptedValueV2_new();
659
+ CHECK_AND_RETURN(uev);
660
+ CHECK_AND_RETURN(mc_FLE2UnindexedEncryptedValueV2_parse(uev, in, status));
541
661
 
542
- BSON_ASSERT_PARAM (ctx);
543
- BSON_ASSERT_PARAM (in);
662
+ const _mongocrypt_buffer_t *key_uuid = mc_FLE2UnindexedEncryptedValueV2_get_key_uuid(uev, status);
663
+ CHECK_AND_RETURN(key_uuid);
664
+ _mongocrypt_key_broker_t *kb = ctx;
665
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_request_id(kb, key_uuid));
544
666
 
545
- mc_FLE2InsertUpdatePayload_init (&iup);
667
+ ret = true;
668
+ fail:
669
+ mc_FLE2UnindexedEncryptedValueV2_destroy(uev);
670
+ return ret;
671
+ }
672
+
673
+ static bool
674
+ _collect_key_uuid_from_FLE2InsertUpdatePayload(void *ctx, const _mongocrypt_buffer_t *in, mongocrypt_status_t *status) {
675
+ BSON_ASSERT_PARAM(ctx);
676
+ BSON_ASSERT_PARAM(in);
677
+ bool ret = false;
546
678
 
547
- if (!mc_FLE2InsertUpdatePayload_parse (&iup, in, status)) {
548
- goto fail;
549
- }
679
+ mc_FLE2InsertUpdatePayload_t iup;
680
+ mc_FLE2InsertUpdatePayload_init(&iup);
550
681
 
551
- if (!_mongocrypt_key_broker_request_id (kb, &iup.userKeyId)) {
552
- _mongocrypt_key_broker_status (kb, status);
553
- goto fail;
554
- }
682
+ CHECK_AND_RETURN(mc_FLE2InsertUpdatePayload_parse(&iup, in, status));
683
+ _mongocrypt_key_broker_t *kb = ctx;
684
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_request_id(kb, &iup.userKeyId));
555
685
 
556
- ret = true;
686
+ ret = true;
557
687
  fail:
558
- mc_FLE2InsertUpdatePayload_cleanup (&iup);
559
- return ret;
688
+ mc_FLE2InsertUpdatePayload_cleanup(&iup);
689
+ return ret;
560
690
  }
561
691
 
562
- static bool
563
- _collect_key_from_ciphertext (void *ctx,
564
- _mongocrypt_buffer_t *in,
565
- mongocrypt_status_t *status)
566
- {
567
- _mongocrypt_ciphertext_t ciphertext;
568
- _mongocrypt_key_broker_t *kb;
569
-
570
- BSON_ASSERT_PARAM (ctx);
571
- BSON_ASSERT_PARAM (in);
572
- BSON_ASSERT (in->data);
573
-
574
- kb = (_mongocrypt_key_broker_t *) ctx;
575
-
576
- if (in->data[0] == MC_SUBTYPE_FLE2IndexedEqualityEncryptedValue ||
577
- in->data[0] == MC_SUBTYPE_FLE2IndexedRangeEncryptedValue) {
578
- return _collect_S_KeyID_from_FLE2IndexedEncryptedValue (ctx, in, status);
579
- }
580
-
581
- if (in->data[0] == MC_SUBTYPE_FLE2UnindexedEncryptedValue) {
582
- return _collect_key_uuid_from_FLE2UnindexedEncryptedValue (
583
- ctx, in, status);
584
- }
585
-
586
- if (in->data[0] == MC_SUBTYPE_FLE2InsertUpdatePayload) {
587
- return _collect_key_uuid_from_FLE2InsertUpdatePayload (ctx, in, status);
588
- }
589
-
590
- if (!_mongocrypt_ciphertext_parse_unowned (in, &ciphertext, status)) {
591
- return false;
592
- }
593
-
594
- if (!_mongocrypt_key_broker_request_id (kb, &ciphertext.key_id)) {
595
- return _mongocrypt_key_broker_status (kb, status);
596
- }
597
-
598
- return true;
692
+ static bool _collect_key_uuid_from_FLE2InsertUpdatePayloadV2(void *ctx,
693
+ const _mongocrypt_buffer_t *in,
694
+ mongocrypt_status_t *status) {
695
+ BSON_ASSERT_PARAM(ctx);
696
+ BSON_ASSERT_PARAM(in);
697
+ bool ret = false;
698
+
699
+ mc_FLE2InsertUpdatePayloadV2_t iup;
700
+ mc_FLE2InsertUpdatePayloadV2_init(&iup);
701
+
702
+ CHECK_AND_RETURN(mc_FLE2InsertUpdatePayloadV2_parse(&iup, in, status));
703
+ _mongocrypt_key_broker_t *kb = ctx;
704
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_request_id(kb, &iup.userKeyId));
705
+
706
+ ret = true;
707
+ fail:
708
+ mc_FLE2InsertUpdatePayloadV2_cleanup(&iup);
709
+ return ret;
599
710
  }
600
711
 
712
+ static bool _collect_key_uuid_from_FLE1(void *ctx, _mongocrypt_buffer_t *in, mongocrypt_status_t *status) {
713
+ _mongocrypt_ciphertext_t ciphertext;
714
+ _mongocrypt_key_broker_t *kb = (_mongocrypt_key_broker_t *)ctx;
601
715
 
602
- static void
603
- _cleanup (mongocrypt_ctx_t *ctx)
604
- {
605
- _mongocrypt_ctx_decrypt_t *dctx;
716
+ CHECK_AND_RETURN(_mongocrypt_ciphertext_parse_unowned(in, &ciphertext, status));
717
+ CHECK_AND_RETURN_KB_STATUS(_mongocrypt_key_broker_request_id(kb, &ciphertext.key_id));
606
718
 
607
- if (!ctx) {
608
- return;
609
- }
610
- dctx = (_mongocrypt_ctx_decrypt_t *) ctx;
611
- _mongocrypt_buffer_cleanup (&dctx->original_doc);
612
- _mongocrypt_buffer_cleanup (&dctx->decrypted_doc);
719
+ return true;
720
+ fail:
721
+ return false;
613
722
  }
614
723
 
724
+ static bool _collect_key_from_ciphertext(void *ctx, _mongocrypt_buffer_t *in, mongocrypt_status_t *status) {
725
+ BSON_ASSERT_PARAM(ctx);
726
+ BSON_ASSERT_PARAM(in);
727
+ BSON_ASSERT(in->data);
728
+
729
+ switch (in->data[0]) {
730
+ // FLE2v2
731
+ case MC_SUBTYPE_FLE2IndexedEqualityEncryptedValueV2:
732
+ case MC_SUBTYPE_FLE2IndexedRangeEncryptedValueV2:
733
+ return _collect_S_KeyID_from_FLE2IndexedEncryptedValueV2(ctx, in, status);
734
+ case MC_SUBTYPE_FLE2UnindexedEncryptedValueV2:
735
+ return _collect_key_uuid_from_FLE2UnindexedEncryptedValueV2(ctx, in, status);
736
+ case MC_SUBTYPE_FLE2InsertUpdatePayloadV2: return _collect_key_uuid_from_FLE2InsertUpdatePayloadV2(ctx, in, status);
737
+
738
+ // FLE2v1
739
+ case MC_SUBTYPE_FLE2IndexedEqualityEncryptedValue:
740
+ case MC_SUBTYPE_FLE2IndexedRangeEncryptedValue:
741
+ return _collect_S_KeyID_from_FLE2IndexedEncryptedValue(ctx, in, status);
742
+ case MC_SUBTYPE_FLE2UnindexedEncryptedValue:
743
+ return _collect_key_uuid_from_FLE2UnindexedEncryptedValue(ctx, in, status);
744
+ case MC_SUBTYPE_FLE2InsertUpdatePayload: return _collect_key_uuid_from_FLE2InsertUpdatePayload(ctx, in, status);
745
+
746
+ // FLE1
747
+ default: return _collect_key_uuid_from_FLE1(ctx, in, status);
748
+ }
749
+ }
615
750
 
616
- bool
617
- mongocrypt_ctx_explicit_decrypt_init (mongocrypt_ctx_t *ctx,
618
- mongocrypt_binary_t *msg)
619
- {
620
- bson_iter_t iter;
621
- bson_t as_bson;
622
-
623
- if (!ctx) {
624
- return false;
625
- }
626
-
627
- if (!msg || !msg->data) {
628
- return _mongocrypt_ctx_fail_w_msg (ctx, "invalid msg");
629
- }
630
-
631
- if (ctx->crypt->log.trace_enabled) {
632
- char *msg_val;
633
- msg_val = _mongocrypt_new_json_string_from_binary (msg);
634
- _mongocrypt_log (&ctx->crypt->log,
635
- MONGOCRYPT_LOG_LEVEL_TRACE,
636
- "%s (%s=\"%s\")",
637
- BSON_FUNC,
638
- "msg",
639
- msg_val);
640
-
641
- bson_free (msg_val);
642
- }
643
-
644
- /* Expect msg to be the BSON a document of the form:
645
- { "v" : (BSON BINARY value of subtype 6) }
646
- */
647
- if (!_mongocrypt_binary_to_bson (msg, &as_bson)) {
648
- return _mongocrypt_ctx_fail_w_msg (ctx, "malformed bson");
649
- }
650
-
651
- if (!bson_iter_init_find (&iter, &as_bson, "v")) {
652
- return _mongocrypt_ctx_fail_w_msg (ctx, "invalid msg, must contain 'v'");
653
- }
654
-
655
- if (!BSON_ITER_HOLDS_BINARY (&iter)) {
656
- return _mongocrypt_ctx_fail_w_msg (
657
- ctx, "invalid msg, 'v' must contain a binary");
658
- }
659
-
660
- {
661
- bson_subtype_t subtype;
662
- const uint8_t *binary;
663
- uint32_t binary_len;
664
- mongocrypt_status_t *status = ctx->status;
665
-
666
- bson_iter_binary (&iter, &subtype, &binary_len, &binary);
667
- if (subtype != BSON_SUBTYPE_ENCRYPTED) {
668
- CLIENT_ERR ("decryption expected BSON binary subtype %d, got %d",
669
- (int) BSON_SUBTYPE_ENCRYPTED,
670
- (int) subtype);
671
- return _mongocrypt_ctx_fail (ctx);
672
- }
673
- }
674
-
675
-
676
- if (!mongocrypt_ctx_decrypt_init (ctx, msg)) {
677
- return false;
678
- }
679
- return true;
751
+ static void _cleanup(mongocrypt_ctx_t *ctx) {
752
+ _mongocrypt_ctx_decrypt_t *dctx;
753
+
754
+ if (!ctx) {
755
+ return;
756
+ }
757
+ dctx = (_mongocrypt_ctx_decrypt_t *)ctx;
758
+ _mongocrypt_buffer_cleanup(&dctx->original_doc);
759
+ _mongocrypt_buffer_cleanup(&dctx->decrypted_doc);
680
760
  }
681
761
 
682
- static bool
683
- _mongo_done_keys (mongocrypt_ctx_t *ctx)
684
- {
685
- BSON_ASSERT_PARAM (ctx);
686
-
687
- (void) _mongocrypt_key_broker_docs_done (&ctx->kb);
688
- if (!_check_for_K_KeyId (ctx)) {
689
- return false;
690
- }
691
- return _mongocrypt_ctx_state_from_key_broker (ctx);
762
+ bool mongocrypt_ctx_explicit_decrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *msg) {
763
+ bson_iter_t iter;
764
+ bson_t as_bson;
765
+
766
+ if (!ctx) {
767
+ return false;
768
+ }
769
+
770
+ if (!msg || !msg->data) {
771
+ return _mongocrypt_ctx_fail_w_msg(ctx, "invalid msg");
772
+ }
773
+
774
+ if (ctx->crypt->log.trace_enabled) {
775
+ char *msg_val;
776
+ msg_val = _mongocrypt_new_json_string_from_binary(msg);
777
+ _mongocrypt_log(&ctx->crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "msg", msg_val);
778
+
779
+ bson_free(msg_val);
780
+ }
781
+
782
+ /* Expect msg to be the BSON a document of the form:
783
+ { "v" : (BSON BINARY value of subtype 6) }
784
+ */
785
+ if (!_mongocrypt_binary_to_bson(msg, &as_bson)) {
786
+ return _mongocrypt_ctx_fail_w_msg(ctx, "malformed bson");
787
+ }
788
+
789
+ if (!bson_iter_init_find(&iter, &as_bson, "v")) {
790
+ return _mongocrypt_ctx_fail_w_msg(ctx, "invalid msg, must contain 'v'");
791
+ }
792
+
793
+ if (!BSON_ITER_HOLDS_BINARY(&iter)) {
794
+ return _mongocrypt_ctx_fail_w_msg(ctx, "invalid msg, 'v' must contain a binary");
795
+ }
796
+
797
+ {
798
+ bson_subtype_t subtype;
799
+ const uint8_t *binary;
800
+ uint32_t binary_len;
801
+ mongocrypt_status_t *status = ctx->status;
802
+
803
+ bson_iter_binary(&iter, &subtype, &binary_len, &binary);
804
+ if (subtype != BSON_SUBTYPE_ENCRYPTED) {
805
+ CLIENT_ERR("decryption expected BSON binary subtype %d, got %d", (int)BSON_SUBTYPE_ENCRYPTED, (int)subtype);
806
+ return _mongocrypt_ctx_fail(ctx);
807
+ }
808
+ }
809
+
810
+ if (!mongocrypt_ctx_decrypt_init(ctx, msg)) {
811
+ return false;
812
+ }
813
+ return true;
692
814
  }
693
815
 
694
- static bool
695
- _kms_done (mongocrypt_ctx_t *ctx)
696
- {
697
- _mongocrypt_opts_kms_providers_t *kms_providers;
698
-
699
- BSON_ASSERT_PARAM (ctx);
700
-
701
- kms_providers = _mongocrypt_ctx_kms_providers (ctx);
702
-
703
- if (!_mongocrypt_key_broker_kms_done (&ctx->kb, kms_providers)) {
704
- BSON_ASSERT (!_mongocrypt_key_broker_status (&ctx->kb, ctx->status));
705
- return _mongocrypt_ctx_fail (ctx);
706
- }
707
- if (!_check_for_K_KeyId (ctx)) {
708
- return false;
709
- }
710
- return _mongocrypt_ctx_state_from_key_broker (ctx);
816
+ static bool _mongo_done_keys(mongocrypt_ctx_t *ctx) {
817
+ BSON_ASSERT_PARAM(ctx);
818
+
819
+ (void)_mongocrypt_key_broker_docs_done(&ctx->kb);
820
+ if (!_check_for_K_KeyId(ctx)) {
821
+ return false;
822
+ }
823
+ return _mongocrypt_ctx_state_from_key_broker(ctx);
824
+ }
825
+
826
+ static bool _kms_done(mongocrypt_ctx_t *ctx) {
827
+ _mongocrypt_opts_kms_providers_t *kms_providers;
828
+
829
+ BSON_ASSERT_PARAM(ctx);
830
+
831
+ kms_providers = _mongocrypt_ctx_kms_providers(ctx);
832
+
833
+ if (!_mongocrypt_key_broker_kms_done(&ctx->kb, kms_providers)) {
834
+ BSON_ASSERT(!_mongocrypt_key_broker_status(&ctx->kb, ctx->status));
835
+ return _mongocrypt_ctx_fail(ctx);
836
+ }
837
+ if (!_check_for_K_KeyId(ctx)) {
838
+ return false;
839
+ }
840
+ return _mongocrypt_ctx_state_from_key_broker(ctx);
711
841
  }
712
842
 
713
- bool
714
- mongocrypt_ctx_decrypt_init (mongocrypt_ctx_t *ctx, mongocrypt_binary_t *doc)
715
- {
716
- _mongocrypt_ctx_decrypt_t *dctx;
717
- bson_t as_bson;
718
- bson_iter_t iter;
719
- _mongocrypt_ctx_opts_spec_t opts_spec;
720
-
721
- memset (&opts_spec, 0, sizeof (opts_spec));
722
- if (!ctx) {
723
- return false;
724
- }
725
-
726
- if (!_mongocrypt_ctx_init (ctx, &opts_spec)) {
727
- return false;
728
- }
729
-
730
- if (!doc || !doc->data) {
731
- return _mongocrypt_ctx_fail_w_msg (ctx, "invalid doc");
732
- }
733
-
734
- if (ctx->crypt->log.trace_enabled) {
735
- char *doc_val;
736
- doc_val = _mongocrypt_new_json_string_from_binary (doc);
737
- _mongocrypt_log (&ctx->crypt->log,
738
- MONGOCRYPT_LOG_LEVEL_TRACE,
739
- "%s (%s=\"%s\")",
740
- BSON_FUNC,
741
- "doc",
742
- doc_val);
743
- bson_free (doc_val);
744
- }
745
- dctx = (_mongocrypt_ctx_decrypt_t *) ctx;
746
- ctx->type = _MONGOCRYPT_TYPE_DECRYPT;
747
- ctx->vtable.finalize = _finalize;
748
- ctx->vtable.cleanup = _cleanup;
749
- ctx->vtable.mongo_done_keys = _mongo_done_keys;
750
- ctx->vtable.kms_done = _kms_done;
751
-
752
- _mongocrypt_buffer_copy_from_binary (&dctx->original_doc, doc);
753
- /* get keys. */
754
- if (!_mongocrypt_buffer_to_bson (&dctx->original_doc, &as_bson)) {
755
- return _mongocrypt_ctx_fail_w_msg (ctx, "malformed bson");
756
- }
757
-
758
- bson_iter_init (&iter, &as_bson);
759
- if (!_mongocrypt_traverse_binary_in_bson (_collect_key_from_ciphertext,
843
+ bool mongocrypt_ctx_decrypt_init(mongocrypt_ctx_t *ctx, mongocrypt_binary_t *doc) {
844
+ _mongocrypt_ctx_decrypt_t *dctx;
845
+ bson_t as_bson;
846
+ bson_iter_t iter;
847
+ _mongocrypt_ctx_opts_spec_t opts_spec;
848
+
849
+ memset(&opts_spec, 0, sizeof(opts_spec));
850
+ if (!ctx) {
851
+ return false;
852
+ }
853
+
854
+ if (!_mongocrypt_ctx_init(ctx, &opts_spec)) {
855
+ return false;
856
+ }
857
+
858
+ if (!doc || !doc->data) {
859
+ return _mongocrypt_ctx_fail_w_msg(ctx, "invalid doc");
860
+ }
861
+
862
+ if (ctx->crypt->log.trace_enabled) {
863
+ char *doc_val;
864
+ doc_val = _mongocrypt_new_json_string_from_binary(doc);
865
+ _mongocrypt_log(&ctx->crypt->log, MONGOCRYPT_LOG_LEVEL_TRACE, "%s (%s=\"%s\")", BSON_FUNC, "doc", doc_val);
866
+ bson_free(doc_val);
867
+ }
868
+ dctx = (_mongocrypt_ctx_decrypt_t *)ctx;
869
+ ctx->type = _MONGOCRYPT_TYPE_DECRYPT;
870
+ ctx->vtable.finalize = _finalize;
871
+ ctx->vtable.cleanup = _cleanup;
872
+ ctx->vtable.mongo_done_keys = _mongo_done_keys;
873
+ ctx->vtable.kms_done = _kms_done;
874
+
875
+ _mongocrypt_buffer_copy_from_binary(&dctx->original_doc, doc);
876
+ /* get keys. */
877
+ if (!_mongocrypt_buffer_to_bson(&dctx->original_doc, &as_bson)) {
878
+ return _mongocrypt_ctx_fail_w_msg(ctx, "malformed bson");
879
+ }
880
+
881
+ bson_iter_init(&iter, &as_bson);
882
+ if (!_mongocrypt_traverse_binary_in_bson(_collect_key_from_ciphertext,
760
883
  &ctx->kb,
761
884
  TRAVERSE_MATCH_CIPHERTEXT,
762
885
  &iter,
763
886
  ctx->status)) {
764
- return _mongocrypt_ctx_fail (ctx);
765
- }
887
+ return _mongocrypt_ctx_fail(ctx);
888
+ }
766
889
 
767
- (void) _mongocrypt_key_broker_requests_done (&ctx->kb);
890
+ (void)_mongocrypt_key_broker_requests_done(&ctx->kb);
768
891
 
769
- if (!_check_for_K_KeyId (ctx)) {
770
- return false;
771
- }
772
- return _mongocrypt_ctx_state_from_key_broker (ctx);
892
+ if (!_check_for_K_KeyId(ctx)) {
893
+ return false;
894
+ }
895
+ return _mongocrypt_ctx_state_from_key_broker(ctx);
773
896
  }