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
@@ -18,132 +18,90 @@
18
18
 
19
19
  /* Utilities for integration tests and example runners. */
20
20
 
21
- #include <mongoc/mongoc.h>
22
21
  #include "mongocrypt.h"
22
+ #include <mongoc/mongoc.h>
23
+
24
+ static void _errexit_status(mongocrypt_status_t *status, int line) {
25
+ int code;
26
+ const char *msg;
27
+
28
+ code = mongocrypt_status_code(status);
29
+ msg = mongocrypt_status_message(status, NULL);
30
+ MONGOC_ERROR("Error at line %d with code %d and msg: %s", line, code, msg);
31
+ exit(1);
32
+ }
33
+
34
+ void _errexit_mongocrypt(mongocrypt_t *crypt, int line) {
35
+ mongocrypt_status_t *status;
36
+
37
+ status = mongocrypt_status_new();
38
+ mongocrypt_status(crypt, status);
39
+ _errexit_status(status, line);
40
+ mongocrypt_status_destroy(status);
41
+ }
42
+
43
+ void _errexit_ctx(mongocrypt_ctx_t *ctx, int line) {
44
+ mongocrypt_status_t *status;
45
+
46
+ status = mongocrypt_status_new();
47
+ mongocrypt_ctx_status(ctx, status);
48
+ _errexit_status(status, line);
49
+ mongocrypt_status_destroy(status);
50
+ }
51
+
52
+ void _errexit_bson(bson_error_t *error, int line) {
53
+ MONGOC_ERROR("Error at line %d with code %d and msg: %s", line, error->code, error->message);
54
+ exit(1);
55
+ }
56
+
57
+ void _log_to_stdout(mongocrypt_log_level_t level, const char *message, uint32_t message_len, void *ctx) {
58
+ switch (level) {
59
+ case MONGOCRYPT_LOG_LEVEL_FATAL: printf("FATAL"); break;
60
+ case MONGOCRYPT_LOG_LEVEL_ERROR: printf("ERROR"); break;
61
+ case MONGOCRYPT_LOG_LEVEL_WARNING: printf("WARNING"); break;
62
+ case MONGOCRYPT_LOG_LEVEL_INFO: printf("INFO"); break;
63
+ case MONGOCRYPT_LOG_LEVEL_TRACE: printf("TRACE"); break;
64
+ default: printf("?????"); break;
65
+ }
66
+ printf(" %s\n", message);
67
+ }
23
68
 
24
- static void
25
- _errexit_status (mongocrypt_status_t *status, int line)
26
- {
27
- int code;
28
- const char *msg;
29
-
30
- code = mongocrypt_status_code (status);
31
- msg = mongocrypt_status_message (status, NULL);
32
- MONGOC_ERROR ("Error at line %d with code %d and msg: %s", line, code, msg);
33
- exit (1);
34
- }
35
-
36
- void
37
- _errexit_mongocrypt (mongocrypt_t *crypt, int line)
38
- {
39
- mongocrypt_status_t *status;
40
-
41
- status = mongocrypt_status_new ();
42
- mongocrypt_status (crypt, status);
43
- _errexit_status (status, line);
44
- mongocrypt_status_destroy (status);
45
- }
46
-
47
- void
48
- _errexit_ctx (mongocrypt_ctx_t *ctx, int line)
49
- {
50
- mongocrypt_status_t *status;
51
-
52
- status = mongocrypt_status_new ();
53
- mongocrypt_ctx_status (ctx, status);
54
- _errexit_status (status, line);
55
- mongocrypt_status_destroy (status);
56
- }
57
-
58
- void
59
- _errexit_bson (bson_error_t *error, int line)
60
- {
61
- MONGOC_ERROR ("Error at line %d with code %d and msg: %s",
62
- line,
63
- error->code,
64
- error->message);
65
- exit (1);
66
- }
67
-
68
- void
69
- _log_to_stdout (mongocrypt_log_level_t level,
70
- const char *message,
71
- uint32_t message_len,
72
- void *ctx)
73
- {
74
- switch (level) {
75
- case MONGOCRYPT_LOG_LEVEL_FATAL:
76
- printf ("FATAL");
77
- break;
78
- case MONGOCRYPT_LOG_LEVEL_ERROR:
79
- printf ("ERROR");
80
- break;
81
- case MONGOCRYPT_LOG_LEVEL_WARNING:
82
- printf ("WARNING");
83
- break;
84
- case MONGOCRYPT_LOG_LEVEL_INFO:
85
- printf ("INFO");
86
- break;
87
- case MONGOCRYPT_LOG_LEVEL_TRACE:
88
- printf ("TRACE");
89
- break;
90
- default:
91
- printf ("?????");
92
- break;
93
- }
94
- printf (" %s\n", message);
95
- }
96
-
97
- char *
98
- util_getenv (const char *key)
99
- {
100
- char *value = getenv (key);
101
- if (!value) {
102
- MONGOC_ERROR ("Environment variable: %s not set", key);
103
- }
104
- return value;
105
- }
106
-
107
- mongocrypt_binary_t *
108
- util_bson_to_bin (bson_t *bson)
109
- {
110
- return mongocrypt_binary_new_from_data ((uint8_t *) bson_get_data (bson),
111
- bson->len);
112
- }
113
-
114
- bson_t *
115
- util_bin_to_bson (mongocrypt_binary_t *bin)
116
- {
117
- return bson_new_from_data (mongocrypt_binary_data (bin),
118
- mongocrypt_binary_len (bin));
119
- }
120
-
121
- static void
122
- _prefix_mongocryptd_error (bson_error_t *error)
123
- {
124
- char buf[sizeof (error->message)];
125
-
126
- bson_snprintf (buf, sizeof (buf), "mongocryptd error: %s:", error->message);
127
- memcpy (error->message, buf, sizeof (buf));
128
- }
129
-
130
- static void
131
- _prefix_keyvault_error (bson_error_t *error)
132
- {
133
- char buf[sizeof (error->message)];
134
-
135
- bson_snprintf (buf, sizeof (buf), "key vault error: %s:", error->message);
136
- memcpy (error->message, buf, sizeof (buf));
137
- }
138
-
139
- static void
140
- _status_to_error (mongocrypt_status_t *status, bson_error_t *error)
141
- {
142
- bson_set_error (error,
69
+ char *util_getenv(const char *key) {
70
+ char *value = getenv(key);
71
+ if (!value) {
72
+ MONGOC_ERROR("Environment variable: %s not set", key);
73
+ }
74
+ return value;
75
+ }
76
+
77
+ mongocrypt_binary_t *util_bson_to_bin(bson_t *bson) {
78
+ return mongocrypt_binary_new_from_data((uint8_t *)bson_get_data(bson), bson->len);
79
+ }
80
+
81
+ bson_t *util_bin_to_bson(mongocrypt_binary_t *bin) {
82
+ return bson_new_from_data(mongocrypt_binary_data(bin), mongocrypt_binary_len(bin));
83
+ }
84
+
85
+ static void _prefix_mongocryptd_error(bson_error_t *error) {
86
+ char buf[sizeof(error->message)];
87
+
88
+ bson_snprintf(buf, sizeof(buf), "mongocryptd error: %s:", error->message);
89
+ memcpy(error->message, buf, sizeof(buf));
90
+ }
91
+
92
+ static void _prefix_keyvault_error(bson_error_t *error) {
93
+ char buf[sizeof(error->message)];
94
+
95
+ bson_snprintf(buf, sizeof(buf), "key vault error: %s:", error->message);
96
+ memcpy(error->message, buf, sizeof(buf));
97
+ }
98
+
99
+ static void _status_to_error(mongocrypt_status_t *status, bson_error_t *error) {
100
+ bson_set_error(error,
143
101
  MONGOC_ERROR_CLIENT_SIDE_ENCRYPTION,
144
- mongocrypt_status_code (status),
102
+ mongocrypt_status_code(status),
145
103
  "%s",
146
- mongocrypt_status_message (status, NULL));
104
+ mongocrypt_status_message(status, NULL));
147
105
  }
148
106
 
149
107
  /* Checks for an error on mongocrypt context.
@@ -153,609 +111,535 @@ _status_to_error (mongocrypt_status_t *status, bson_error_t *error)
153
111
  * Returns true if ok, and does not modify @error.
154
112
  * Returns false if error, and sets @error.
155
113
  */
156
- bool
157
- _test_ctx_check_error (mongocrypt_ctx_t *ctx,
158
- bson_error_t *error,
159
- bool error_expected)
160
- {
161
- mongocrypt_status_t *status;
162
-
163
- status = mongocrypt_status_new ();
164
- if (!mongocrypt_ctx_status (ctx, status)) {
165
- _status_to_error (status, error);
166
- mongocrypt_status_destroy (status);
167
- return false;
168
- } else if (error_expected) {
169
- bson_set_error (error,
170
- MONGOC_ERROR_CLIENT,
171
- MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_STATE,
172
- "generic error from libmongocrypt operation");
173
- mongocrypt_status_destroy (status);
174
- return false;
175
- }
176
- mongocrypt_status_destroy (status);
177
- return true;
178
- }
179
-
180
- bool
181
- _test_kms_ctx_check_error (mongocrypt_kms_ctx_t *kms_ctx,
182
- bson_error_t *error,
183
- bool error_expected)
184
- {
185
- mongocrypt_status_t *status;
186
-
187
- status = mongocrypt_status_new ();
188
- if (!mongocrypt_kms_ctx_status (kms_ctx, status)) {
189
- _status_to_error (status, error);
190
- mongocrypt_status_destroy (status);
191
- return false;
192
- } else if (error_expected) {
193
- bson_set_error (error,
194
- MONGOC_ERROR_CLIENT,
195
- MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_STATE,
196
- "generic error from libmongocrypt KMS operation");
197
- mongocrypt_status_destroy (status);
198
- return false;
199
- }
200
- mongocrypt_status_destroy (status);
201
- return true;
114
+ bool _test_ctx_check_error(mongocrypt_ctx_t *ctx, bson_error_t *error, bool error_expected) {
115
+ mongocrypt_status_t *status;
116
+
117
+ status = mongocrypt_status_new();
118
+ if (!mongocrypt_ctx_status(ctx, status)) {
119
+ _status_to_error(status, error);
120
+ mongocrypt_status_destroy(status);
121
+ return false;
122
+ } else if (error_expected) {
123
+ bson_set_error(error,
124
+ MONGOC_ERROR_CLIENT,
125
+ MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_STATE,
126
+ "generic error from libmongocrypt operation");
127
+ mongocrypt_status_destroy(status);
128
+ return false;
129
+ }
130
+ mongocrypt_status_destroy(status);
131
+ return true;
132
+ }
133
+
134
+ bool _test_kms_ctx_check_error(mongocrypt_kms_ctx_t *kms_ctx, bson_error_t *error, bool error_expected) {
135
+ mongocrypt_status_t *status;
136
+
137
+ status = mongocrypt_status_new();
138
+ if (!mongocrypt_kms_ctx_status(kms_ctx, status)) {
139
+ _status_to_error(status, error);
140
+ mongocrypt_status_destroy(status);
141
+ return false;
142
+ } else if (error_expected) {
143
+ bson_set_error(error,
144
+ MONGOC_ERROR_CLIENT,
145
+ MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_STATE,
146
+ "generic error from libmongocrypt KMS operation");
147
+ mongocrypt_status_destroy(status);
148
+ return false;
149
+ }
150
+ mongocrypt_status_destroy(status);
151
+ return true;
202
152
  }
203
153
 
204
154
  /* Convert a mongocrypt_binary_t to a static bson_t */
205
- static bool
206
- _bin_to_static_bson (mongocrypt_binary_t *bin, bson_t *out, bson_error_t *error)
207
- {
208
- /* Copy bin into bson_t result. */
209
- if (!bson_init_static (
210
- out, mongocrypt_binary_data (bin), mongocrypt_binary_len (bin))) {
211
- bson_set_error (error,
212
- MONGOC_ERROR_BSON,
213
- MONGOC_ERROR_BSON_INVALID,
214
- "invalid returned bson");
215
- return false;
216
- }
217
- return true;
155
+ static bool _bin_to_static_bson(mongocrypt_binary_t *bin, bson_t *out, bson_error_t *error) {
156
+ /* Copy bin into bson_t result. */
157
+ if (!bson_init_static(out, mongocrypt_binary_data(bin), mongocrypt_binary_len(bin))) {
158
+ bson_set_error(error, MONGOC_ERROR_BSON, MONGOC_ERROR_BSON_INVALID, "invalid returned bson");
159
+ return false;
160
+ }
161
+ return true;
218
162
  }
219
163
 
220
164
  /* State handler MONGOCRYPT_CTX_NEED_MONGO_COLLINFO */
221
- static bool
222
- _state_need_mongo_collinfo (_state_machine_t *state_machine,
223
- bson_error_t *error)
224
- {
225
- mongoc_database_t *db = NULL;
226
- mongoc_cursor_t *cursor = NULL;
227
- bson_t filter_bson;
228
- const bson_t *collinfo_bson = NULL;
229
- bson_t opts = BSON_INITIALIZER;
230
- mongocrypt_binary_t *filter_bin = NULL;
231
- mongocrypt_binary_t *collinfo_bin = NULL;
232
- bool ret = false;
233
-
234
- /* 1. Run listCollections on the encrypted MongoClient with the filter
235
- * provided by mongocrypt_ctx_mongo_op */
236
- filter_bin = mongocrypt_binary_new ();
237
- if (!mongocrypt_ctx_mongo_op (state_machine->ctx, filter_bin)) {
238
- _test_ctx_check_error (state_machine->ctx, error, true);
239
- goto fail;
240
- }
241
-
242
- if (!_bin_to_static_bson (filter_bin, &filter_bson, error)) {
243
- goto fail;
244
- }
245
-
246
- bson_append_document (&opts, "filter", -1, &filter_bson);
247
- db = mongoc_client_get_database (state_machine->collinfo_client,
248
- state_machine->db_name);
249
-
250
- if (state_machine->trace) {
251
- char *opts_str;
252
-
253
- opts_str = bson_as_canonical_extended_json (&filter_bson, NULL);
254
- MONGOC_DEBUG (
255
- "--> sending listCollections cmd on db %s mongod with opts: %s",
256
- state_machine->db_name,
257
- opts_str);
258
- bson_free (opts_str);
259
- }
260
- cursor = mongoc_database_find_collections_with_opts (db, &opts);
261
- if (mongoc_cursor_error (cursor, error)) {
262
- goto fail;
263
- }
264
-
265
- /* 2. Return the first result (if any) with mongocrypt_ctx_mongo_feed or
266
- * proceed to the next step if nothing was returned. */
267
- if (mongoc_cursor_next (cursor, &collinfo_bson)) {
268
- if (state_machine->trace) {
269
- char *result_str;
270
-
271
- result_str = bson_as_canonical_extended_json (collinfo_bson, NULL);
272
- MONGOC_DEBUG ("<-- got result: %s", result_str);
273
- bson_free (result_str);
274
- }
275
- collinfo_bin = mongocrypt_binary_new_from_data (
276
- (uint8_t *) bson_get_data (collinfo_bson), collinfo_bson->len);
277
- if (!mongocrypt_ctx_mongo_feed (state_machine->ctx, collinfo_bin)) {
278
- _test_ctx_check_error (state_machine->ctx, error, true);
279
- goto fail;
280
- }
281
- } else if (mongoc_cursor_error (cursor, error)) {
282
- goto fail;
283
- }
284
-
285
- /* 3. Call mongocrypt_ctx_mongo_done */
286
- if (!mongocrypt_ctx_mongo_done (state_machine->ctx)) {
287
- _test_ctx_check_error (state_machine->ctx, error, true);
288
- goto fail;
289
- }
290
-
291
- ret = true;
165
+ static bool _state_need_mongo_collinfo(_state_machine_t *state_machine, bson_error_t *error) {
166
+ mongoc_database_t *db = NULL;
167
+ mongoc_cursor_t *cursor = NULL;
168
+ bson_t filter_bson;
169
+ const bson_t *collinfo_bson = NULL;
170
+ bson_t opts = BSON_INITIALIZER;
171
+ mongocrypt_binary_t *filter_bin = NULL;
172
+ mongocrypt_binary_t *collinfo_bin = NULL;
173
+ bool ret = false;
174
+
175
+ /* 1. Run listCollections on the encrypted MongoClient with the filter
176
+ * provided by mongocrypt_ctx_mongo_op */
177
+ filter_bin = mongocrypt_binary_new();
178
+ if (!mongocrypt_ctx_mongo_op(state_machine->ctx, filter_bin)) {
179
+ _test_ctx_check_error(state_machine->ctx, error, true);
180
+ goto fail;
181
+ }
182
+
183
+ if (!_bin_to_static_bson(filter_bin, &filter_bson, error)) {
184
+ goto fail;
185
+ }
186
+
187
+ bson_append_document(&opts, "filter", -1, &filter_bson);
188
+ db = mongoc_client_get_database(state_machine->collinfo_client, state_machine->db_name);
189
+
190
+ if (state_machine->trace) {
191
+ char *opts_str;
192
+
193
+ opts_str = bson_as_canonical_extended_json(&filter_bson, NULL);
194
+ MONGOC_DEBUG("--> sending listCollections cmd on db %s mongod with opts: %s", state_machine->db_name, opts_str);
195
+ bson_free(opts_str);
196
+ }
197
+ cursor = mongoc_database_find_collections_with_opts(db, &opts);
198
+ if (mongoc_cursor_error(cursor, error)) {
199
+ goto fail;
200
+ }
201
+
202
+ /* 2. Return the first result (if any) with mongocrypt_ctx_mongo_feed or
203
+ * proceed to the next step if nothing was returned. */
204
+ if (mongoc_cursor_next(cursor, &collinfo_bson)) {
205
+ if (state_machine->trace) {
206
+ char *result_str;
207
+
208
+ result_str = bson_as_canonical_extended_json(collinfo_bson, NULL);
209
+ MONGOC_DEBUG("<-- got result: %s", result_str);
210
+ bson_free(result_str);
211
+ }
212
+ collinfo_bin = mongocrypt_binary_new_from_data((uint8_t *)bson_get_data(collinfo_bson), collinfo_bson->len);
213
+ if (!mongocrypt_ctx_mongo_feed(state_machine->ctx, collinfo_bin)) {
214
+ _test_ctx_check_error(state_machine->ctx, error, true);
215
+ goto fail;
216
+ }
217
+ } else if (mongoc_cursor_error(cursor, error)) {
218
+ goto fail;
219
+ }
220
+
221
+ /* 3. Call mongocrypt_ctx_mongo_done */
222
+ if (!mongocrypt_ctx_mongo_done(state_machine->ctx)) {
223
+ _test_ctx_check_error(state_machine->ctx, error, true);
224
+ goto fail;
225
+ }
226
+
227
+ ret = true;
292
228
 
293
229
  fail:
294
230
 
295
- bson_destroy (&opts);
296
- mongocrypt_binary_destroy (filter_bin);
297
- mongocrypt_binary_destroy (collinfo_bin);
298
- mongoc_cursor_destroy (cursor);
299
- mongoc_database_destroy (db);
300
- return ret;
301
- }
302
-
303
- static bool
304
- _state_need_mongo_markings (_state_machine_t *state_machine,
305
- bson_error_t *error)
306
- {
307
- bool ret = false;
308
- mongocrypt_binary_t *mongocryptd_cmd_bin = NULL;
309
- mongocrypt_binary_t *mongocryptd_reply_bin = NULL;
310
- bson_t mongocryptd_cmd_bson;
311
- bson_t reply = BSON_INITIALIZER;
312
-
313
- mongocryptd_cmd_bin = mongocrypt_binary_new ();
314
-
315
- if (!mongocrypt_ctx_mongo_op (state_machine->ctx, mongocryptd_cmd_bin)) {
316
- _test_ctx_check_error (state_machine->ctx, error, true);
317
- goto fail;
318
- }
319
-
320
- if (!_bin_to_static_bson (
321
- mongocryptd_cmd_bin, &mongocryptd_cmd_bson, error)) {
322
- goto fail;
323
- }
324
-
325
- if (state_machine->trace) {
326
- char *cmd_str;
327
- bson_iter_t iter;
328
-
329
- bson_iter_init (&iter, &mongocryptd_cmd_bson);
330
- bson_iter_next (&iter);
331
- cmd_str = bson_as_canonical_extended_json (&mongocryptd_cmd_bson, NULL);
332
- MONGOC_DEBUG ("--> sending %s cmd to mongocryptd: %s",
333
- bson_iter_key (&iter),
334
- cmd_str);
335
- bson_free (cmd_str);
336
- }
337
-
338
- /* 1. Use db.runCommand to run the command provided by
339
- * mongocrypt_ctx_mongo_op on the MongoClient connected to mongocryptd. */
340
- bson_destroy (&reply);
341
- if (!mongoc_client_command_simple (state_machine->mongocryptd_client,
231
+ bson_destroy(&opts);
232
+ mongocrypt_binary_destroy(filter_bin);
233
+ mongocrypt_binary_destroy(collinfo_bin);
234
+ mongoc_cursor_destroy(cursor);
235
+ mongoc_database_destroy(db);
236
+ return ret;
237
+ }
238
+
239
+ static bool _state_need_mongo_markings(_state_machine_t *state_machine, bson_error_t *error) {
240
+ bool ret = false;
241
+ mongocrypt_binary_t *mongocryptd_cmd_bin = NULL;
242
+ mongocrypt_binary_t *mongocryptd_reply_bin = NULL;
243
+ bson_t mongocryptd_cmd_bson;
244
+ bson_t reply = BSON_INITIALIZER;
245
+
246
+ mongocryptd_cmd_bin = mongocrypt_binary_new();
247
+
248
+ if (!mongocrypt_ctx_mongo_op(state_machine->ctx, mongocryptd_cmd_bin)) {
249
+ _test_ctx_check_error(state_machine->ctx, error, true);
250
+ goto fail;
251
+ }
252
+
253
+ if (!_bin_to_static_bson(mongocryptd_cmd_bin, &mongocryptd_cmd_bson, error)) {
254
+ goto fail;
255
+ }
256
+
257
+ if (state_machine->trace) {
258
+ char *cmd_str;
259
+ bson_iter_t iter;
260
+
261
+ bson_iter_init(&iter, &mongocryptd_cmd_bson);
262
+ bson_iter_next(&iter);
263
+ cmd_str = bson_as_canonical_extended_json(&mongocryptd_cmd_bson, NULL);
264
+ MONGOC_DEBUG("--> sending %s cmd to mongocryptd: %s", bson_iter_key(&iter), cmd_str);
265
+ bson_free(cmd_str);
266
+ }
267
+
268
+ /* 1. Use db.runCommand to run the command provided by
269
+ * mongocrypt_ctx_mongo_op on the MongoClient connected to mongocryptd. */
270
+ bson_destroy(&reply);
271
+ if (!mongoc_client_command_simple(state_machine->mongocryptd_client,
342
272
  "admin",
343
273
  &mongocryptd_cmd_bson,
344
274
  NULL /* read_prefs */,
345
275
  &reply,
346
276
  error)) {
347
- _prefix_mongocryptd_error (error);
348
- goto fail;
349
- }
350
-
351
- if (state_machine->trace) {
352
- char *reply_str;
353
-
354
- reply_str = bson_as_canonical_extended_json (&reply, NULL);
355
- MONGOC_DEBUG ("<-- got reply: %s", reply_str);
356
- bson_free (reply_str);
357
- }
358
-
359
- /* 2. Feed the reply back with mongocrypt_ctx_mongo_feed. */
360
- mongocryptd_reply_bin = mongocrypt_binary_new_from_data (
361
- (uint8_t *) bson_get_data (&reply), reply.len);
362
- if (!mongocrypt_ctx_mongo_feed (state_machine->ctx, mongocryptd_reply_bin)) {
363
- _test_ctx_check_error (state_machine->ctx, error, true);
364
- goto fail;
365
- }
366
-
367
- /* 3. Call mongocrypt_ctx_mongo_done. */
368
- if (!mongocrypt_ctx_mongo_done (state_machine->ctx)) {
369
- _test_ctx_check_error (state_machine->ctx, error, true);
370
- goto fail;
371
- }
372
-
373
- ret = true;
277
+ _prefix_mongocryptd_error(error);
278
+ goto fail;
279
+ }
280
+
281
+ if (state_machine->trace) {
282
+ char *reply_str;
283
+
284
+ reply_str = bson_as_canonical_extended_json(&reply, NULL);
285
+ MONGOC_DEBUG("<-- got reply: %s", reply_str);
286
+ bson_free(reply_str);
287
+ }
288
+
289
+ /* 2. Feed the reply back with mongocrypt_ctx_mongo_feed. */
290
+ mongocryptd_reply_bin = mongocrypt_binary_new_from_data((uint8_t *)bson_get_data(&reply), reply.len);
291
+ if (!mongocrypt_ctx_mongo_feed(state_machine->ctx, mongocryptd_reply_bin)) {
292
+ _test_ctx_check_error(state_machine->ctx, error, true);
293
+ goto fail;
294
+ }
295
+
296
+ /* 3. Call mongocrypt_ctx_mongo_done. */
297
+ if (!mongocrypt_ctx_mongo_done(state_machine->ctx)) {
298
+ _test_ctx_check_error(state_machine->ctx, error, true);
299
+ goto fail;
300
+ }
301
+
302
+ ret = true;
374
303
  fail:
375
- bson_destroy (&reply);
376
- mongocrypt_binary_destroy (mongocryptd_cmd_bin);
377
- mongocrypt_binary_destroy (mongocryptd_reply_bin);
378
- return ret;
379
- }
380
-
381
- static bool
382
- _state_need_mongo_keys (_state_machine_t *state_machine, bson_error_t *error)
383
- {
384
- bool ret = false;
385
- mongocrypt_binary_t *filter_bin = NULL;
386
- bson_t filter_bson;
387
- bson_t opts = BSON_INITIALIZER;
388
- mongocrypt_binary_t *key_bin = NULL;
389
- const bson_t *key_bson;
390
- mongoc_cursor_t *cursor = NULL;
391
- mongoc_read_concern_t *rc = NULL;
392
-
393
- /* 1. Use MongoCollection.find on the MongoClient connected to the key vault
394
- * client (which may be the same as the encrypted client). Use the filter
395
- * provided by mongocrypt_ctx_mongo_op. */
396
- filter_bin = mongocrypt_binary_new ();
397
- if (!mongocrypt_ctx_mongo_op (state_machine->ctx, filter_bin)) {
398
- _test_ctx_check_error (state_machine->ctx, error, true);
399
- goto fail;
400
- }
401
-
402
- if (!_bin_to_static_bson (filter_bin, &filter_bson, error)) {
403
- _test_ctx_check_error (state_machine->ctx, error, true);
404
- goto fail;
405
- }
406
-
407
- rc = mongoc_read_concern_new ();
408
- mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_MAJORITY);
409
- if (!mongoc_read_concern_append (rc, &opts)) {
410
- bson_set_error (error,
411
- MONGOC_ERROR_BSON,
412
- MONGOC_ERROR_BSON_INVALID,
413
- "%s",
414
- "could not set read concern");
415
- goto fail;
416
- }
417
-
418
- if (state_machine->trace) {
419
- char *filter_str;
420
- char *opts_str;
421
-
422
- filter_str = bson_as_canonical_extended_json (&filter_bson, NULL);
423
- opts_str = bson_as_canonical_extended_json (&opts, NULL);
424
- MONGOC_DEBUG ("--> sending find to mongod with filter: %s and opts: %s",
425
- filter_str,
426
- opts_str);
427
- bson_free (filter_str);
428
- bson_free (opts_str);
429
- }
430
-
431
- cursor = mongoc_collection_find_with_opts (
432
- state_machine->keyvault_coll, &filter_bson, &opts, NULL /* read prefs */);
433
- /* 2. Feed all resulting documents back (if any) with repeated calls to
434
- * mongocrypt_ctx_mongo_feed. */
435
- while (mongoc_cursor_next (cursor, &key_bson)) {
436
- if (state_machine->trace) {
437
- char *key_str;
438
-
439
- key_str = bson_as_canonical_extended_json (key_bson, NULL);
440
- MONGOC_DEBUG ("<-- got result key document: %s", key_str);
441
- bson_free (key_str);
442
- }
443
- mongocrypt_binary_destroy (key_bin);
444
- key_bin = mongocrypt_binary_new_from_data (
445
- (uint8_t *) bson_get_data (key_bson), key_bson->len);
446
- if (!mongocrypt_ctx_mongo_feed (state_machine->ctx, key_bin)) {
447
- _test_ctx_check_error (state_machine->ctx, error, true);
448
- goto fail;
449
- }
450
- }
451
- if (mongoc_cursor_error (cursor, error)) {
452
- _prefix_keyvault_error (error);
453
- goto fail;
454
- }
455
-
456
- /* 3. Call mongocrypt_ctx_mongo_done. */
457
- if (!mongocrypt_ctx_mongo_done (state_machine->ctx)) {
458
- _test_ctx_check_error (state_machine->ctx, error, true);
459
- goto fail;
460
- }
461
-
462
- ret = true;
304
+ bson_destroy(&reply);
305
+ mongocrypt_binary_destroy(mongocryptd_cmd_bin);
306
+ mongocrypt_binary_destroy(mongocryptd_reply_bin);
307
+ return ret;
308
+ }
309
+
310
+ static bool _state_need_mongo_keys(_state_machine_t *state_machine, bson_error_t *error) {
311
+ bool ret = false;
312
+ mongocrypt_binary_t *filter_bin = NULL;
313
+ bson_t filter_bson;
314
+ bson_t opts = BSON_INITIALIZER;
315
+ mongocrypt_binary_t *key_bin = NULL;
316
+ const bson_t *key_bson;
317
+ mongoc_cursor_t *cursor = NULL;
318
+ mongoc_read_concern_t *rc = NULL;
319
+
320
+ /* 1. Use MongoCollection.find on the MongoClient connected to the key vault
321
+ * client (which may be the same as the encrypted client). Use the filter
322
+ * provided by mongocrypt_ctx_mongo_op. */
323
+ filter_bin = mongocrypt_binary_new();
324
+ if (!mongocrypt_ctx_mongo_op(state_machine->ctx, filter_bin)) {
325
+ _test_ctx_check_error(state_machine->ctx, error, true);
326
+ goto fail;
327
+ }
328
+
329
+ if (!_bin_to_static_bson(filter_bin, &filter_bson, error)) {
330
+ _test_ctx_check_error(state_machine->ctx, error, true);
331
+ goto fail;
332
+ }
333
+
334
+ rc = mongoc_read_concern_new();
335
+ mongoc_read_concern_set_level(rc, MONGOC_READ_CONCERN_LEVEL_MAJORITY);
336
+ if (!mongoc_read_concern_append(rc, &opts)) {
337
+ bson_set_error(error, MONGOC_ERROR_BSON, MONGOC_ERROR_BSON_INVALID, "%s", "could not set read concern");
338
+ goto fail;
339
+ }
340
+
341
+ if (state_machine->trace) {
342
+ char *filter_str;
343
+ char *opts_str;
344
+
345
+ filter_str = bson_as_canonical_extended_json(&filter_bson, NULL);
346
+ opts_str = bson_as_canonical_extended_json(&opts, NULL);
347
+ MONGOC_DEBUG("--> sending find to mongod with filter: %s and opts: %s", filter_str, opts_str);
348
+ bson_free(filter_str);
349
+ bson_free(opts_str);
350
+ }
351
+
352
+ cursor = mongoc_collection_find_with_opts(state_machine->keyvault_coll, &filter_bson, &opts, NULL /* read prefs */);
353
+ /* 2. Feed all resulting documents back (if any) with repeated calls to
354
+ * mongocrypt_ctx_mongo_feed. */
355
+ while (mongoc_cursor_next(cursor, &key_bson)) {
356
+ if (state_machine->trace) {
357
+ char *key_str;
358
+
359
+ key_str = bson_as_canonical_extended_json(key_bson, NULL);
360
+ MONGOC_DEBUG("<-- got result key document: %s", key_str);
361
+ bson_free(key_str);
362
+ }
363
+ mongocrypt_binary_destroy(key_bin);
364
+ key_bin = mongocrypt_binary_new_from_data((uint8_t *)bson_get_data(key_bson), key_bson->len);
365
+ if (!mongocrypt_ctx_mongo_feed(state_machine->ctx, key_bin)) {
366
+ _test_ctx_check_error(state_machine->ctx, error, true);
367
+ goto fail;
368
+ }
369
+ }
370
+ if (mongoc_cursor_error(cursor, error)) {
371
+ _prefix_keyvault_error(error);
372
+ goto fail;
373
+ }
374
+
375
+ /* 3. Call mongocrypt_ctx_mongo_done. */
376
+ if (!mongocrypt_ctx_mongo_done(state_machine->ctx)) {
377
+ _test_ctx_check_error(state_machine->ctx, error, true);
378
+ goto fail;
379
+ }
380
+
381
+ ret = true;
463
382
  fail:
464
- mongocrypt_binary_destroy (filter_bin);
465
- mongoc_cursor_destroy (cursor);
466
- mongoc_read_concern_destroy (rc);
467
- bson_destroy (&opts);
468
- mongocrypt_binary_destroy (key_bin);
469
- return ret;
383
+ mongocrypt_binary_destroy(filter_bin);
384
+ mongoc_cursor_destroy(cursor);
385
+ mongoc_read_concern_destroy(rc);
386
+ bson_destroy(&opts);
387
+ mongocrypt_binary_destroy(key_bin);
388
+ return ret;
470
389
  }
471
390
 
472
391
  /* Create a TLS stream to a host. */
473
- static mongoc_stream_t *
474
- connect_stream_with_tls (mongoc_ssl_opt_t *ssl_opt,
475
- const char *endpoint,
476
- int32_t connecttimeoutms,
477
- bson_error_t *error)
478
- {
479
- mongoc_stream_t *stream = NULL;
480
- mongoc_socket_t *sock = NULL;
481
- struct addrinfo hints;
482
- struct addrinfo *result, *rp;
483
- int64_t expire_at;
484
- int s;
485
- char *colon = NULL;
486
- char *host = NULL;
487
- char *port = NULL;
488
- bool success = false;
489
-
490
- colon = strstr (endpoint, ":");
491
- if (colon == NULL) {
492
- host = bson_strdup (endpoint);
493
- port = bson_strdup ("443");
494
- } else {
495
- host = bson_strndup (endpoint, colon - endpoint);
496
- port = bson_strdup (colon + 1);
497
- }
498
-
499
- memset (&hints, 0, sizeof hints);
500
- hints.ai_family = AF_INET;
501
- hints.ai_socktype = SOCK_STREAM;
502
- hints.ai_flags = 0;
503
- hints.ai_protocol = 0;
504
-
505
- s = getaddrinfo (host, port, &hints, &result);
506
- if (s != 0) {
507
- MONGOC_ERROR ("DNS lookup failed: %s", host);
508
- goto done;
509
- }
510
-
511
- for (rp = result; rp; rp = rp->ai_next) {
512
- if (!(sock = mongoc_socket_new (
513
- rp->ai_family, rp->ai_socktype, rp->ai_protocol))) {
514
- continue;
515
- }
516
-
517
- expire_at = bson_get_monotonic_time () + (connecttimeoutms * 1000L);
518
- if (0 !=
519
- mongoc_socket_connect (
520
- sock, rp->ai_addr, (mongoc_socklen_t) rp->ai_addrlen, expire_at)) {
521
- mongoc_socket_destroy (sock);
522
- sock = NULL;
523
- continue;
524
- }
525
-
526
- break;
527
- }
528
-
529
- if (!sock) {
530
- MONGOC_ERROR ("Failed to connect: %s", host);
531
- goto done;
532
- }
533
-
534
- stream = mongoc_stream_socket_new (sock);
535
- if (!stream) {
536
- MONGOC_ERROR ("Failed to create stream: %s", host);
537
- goto done;
538
- }
539
-
540
- success = true;
392
+ static mongoc_stream_t *connect_stream_with_tls(mongoc_ssl_opt_t *ssl_opt,
393
+ const char *endpoint,
394
+ int32_t connecttimeoutms,
395
+ bson_error_t *error) {
396
+ mongoc_stream_t *stream = NULL;
397
+ mongoc_socket_t *sock = NULL;
398
+ struct addrinfo hints;
399
+ struct addrinfo *result, *rp;
400
+ int64_t expire_at;
401
+ int s;
402
+ char *colon = NULL;
403
+ char *host = NULL;
404
+ char *port = NULL;
405
+ bool success = false;
406
+
407
+ colon = strstr(endpoint, ":");
408
+ if (colon == NULL) {
409
+ host = bson_strdup(endpoint);
410
+ port = bson_strdup("443");
411
+ } else {
412
+ host = bson_strndup(endpoint, colon - endpoint);
413
+ port = bson_strdup(colon + 1);
414
+ }
415
+
416
+ memset(&hints, 0, sizeof hints);
417
+ hints.ai_family = AF_INET;
418
+ hints.ai_socktype = SOCK_STREAM;
419
+ hints.ai_flags = 0;
420
+ hints.ai_protocol = 0;
421
+
422
+ s = getaddrinfo(host, port, &hints, &result);
423
+ if (s != 0) {
424
+ MONGOC_ERROR("DNS lookup failed: %s", host);
425
+ goto done;
426
+ }
427
+
428
+ for (rp = result; rp; rp = rp->ai_next) {
429
+ if (!(sock = mongoc_socket_new(rp->ai_family, rp->ai_socktype, rp->ai_protocol))) {
430
+ continue;
431
+ }
432
+
433
+ expire_at = bson_get_monotonic_time() + (connecttimeoutms * 1000L);
434
+ if (0 != mongoc_socket_connect(sock, rp->ai_addr, (mongoc_socklen_t)rp->ai_addrlen, expire_at)) {
435
+ mongoc_socket_destroy(sock);
436
+ sock = NULL;
437
+ continue;
438
+ }
439
+
440
+ break;
441
+ }
442
+
443
+ if (!sock) {
444
+ MONGOC_ERROR("Failed to connect: %s", host);
445
+ goto done;
446
+ }
447
+
448
+ stream = mongoc_stream_socket_new(sock);
449
+ if (!stream) {
450
+ MONGOC_ERROR("Failed to create stream: %s", host);
451
+ goto done;
452
+ }
453
+
454
+ success = true;
541
455
  done:
542
- if (result) {
543
- freeaddrinfo (result);
544
- }
545
- if (success) {
546
- stream = mongoc_stream_tls_new_with_hostname (stream, host, ssl_opt, 1);
547
- } else {
548
- mongoc_stream_destroy (stream);
549
- stream = NULL;
550
- }
551
-
552
- if (!mongoc_stream_tls_handshake_block (
553
- stream, host, connecttimeoutms, error)) {
554
- mongoc_stream_destroy (stream);
555
- stream = NULL;
556
- }
557
-
558
- bson_free (host);
559
- bson_free (port);
560
- return stream;
456
+ if (result) {
457
+ freeaddrinfo(result);
458
+ }
459
+ if (success) {
460
+ stream = mongoc_stream_tls_new_with_hostname(stream, host, ssl_opt, 1);
461
+ } else {
462
+ mongoc_stream_destroy(stream);
463
+ stream = NULL;
464
+ }
465
+
466
+ if (!mongoc_stream_tls_handshake_block(stream, host, connecttimeoutms, error)) {
467
+ mongoc_stream_destroy(stream);
468
+ stream = NULL;
469
+ }
470
+
471
+ bson_free(host);
472
+ bson_free(port);
473
+ return stream;
561
474
  }
562
475
 
563
476
  /* Copied from mongoc-stream.c */
564
- bool
565
- _mongoc_stream_writev_full (mongoc_stream_t *stream,
566
- mongoc_iovec_t *iov,
567
- size_t iovcnt,
568
- int32_t timeout_msec,
569
- bson_error_t *error);
570
-
571
- static bool
572
- _state_need_kms_credentials (_state_machine_t *state_machine,
573
- bson_error_t *error)
574
- {
575
- bson_t empty = BSON_INITIALIZER;
576
- mongocrypt_binary_t *bin = util_bson_to_bin (&empty);
577
- mongocrypt_ctx_provide_kms_providers (state_machine->ctx, bin);
578
- mongocrypt_binary_destroy (bin);
579
- return true;
580
- }
581
-
582
- static bool
583
- _state_need_kms (_state_machine_t *state_machine, bson_error_t *error)
584
- {
585
- mongocrypt_kms_ctx_t *kms_ctx = NULL;
586
- mongoc_stream_t *tls_stream = NULL;
587
- bool ret = false;
588
- mongocrypt_binary_t *http_req = NULL;
589
- mongocrypt_binary_t *http_reply = NULL;
590
- const char *endpoint;
591
- uint32_t sockettimeout;
592
- mongoc_ssl_opt_t ssl_opt;
593
-
594
- sockettimeout = MONGOC_DEFAULT_SOCKETTIMEOUTMS;
595
- kms_ctx = mongocrypt_ctx_next_kms_ctx (state_machine->ctx);
596
- while (kms_ctx) {
597
- mongoc_iovec_t iov;
598
-
599
- mongocrypt_binary_destroy (http_req);
600
- http_req = mongocrypt_binary_new ();
601
- if (!mongocrypt_kms_ctx_message (kms_ctx, http_req)) {
602
- _test_kms_ctx_check_error (kms_ctx, error, true);
603
- goto fail;
604
- }
605
-
606
- if (!mongocrypt_kms_ctx_endpoint (kms_ctx, &endpoint)) {
607
- _test_kms_ctx_check_error (kms_ctx, error, true);
608
- goto fail;
609
- }
610
-
611
- ssl_opt = *mongoc_ssl_opt_get_default ();
612
- ssl_opt.ca_file = state_machine->tls_ca_file;
613
- ssl_opt.pem_file = state_machine->tls_certificate_key_file;
614
- tls_stream =
615
- connect_stream_with_tls (&ssl_opt, endpoint, sockettimeout, error);
477
+ bool _mongoc_stream_writev_full(mongoc_stream_t *stream,
478
+ mongoc_iovec_t *iov,
479
+ size_t iovcnt,
480
+ int32_t timeout_msec,
481
+ bson_error_t *error);
482
+
483
+ static bool _state_need_kms_credentials(_state_machine_t *state_machine, bson_error_t *error) {
484
+ bson_t empty = BSON_INITIALIZER;
485
+ mongocrypt_binary_t *bin = util_bson_to_bin(&empty);
486
+ mongocrypt_ctx_provide_kms_providers(state_machine->ctx, bin);
487
+ mongocrypt_binary_destroy(bin);
488
+ return true;
489
+ }
490
+
491
+ static bool _state_need_kms(_state_machine_t *state_machine, bson_error_t *error) {
492
+ mongocrypt_kms_ctx_t *kms_ctx = NULL;
493
+ mongoc_stream_t *tls_stream = NULL;
494
+ bool ret = false;
495
+ mongocrypt_binary_t *http_req = NULL;
496
+ mongocrypt_binary_t *http_reply = NULL;
497
+ const char *endpoint;
498
+ uint32_t sockettimeout;
499
+ mongoc_ssl_opt_t ssl_opt;
500
+
501
+ sockettimeout = MONGOC_DEFAULT_SOCKETTIMEOUTMS;
502
+ kms_ctx = mongocrypt_ctx_next_kms_ctx(state_machine->ctx);
503
+ while (kms_ctx) {
504
+ mongoc_iovec_t iov;
505
+
506
+ mongocrypt_binary_destroy(http_req);
507
+ http_req = mongocrypt_binary_new();
508
+ if (!mongocrypt_kms_ctx_message(kms_ctx, http_req)) {
509
+ _test_kms_ctx_check_error(kms_ctx, error, true);
510
+ goto fail;
511
+ }
512
+
513
+ if (!mongocrypt_kms_ctx_endpoint(kms_ctx, &endpoint)) {
514
+ _test_kms_ctx_check_error(kms_ctx, error, true);
515
+ goto fail;
516
+ }
517
+
518
+ ssl_opt = *mongoc_ssl_opt_get_default();
519
+ ssl_opt.ca_file = state_machine->tls_ca_file;
520
+ ssl_opt.pem_file = state_machine->tls_certificate_key_file;
521
+ tls_stream = connect_stream_with_tls(&ssl_opt, endpoint, sockettimeout, error);
616
522
  #ifdef MONGOC_ENABLE_SSL_SECURE_CHANNEL
617
- /* Retry once with schannel as a workaround for CDRIVER-3566. */
618
- if (!tls_stream) {
619
- tls_stream =
620
- connect_stream_with_tls (&ssl_opt, endpoint, sockettimeout, error);
621
- }
523
+ /* Retry once with schannel as a workaround for CDRIVER-3566. */
524
+ if (!tls_stream) {
525
+ tls_stream = connect_stream_with_tls(&ssl_opt, endpoint, sockettimeout, error);
526
+ }
622
527
  #endif
623
- if (!tls_stream) {
624
- goto fail;
625
- }
626
-
627
- iov.iov_base = (char *) mongocrypt_binary_data (http_req);
628
- iov.iov_len = mongocrypt_binary_len (http_req);
629
-
630
- if (state_machine->trace) {
631
- MONGOC_DEBUG ("--> sending KMS message: \n%.*s",
632
- (int) iov.iov_len,
633
- (char *) iov.iov_base);
634
- }
635
-
636
- if (!_mongoc_stream_writev_full (
637
- tls_stream, &iov, 1, sockettimeout, error)) {
638
- goto fail;
639
- }
640
-
641
- /* Read and feed reply. */
642
- while (mongocrypt_kms_ctx_bytes_needed (kms_ctx) > 0) {
643
- #define BUFFER_SIZE 1024
644
- uint8_t buf[BUFFER_SIZE];
645
- uint32_t bytes_needed = mongocrypt_kms_ctx_bytes_needed (kms_ctx);
646
- ssize_t read_ret;
647
-
648
- /* Cap the bytes requested at the buffer size. */
649
- if (bytes_needed > BUFFER_SIZE) {
650
- bytes_needed = BUFFER_SIZE;
651
- }
652
-
653
- read_ret = mongoc_stream_read (
654
- tls_stream, buf, bytes_needed, 0 /* min_bytes. */, sockettimeout);
655
- if (read_ret == -1) {
656
- bson_set_error (error,
657
- MONGOC_ERROR_STREAM,
658
- MONGOC_ERROR_STREAM_SOCKET,
659
- "failed to read from KMS stream: %d",
660
- errno);
528
+ if (!tls_stream) {
661
529
  goto fail;
662
- }
530
+ }
663
531
 
664
- if (read_ret == 0) {
665
- bson_set_error (error,
666
- MONGOC_ERROR_STREAM,
667
- MONGOC_ERROR_STREAM_SOCKET,
668
- "unexpected EOF from KMS stream");
669
- goto fail;
670
- }
671
-
672
- if (state_machine->trace) {
673
- MONGOC_DEBUG (
674
- "<-- read KMS reply: %.*s", (int) read_ret, (char *) buf);
675
- }
676
-
677
- mongocrypt_binary_destroy (http_reply);
678
- http_reply =
679
- mongocrypt_binary_new_from_data (buf, (uint32_t) read_ret);
680
- if (!mongocrypt_kms_ctx_feed (kms_ctx, http_reply)) {
681
- _test_kms_ctx_check_error (kms_ctx, error, true);
532
+ iov.iov_base = (char *)mongocrypt_binary_data(http_req);
533
+ iov.iov_len = mongocrypt_binary_len(http_req);
534
+
535
+ if (state_machine->trace) {
536
+ MONGOC_DEBUG("--> sending KMS message: \n%.*s", (int)iov.iov_len, (char *)iov.iov_base);
537
+ }
538
+
539
+ if (!_mongoc_stream_writev_full(tls_stream, &iov, 1, sockettimeout, error)) {
682
540
  goto fail;
683
- }
684
- }
685
- kms_ctx = mongocrypt_ctx_next_kms_ctx (state_machine->ctx);
686
- }
687
- /* When NULL is returned by mongocrypt_ctx_next_kms_ctx, this can either be
688
- * an error or end-of-list. */
689
- if (!_test_ctx_check_error (state_machine->ctx, error, false)) {
690
- goto fail;
691
- }
692
-
693
- if (!mongocrypt_ctx_kms_done (state_machine->ctx)) {
694
- _test_ctx_check_error (state_machine->ctx, error, true);
695
- goto fail;
696
- }
697
-
698
- ret = true;
541
+ }
542
+
543
+ /* Read and feed reply. */
544
+ while (mongocrypt_kms_ctx_bytes_needed(kms_ctx) > 0) {
545
+ #define BUFFER_SIZE 1024
546
+ uint8_t buf[BUFFER_SIZE];
547
+ uint32_t bytes_needed = mongocrypt_kms_ctx_bytes_needed(kms_ctx);
548
+ ssize_t read_ret;
549
+
550
+ /* Cap the bytes requested at the buffer size. */
551
+ if (bytes_needed > BUFFER_SIZE) {
552
+ bytes_needed = BUFFER_SIZE;
553
+ }
554
+
555
+ read_ret = mongoc_stream_read(tls_stream, buf, bytes_needed, 0 /* min_bytes. */, sockettimeout);
556
+ if (read_ret == -1) {
557
+ bson_set_error(error,
558
+ MONGOC_ERROR_STREAM,
559
+ MONGOC_ERROR_STREAM_SOCKET,
560
+ "failed to read from KMS stream: %d",
561
+ errno);
562
+ goto fail;
563
+ }
564
+
565
+ if (read_ret == 0) {
566
+ bson_set_error(error,
567
+ MONGOC_ERROR_STREAM,
568
+ MONGOC_ERROR_STREAM_SOCKET,
569
+ "unexpected EOF from KMS stream");
570
+ goto fail;
571
+ }
572
+
573
+ if (state_machine->trace) {
574
+ MONGOC_DEBUG("<-- read KMS reply: %.*s", (int)read_ret, (char *)buf);
575
+ }
576
+
577
+ mongocrypt_binary_destroy(http_reply);
578
+ http_reply = mongocrypt_binary_new_from_data(buf, (uint32_t)read_ret);
579
+ if (!mongocrypt_kms_ctx_feed(kms_ctx, http_reply)) {
580
+ _test_kms_ctx_check_error(kms_ctx, error, true);
581
+ goto fail;
582
+ }
583
+ }
584
+ kms_ctx = mongocrypt_ctx_next_kms_ctx(state_machine->ctx);
585
+ }
586
+ /* When NULL is returned by mongocrypt_ctx_next_kms_ctx, this can either be
587
+ * an error or end-of-list. */
588
+ if (!_test_ctx_check_error(state_machine->ctx, error, false)) {
589
+ goto fail;
590
+ }
591
+
592
+ if (!mongocrypt_ctx_kms_done(state_machine->ctx)) {
593
+ _test_ctx_check_error(state_machine->ctx, error, true);
594
+ goto fail;
595
+ }
596
+
597
+ ret = true;
699
598
  fail:
700
- mongoc_stream_destroy (tls_stream);
701
- mongocrypt_binary_destroy (http_req);
702
- mongocrypt_binary_destroy (http_reply);
703
- return ret;
599
+ mongoc_stream_destroy(tls_stream);
600
+ mongocrypt_binary_destroy(http_req);
601
+ mongocrypt_binary_destroy(http_reply);
602
+ return ret;
704
603
  #undef BUFFER_SIZE
705
604
  }
706
605
 
707
- static bool
708
- _state_ready (_state_machine_t *state_machine,
709
- bson_t *result,
710
- bson_error_t *error)
711
- {
712
- mongocrypt_binary_t *result_bin = NULL;
713
- bson_t tmp;
714
- bool ret = false;
606
+ static bool _state_ready(_state_machine_t *state_machine, bson_t *result, bson_error_t *error) {
607
+ mongocrypt_binary_t *result_bin = NULL;
608
+ bson_t tmp;
609
+ bool ret = false;
715
610
 
716
- bson_init (result);
717
- result_bin = mongocrypt_binary_new ();
718
- if (!mongocrypt_ctx_finalize (state_machine->ctx, result_bin)) {
719
- _test_ctx_check_error (state_machine->ctx, error, true);
720
- goto fail;
721
- }
611
+ bson_init(result);
612
+ result_bin = mongocrypt_binary_new();
613
+ if (!mongocrypt_ctx_finalize(state_machine->ctx, result_bin)) {
614
+ _test_ctx_check_error(state_machine->ctx, error, true);
615
+ goto fail;
616
+ }
722
617
 
723
- if (!_bin_to_static_bson (result_bin, &tmp, error)) {
724
- goto fail;
725
- }
618
+ if (!_bin_to_static_bson(result_bin, &tmp, error)) {
619
+ goto fail;
620
+ }
726
621
 
727
- bson_destroy (result);
728
- bson_copy_to (&tmp, result);
622
+ bson_destroy(result);
623
+ bson_copy_to(&tmp, result);
729
624
 
730
- ret = true;
625
+ ret = true;
731
626
  fail:
732
- mongocrypt_binary_destroy (result_bin);
733
- return ret;
734
- }
735
-
736
- const char *
737
- _state_string (mongocrypt_ctx_state_t state)
738
- {
739
- switch (state) {
740
- case MONGOCRYPT_CTX_ERROR:
741
- return "MONGOCRYPT_CTX_ERROR";
742
- case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
743
- return "MONGOCRYPT_CTX_NEED_MONGO_COLLINFO";
744
- case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
745
- return "MONGOCRYPT_CTX_NEED_MONGO_MARKINGS";
746
- case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
747
- return "MONGOCRYPT_CTX_NEED_MONGO_KEYS";
748
- case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
749
- return "MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS";
750
- case MONGOCRYPT_CTX_NEED_KMS:
751
- return "MONGOCRYPT_CTX_NEED_KMS";
752
- case MONGOCRYPT_CTX_READY:
753
- return "MONGOCRYPT_CTX_READY";
754
- case MONGOCRYPT_CTX_DONE:
755
- return "MONGOCRYPT_CTX_DONE";
756
- default:
757
- return "UNKNOWN";
758
- }
627
+ mongocrypt_binary_destroy(result_bin);
628
+ return ret;
629
+ }
630
+
631
+ const char *_state_string(mongocrypt_ctx_state_t state) {
632
+ switch (state) {
633
+ case MONGOCRYPT_CTX_ERROR: return "MONGOCRYPT_CTX_ERROR";
634
+ case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO: return "MONGOCRYPT_CTX_NEED_MONGO_COLLINFO";
635
+ case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS: return "MONGOCRYPT_CTX_NEED_MONGO_MARKINGS";
636
+ case MONGOCRYPT_CTX_NEED_MONGO_KEYS: return "MONGOCRYPT_CTX_NEED_MONGO_KEYS";
637
+ case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS: return "MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS";
638
+ case MONGOCRYPT_CTX_NEED_KMS: return "MONGOCRYPT_CTX_NEED_KMS";
639
+ case MONGOCRYPT_CTX_READY: return "MONGOCRYPT_CTX_READY";
640
+ case MONGOCRYPT_CTX_DONE: return "MONGOCRYPT_CTX_DONE";
641
+ default: return "UNKNOWN";
642
+ }
759
643
  }
760
644
 
761
645
  /*--------------------------------------------------------------------------
@@ -770,200 +654,170 @@ _state_string (mongocrypt_ctx_state_t state)
770
654
  *
771
655
  * --------------------------------------------------------------------------
772
656
  */
773
- bool
774
- _csfle_state_machine_run (_state_machine_t *state_machine,
775
- bson_t *result,
776
- bson_error_t *error)
777
- {
778
- bool ret = false;
779
- mongocrypt_binary_t *bin = NULL;
780
-
781
- bson_init (result);
782
- while (true) {
783
- if (state_machine->trace) {
784
- MONGOC_DEBUG (
785
- "Current state = %s",
786
- _state_string (mongocrypt_ctx_state (state_machine->ctx)));
787
- }
788
- switch (mongocrypt_ctx_state (state_machine->ctx)) {
789
- default:
790
- case MONGOCRYPT_CTX_ERROR:
791
- _test_ctx_check_error (state_machine->ctx, error, true);
792
- goto fail;
793
- case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
794
- if (!_state_need_mongo_collinfo (state_machine, error)) {
795
- goto fail;
796
- }
797
- break;
798
- case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
799
- if (!_state_need_mongo_markings (state_machine, error)) {
800
- goto fail;
801
- }
802
- break;
803
- case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
804
- if (!_state_need_mongo_keys (state_machine, error)) {
805
- goto fail;
806
- }
807
- break;
808
- case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
809
- if (!_state_need_kms_credentials (state_machine, error)) {
810
- goto fail;
811
- }
812
- break;
813
- case MONGOCRYPT_CTX_NEED_KMS:
814
- if (!_state_need_kms (state_machine, error)) {
815
- goto fail;
816
- }
817
- break;
818
- case MONGOCRYPT_CTX_READY:
819
- bson_destroy (result);
820
- if (!_state_ready (state_machine, result, error)) {
821
- goto fail;
822
- }
823
- break;
824
- case MONGOCRYPT_CTX_DONE:
825
- goto success;
826
- break;
827
- }
828
- }
657
+ bool _csfle_state_machine_run(_state_machine_t *state_machine, bson_t *result, bson_error_t *error) {
658
+ bool ret = false;
659
+ mongocrypt_binary_t *bin = NULL;
660
+
661
+ bson_init(result);
662
+ while (true) {
663
+ if (state_machine->trace) {
664
+ MONGOC_DEBUG("Current state = %s", _state_string(mongocrypt_ctx_state(state_machine->ctx)));
665
+ }
666
+ switch (mongocrypt_ctx_state(state_machine->ctx)) {
667
+ default:
668
+ case MONGOCRYPT_CTX_ERROR: _test_ctx_check_error(state_machine->ctx, error, true); goto fail;
669
+ case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
670
+ if (!_state_need_mongo_collinfo(state_machine, error)) {
671
+ goto fail;
672
+ }
673
+ break;
674
+ case MONGOCRYPT_CTX_NEED_MONGO_MARKINGS:
675
+ if (!_state_need_mongo_markings(state_machine, error)) {
676
+ goto fail;
677
+ }
678
+ break;
679
+ case MONGOCRYPT_CTX_NEED_MONGO_KEYS:
680
+ if (!_state_need_mongo_keys(state_machine, error)) {
681
+ goto fail;
682
+ }
683
+ break;
684
+ case MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS:
685
+ if (!_state_need_kms_credentials(state_machine, error)) {
686
+ goto fail;
687
+ }
688
+ break;
689
+ case MONGOCRYPT_CTX_NEED_KMS:
690
+ if (!_state_need_kms(state_machine, error)) {
691
+ goto fail;
692
+ }
693
+ break;
694
+ case MONGOCRYPT_CTX_READY:
695
+ bson_destroy(result);
696
+ if (!_state_ready(state_machine, result, error)) {
697
+ goto fail;
698
+ }
699
+ break;
700
+ case MONGOCRYPT_CTX_DONE: goto success; break;
701
+ }
702
+ }
829
703
 
830
704
  success:
831
- ret = true;
705
+ ret = true;
832
706
  fail:
833
- if (!ret && state_machine->trace) {
834
- MONGOC_DEBUG ("Error: %s", error->message);
835
- }
836
- mongocrypt_binary_destroy (bin);
837
- return ret;
838
- }
839
-
840
- bson_t *
841
- util_read_json_file (const char *path)
842
- {
843
- bson_json_reader_t *reader;
844
- bson_error_t error;
845
- bson_t *doc;
846
-
847
- reader = bson_json_reader_new_from_file (path, &error);
848
- if (!reader) {
849
- ERREXIT ("Error opening %s: %s", path, error.message);
850
- }
851
-
852
- doc = bson_new ();
853
- if (1 != bson_json_reader_read (reader, doc, &error)) {
854
- ERREXIT ("Could not read BSON from %s: %s", path, error.message);
855
- }
856
- bson_json_reader_destroy (reader);
857
- return doc;
858
- }
859
-
860
- void
861
- args_parse (bson_t *args, int argc, char **argv)
862
- {
863
- int i;
864
-
865
- if (argc % 2 != 0) {
866
- ERREXIT ("Invalid arguments, expected list of key-value pairs.");
867
- }
868
-
869
- for (i = 0; i < argc; i++) {
870
- for (i = 0; i < argc; i += 2) {
871
- if (0 != strncmp (argv[i], "--", 2)) {
872
- ERREXIT ("Malformed option: %s", argv[i]);
873
- }
874
- bson_append_utf8 (args, argv[i] + 2, -1, argv[i + 1], -1);
875
- }
876
- }
877
- }
878
-
879
- const char *
880
- bson_get_utf8 (bson_t *bson, const char *dotkey, const char *default_value)
881
- {
882
- bson_iter_t iter;
883
-
884
- bson_iter_init (&iter, bson);
885
- if (bson_iter_find_descendant (&iter, dotkey, &iter) &&
886
- BSON_ITER_HOLDS_UTF8 (&iter)) {
887
- return bson_iter_utf8 (&iter, NULL);
888
- }
889
- return default_value;
890
- }
891
-
892
- const char *
893
- bson_req_utf8 (bson_t *bson, const char *dotkey)
894
- {
895
- const char *ret;
896
-
897
- ret = bson_get_utf8 (bson, dotkey, NULL);
898
- if (!ret) {
899
- ERREXIT ("Required field missing: '%s'", dotkey);
900
- }
901
- return ret;
902
- }
903
-
904
- const uint8_t *
905
- bson_get_bin (bson_t *bson, const char *dotkey, uint32_t *len)
906
- {
907
- bson_iter_t iter;
908
- bson_iter_t subiter;
909
- bson_subtype_t subtype;
910
- const uint8_t *data = NULL;
911
-
912
- bson_iter_init (&iter, bson);
913
- if (bson_iter_find_descendant (&iter, dotkey, &subiter) &&
914
- BSON_ITER_HOLDS_BINARY (&subiter)) {
915
- bson_iter_binary (&subiter, &subtype, len, &data);
916
- }
917
- return data;
918
- }
919
-
920
- const uint8_t *
921
- bson_req_bin (bson_t *bson, const char *dotkey, uint32_t *len)
922
- {
923
- const uint8_t *ret;
924
-
925
- ret = bson_get_bin (bson, dotkey, len);
926
- if (!ret) {
927
- ERREXIT ("Required field missing: '%s'", dotkey);
928
- }
929
- return ret;
930
- }
931
-
932
- bson_t *
933
- bson_get_json (bson_t *bson, const char *dotkey)
934
- {
935
- const char *path;
936
-
937
- path = bson_get_utf8 (bson, dotkey, NULL);
938
- if (!path) {
939
- return NULL;
940
- }
941
- return util_read_json_file (path);
942
- }
943
-
944
- bson_t *
945
- bson_req_json (bson_t *bson, const char *dotkey)
946
- {
947
- bson_t *ret;
948
-
949
- ret = bson_get_json (bson, dotkey);
950
- if (!ret) {
951
- ERREXIT ("Required field missing: '%s'", dotkey);
952
- }
953
- return ret;
954
- }
955
-
956
- bool
957
- bson_get_bool (bson_t *bson, const char *dotkey, bool default_value)
958
- {
959
- const char *as_str;
960
-
961
- as_str = bson_get_utf8 (bson, dotkey, NULL);
962
- if (!as_str) {
963
- return default_value;
964
- }
965
- if (0 == bson_strcasecmp (as_str, "true") || 0 == strcmp (as_str, "1")) {
966
- return true;
967
- }
968
- return default_value;
707
+ if (!ret && state_machine->trace) {
708
+ MONGOC_DEBUG("Error: %s", error->message);
709
+ }
710
+ mongocrypt_binary_destroy(bin);
711
+ return ret;
712
+ }
713
+
714
+ bson_t *util_read_json_file(const char *path) {
715
+ bson_json_reader_t *reader;
716
+ bson_error_t error;
717
+ bson_t *doc;
718
+
719
+ reader = bson_json_reader_new_from_file(path, &error);
720
+ if (!reader) {
721
+ ERREXIT("Error opening %s: %s", path, error.message);
722
+ }
723
+
724
+ doc = bson_new();
725
+ if (1 != bson_json_reader_read(reader, doc, &error)) {
726
+ ERREXIT("Could not read BSON from %s: %s", path, error.message);
727
+ }
728
+ bson_json_reader_destroy(reader);
729
+ return doc;
730
+ }
731
+
732
+ void args_parse(bson_t *args, int argc, char **argv) {
733
+ int i;
734
+
735
+ if (argc % 2 != 0) {
736
+ ERREXIT("Invalid arguments, expected list of key-value pairs.");
737
+ }
738
+
739
+ for (i = 0; i < argc; i++) {
740
+ for (i = 0; i < argc; i += 2) {
741
+ if (0 != strncmp(argv[i], "--", 2)) {
742
+ ERREXIT("Malformed option: %s", argv[i]);
743
+ }
744
+ bson_append_utf8(args, argv[i] + 2, -1, argv[i + 1], -1);
745
+ }
746
+ }
747
+ }
748
+
749
+ const char *bson_get_utf8(bson_t *bson, const char *dotkey, const char *default_value) {
750
+ bson_iter_t iter;
751
+
752
+ bson_iter_init(&iter, bson);
753
+ if (bson_iter_find_descendant(&iter, dotkey, &iter) && BSON_ITER_HOLDS_UTF8(&iter)) {
754
+ return bson_iter_utf8(&iter, NULL);
755
+ }
756
+ return default_value;
757
+ }
758
+
759
+ const char *bson_req_utf8(bson_t *bson, const char *dotkey) {
760
+ const char *ret;
761
+
762
+ ret = bson_get_utf8(bson, dotkey, NULL);
763
+ if (!ret) {
764
+ ERREXIT("Required field missing: '%s'", dotkey);
765
+ }
766
+ return ret;
767
+ }
768
+
769
+ const uint8_t *bson_get_bin(bson_t *bson, const char *dotkey, uint32_t *len) {
770
+ bson_iter_t iter;
771
+ bson_iter_t subiter;
772
+ bson_subtype_t subtype;
773
+ const uint8_t *data = NULL;
774
+
775
+ bson_iter_init(&iter, bson);
776
+ if (bson_iter_find_descendant(&iter, dotkey, &subiter) && BSON_ITER_HOLDS_BINARY(&subiter)) {
777
+ bson_iter_binary(&subiter, &subtype, len, &data);
778
+ }
779
+ return data;
780
+ }
781
+
782
+ const uint8_t *bson_req_bin(bson_t *bson, const char *dotkey, uint32_t *len) {
783
+ const uint8_t *ret;
784
+
785
+ ret = bson_get_bin(bson, dotkey, len);
786
+ if (!ret) {
787
+ ERREXIT("Required field missing: '%s'", dotkey);
788
+ }
789
+ return ret;
790
+ }
791
+
792
+ bson_t *bson_get_json(bson_t *bson, const char *dotkey) {
793
+ const char *path;
794
+
795
+ path = bson_get_utf8(bson, dotkey, NULL);
796
+ if (!path) {
797
+ return NULL;
798
+ }
799
+ return util_read_json_file(path);
800
+ }
801
+
802
+ bson_t *bson_req_json(bson_t *bson, const char *dotkey) {
803
+ bson_t *ret;
804
+
805
+ ret = bson_get_json(bson, dotkey);
806
+ if (!ret) {
807
+ ERREXIT("Required field missing: '%s'", dotkey);
808
+ }
809
+ return ret;
810
+ }
811
+
812
+ bool bson_get_bool(bson_t *bson, const char *dotkey, bool default_value) {
813
+ const char *as_str;
814
+
815
+ as_str = bson_get_utf8(bson, dotkey, NULL);
816
+ if (!as_str) {
817
+ return default_value;
818
+ }
819
+ if (0 == bson_strcasecmp(as_str, "true") || 0 == strcmp(as_str, "1")) {
820
+ return true;
821
+ }
822
+ return default_value;
969
823
  }