libmongocrypt-helper 1.7.4.0.1002 → 1.11.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (600) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +40 -5
  3. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +29 -24
  4. data/ext/libmongocrypt/libmongocrypt/CODEOWNERS +1 -4
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +522 -0
  6. data/ext/libmongocrypt/libmongocrypt/README.md +36 -40
  7. data/ext/libmongocrypt/libmongocrypt/bindings/cs/CMakeLists.txt +1 -0
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Driver.snk +0 -0
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/AssemblyInfo.cs +2 -2
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Binary.cs +16 -2
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClientFactory.cs +8 -4
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +35 -3
  14. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/LibraryLoader.cs +81 -44
  15. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/MongoDB.Libmongocrypt.csproj +2 -1
  16. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  17. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  18. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/MongoDB.Libmongocrypt.Test.csproj +2 -0
  19. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test32/MongoDB.Libmongocrypt.Test32.csproj +2 -0
  20. data/ext/libmongocrypt/libmongocrypt/bindings/cs/README.md +3 -0
  21. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +22 -26
  22. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.config +3 -0
  23. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.sh +0 -0
  24. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/build.gradle.kts +28 -0
  25. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/java/com/mongodb/crypt/benchmark/BenchmarkRunner.java +217 -0
  26. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/resources/keyDocument.json +24 -0
  27. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +22 -7
  28. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.jar +0 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.properties +1 -1
  30. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew +154 -108
  31. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew.bat +7 -18
  32. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/settings.gradle.kts +1 -0
  33. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPI.java +41 -6
  34. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPIHelper.java +5 -5
  35. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CipherCallback.java +27 -1
  36. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoCryptImpl.java +34 -19
  37. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoExplicitEncryptOptions.java +6 -4
  38. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/jni-config.json +180 -0
  39. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/reflect-config.json +134 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +50 -6
  41. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/{python/test/data/fle2-find-range-explicit → java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2}/int32/rangeopts.json +3 -0
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +4 -771
  44. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +86 -0
  45. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +41 -20
  46. data/ext/libmongocrypt/libmongocrypt/bindings/python/RELEASE.rst +6 -24
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +4 -13
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/hatch_build.py +36 -0
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/libmongocrypt-version.txt +1 -0
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/__init__.py +2 -2
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/auto_encrypter.py +61 -0
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/credentials.py +156 -0
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/explicit_encrypter.py +156 -0
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/state_machine.py +149 -0
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/auto_encrypter.py +2 -46
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binary.py +14 -17
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +232 -296
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +6 -31
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/credentials.py +2 -121
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/crypto.py +31 -20
  61. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/errors.py +2 -2
  62. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +2 -233
  63. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +168 -254
  64. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/options.py +265 -0
  65. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/state_machine.py +2 -141
  66. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/auto_encrypter.py +61 -0
  67. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/credentials.py +156 -0
  68. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/explicit_encrypter.py +156 -0
  69. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/state_machine.py +149 -0
  70. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  71. data/ext/libmongocrypt/libmongocrypt/bindings/python/pyproject.toml +118 -0
  72. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +97 -61
  73. data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements-test.txt +7 -0
  74. data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements.txt +4 -0
  75. data/ext/libmongocrypt/libmongocrypt/bindings/python/sbom.json +76 -0
  76. data/ext/libmongocrypt/libmongocrypt/bindings/python/strip_header.py +6 -7
  77. data/ext/libmongocrypt/libmongocrypt/bindings/python/synchro.py +64 -0
  78. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +2 -10
  79. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/collection-info.json +1 -1
  80. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/command.json +1 -1
  81. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/compact/success/encrypted-payload.json +21 -21
  82. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-command-reply.json +1 -1
  83. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-field-config-map.json +1 -1
  84. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  85. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/rangeopts.json +14 -0
  86. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-azure.json +1 -1
  87. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-gcp.json +1 -1
  88. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document.json +1 -1
  89. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-filter.json +1 -1
  90. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/list-collections-filter.json +1 -1
  91. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-command.json +1 -1
  92. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-reply.json +1 -1
  93. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/schema-map.json +1 -1
  94. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/keyDocument.json +24 -0
  95. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/perf_test.py +165 -0
  96. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_binding.py +8 -12
  97. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_crypto.py +9 -11
  98. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +991 -343
  99. data/ext/libmongocrypt/libmongocrypt/bindings/python/update-sbom.sh +14 -0
  100. data/ext/libmongocrypt/libmongocrypt/cmake/FetchMongoC.cmake +19 -1
  101. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +31 -6
  102. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +20 -227
  103. data/ext/libmongocrypt/libmongocrypt/cmake/Patch.cmake +54 -0
  104. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  105. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  106. data/ext/libmongocrypt/libmongocrypt/doc/img/cli-icon.png +0 -0
  107. data/ext/libmongocrypt/libmongocrypt/doc/img/reference-targets.png +0 -0
  108. data/ext/libmongocrypt/libmongocrypt/doc/releasing.md +153 -0
  109. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  110. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version.py +61 -28
  111. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version_selftest.sh +73 -0
  112. data/ext/libmongocrypt/libmongocrypt/etc/cyclonedx.sbom.json +108 -0
  113. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  114. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  115. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  116. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  117. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  118. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  119. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  120. data/ext/libmongocrypt/libmongocrypt/etc/libbson-remove-GCC-diagnostic-pragma.patch +27 -0
  121. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-alpine-arm-fix.patch +17 -0
  122. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  123. data/ext/libmongocrypt/libmongocrypt/etc/packager.py +120 -91
  124. data/ext/libmongocrypt/libmongocrypt/etc/purls.txt +14 -0
  125. data/ext/libmongocrypt/libmongocrypt/etc/repo_config.yaml +56 -0
  126. data/ext/libmongocrypt/libmongocrypt/etc/silk-create-asset-group.sh +70 -0
  127. data/ext/libmongocrypt/libmongocrypt/etc/ssdlc_compliance_report.md +37 -0
  128. data/ext/libmongocrypt/libmongocrypt/etc/third_party_vulnerabilities.md +42 -0
  129. data/ext/libmongocrypt/libmongocrypt/integrating.md +18 -1
  130. data/ext/libmongocrypt/libmongocrypt/kms-message/CMakeLists.txt +11 -3
  131. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_gcp_request.c +1 -1
  132. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer.c +17 -0
  133. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer_private.h +6 -0
  134. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_request.c +211 -1
  135. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_response.c +163 -0
  136. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_tag_type_private.h +2 -1
  137. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_request.h +17 -0
  138. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_response.h +6 -0
  139. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_port.c +3 -2
  140. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request.c +4 -2
  141. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.c +2 -2
  142. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kmip_reader_writer.c +23 -2
  143. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  144. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  145. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +183 -248
  146. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  147. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  148. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  149. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  150. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  151. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  152. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  153. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +21 -11
  154. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +175 -99
  155. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  156. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +69 -70
  157. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +445 -439
  158. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  159. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  160. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  161. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  162. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +103 -0
  163. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +28 -31
  164. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +173 -0
  165. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  166. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +130 -0
  167. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +36 -44
  168. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +382 -0
  169. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  170. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  171. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  172. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  173. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +454 -325
  174. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  175. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  176. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  177. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  178. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  179. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  180. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  181. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +56 -56
  182. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +520 -580
  183. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +47 -66
  184. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +67 -76
  185. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +201 -190
  186. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +55 -42
  187. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +809 -558
  188. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +177 -201
  189. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +54 -53
  190. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +188 -240
  191. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +43 -35
  192. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +484 -337
  193. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  194. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  195. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +87 -65
  196. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +153 -125
  197. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  198. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  199. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  200. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  201. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  202. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +461 -499
  203. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +256 -334
  204. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  205. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  206. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  207. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  208. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  209. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  210. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  211. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +1 -9
  212. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  213. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  214. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +442 -565
  215. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  216. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  217. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  218. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +104 -132
  219. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +16 -24
  220. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +110 -93
  221. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  222. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  223. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  224. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  225. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  226. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  227. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1145 -1567
  228. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +510 -476
  229. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  230. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2775 -2697
  231. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +189 -184
  232. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  233. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +990 -1139
  234. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +23 -24
  235. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  236. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  237. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  238. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +42 -44
  239. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +292 -272
  240. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +70 -110
  241. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +1010 -1033
  242. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  243. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  244. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +127 -120
  245. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1692 -1611
  246. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  247. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  248. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +31 -36
  249. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1923 -1479
  250. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  251. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +124 -107
  252. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +925 -419
  253. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +99 -122
  254. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  255. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  256. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  257. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  258. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  259. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +98 -136
  260. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +924 -1339
  261. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +199 -313
  262. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +83 -79
  263. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  264. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +64 -73
  265. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  266. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  267. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/bypassQueryAnalysis/payload.json +53 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd-to-mongocryptd.json +23 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd.json +20 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd-to-mongocryptd.json +50 -0
  271. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd.json +20 -0
  272. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/collinfo.json +44 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-field-map.json +24 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-payload-pattern.json +53 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/mongocryptd-reply.json +62 -0
  276. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd-to-mongocryptd.json +30 -0
  277. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd.json +17 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/mongocryptd-reply.json +39 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/payload.json +21 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/missing-key-id/collinfo.json +20 -0
  281. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/collinfo.json +9 -0
  282. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/encrypted-payload.json +4 -0
  283. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/cmd.json +1 -0
  284. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/collinfo.json +63 -0
  285. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-field-config-map.json +61 -0
  286. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload-range-v2.json +37 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload.json +29 -0
  288. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/cmd.json +1 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/collinfo.json +64 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload-range-v2.json +105 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload.json +30 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/cmd.json +1 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/collinfo.json +49 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-field-config-map.json +47 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-payload.json +23 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/collinfo.json +15 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-field-config-map.json +10 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload-range-v2.json +104 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload.json +6 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/collinfo.json +4 -4
  303. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +5 -5
  304. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  314. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  315. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  316. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  317. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  318. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  319. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  320. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  323. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  324. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  325. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  326. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  327. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  328. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  329. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  330. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  331. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  332. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  333. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  334. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  335. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  336. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  337. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  338. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  339. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  340. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  341. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  342. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  343. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  344. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  345. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  346. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  347. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  348. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  349. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  350. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  351. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  352. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  353. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  354. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  355. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  356. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  357. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  358. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  359. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  360. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  361. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  362. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  363. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  364. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  365. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  366. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  367. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  368. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  369. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  370. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  371. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  372. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  373. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  374. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  375. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  376. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  377. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  378. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  379. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  380. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  381. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  382. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  383. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  384. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  392. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  393. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  394. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  395. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  396. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  397. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  398. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  399. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  400. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  401. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/decrypt-response.txt +16 -0
  402. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/encrypt-response.txt +16 -0
  403. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/oauth-response.txt +19 -0
  404. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/cmd.json +9 -0
  405. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-field-map.json +19 -0
  406. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-payload.json +62 -0
  407. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/mongocryptd-reply.json +69 -0
  408. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/cmd.json +11 -0
  409. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-field-map.json +19 -0
  410. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-payload.json +40 -0
  411. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/mongocryptd-reply.json +47 -0
  412. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_decimal128.cstruct +1 -1
  413. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_double.cstruct +8637 -7958
  414. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int32.cstruct +5522 -1382
  415. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int64.cstruct +5042 -1262
  416. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128.cstruct +1 -1
  417. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128_precision.cstruct +1 -1
  418. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double.cstruct +1 -1
  419. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double_precision.cstruct +2 -2
  420. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int32.cstruct +1 -1
  421. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int64.cstruct +1 -1
  422. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/cmd.json +8 -0
  423. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-field-map.json +19 -0
  424. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-payload.json +53 -0
  425. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/mongocryptd-reply.json +58 -0
  426. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/cmd.json +11 -0
  427. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-field-map.json +19 -0
  428. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-payload.json +40 -0
  429. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/mongocryptd-reply.json +45 -0
  430. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/expected.json +26 -0
  431. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/to-encrypt.json +20 -0
  432. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/expected.json +26 -0
  433. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/to-encrypt.json +20 -0
  434. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-double/expected.json +8 -0
  435. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32/expected.json +8 -0
  436. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32-defaults/expected.json +8 -0
  437. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  438. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  439. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  440. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  441. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  442. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  443. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  444. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  445. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  446. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  447. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  448. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +30 -0
  449. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +25 -0
  450. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +25 -0
  451. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  452. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +279 -323
  453. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  454. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  455. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  456. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +60 -73
  457. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  458. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +129 -0
  459. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  460. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  461. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +248 -0
  462. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  463. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  464. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  465. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  466. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +421 -388
  467. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +974 -825
  468. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +499 -481
  469. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +312 -148
  470. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  471. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +249 -213
  472. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  473. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +632 -808
  474. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +22 -2
  475. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  476. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  477. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +118 -37
  478. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  479. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  480. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cleanup.c +374 -0
  481. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +410 -445
  482. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +798 -812
  483. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +142 -135
  484. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +70 -71
  485. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  486. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  487. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +870 -1045
  488. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +5183 -4717
  489. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  490. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +1093 -1178
  491. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +348 -420
  492. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  493. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  494. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  495. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  496. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  497. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  498. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +705 -368
  499. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  500. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  501. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  502. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +1073 -690
  503. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-opts.c +42 -0
  504. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  505. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +381 -451
  506. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +55 -67
  507. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +7 -10
  508. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +879 -918
  509. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +119 -169
  510. data/ext/libmongocrypt/libmongocrypt/test/test-named-kms-providers.c +2381 -0
  511. data/ext/libmongocrypt/libmongocrypt/test/util/HELP.autogen +3 -1
  512. data/ext/libmongocrypt/libmongocrypt/test/util/README.md +1 -0
  513. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +512 -559
  514. data/ext/libmongocrypt/libmongocrypt/test/util/make_includes.py +1 -1
  515. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +771 -882
  516. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  517. data/lib/libmongocrypt_helper/version.rb +2 -2
  518. metadata +245 -111
  519. checksums.yaml.gz.sig +0 -0
  520. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +0 -1
  521. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  522. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  523. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +0 -81
  524. data/ext/libmongocrypt/libmongocrypt/bindings/node/LICENSE +0 -201
  525. data/ext/libmongocrypt/libmongocrypt/bindings/node/binding.gyp +0 -79
  526. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/README.hbs +0 -44
  527. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +0 -39
  528. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +0 -515
  529. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +0 -420
  530. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/buffer_pool.js +0 -123
  531. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +0 -699
  532. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +0 -100
  533. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  534. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/cryptoCallbacks.js +0 -87
  535. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +0 -42
  536. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js +0 -66
  537. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +0 -487
  538. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +0 -16051
  539. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +0 -81
  540. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +0 -929
  541. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.h +0 -114
  542. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +0 -953
  543. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/buffer_pool.test.js +0 -91
  544. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +0 -701
  545. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  546. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +0 -284
  547. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/README.md +0 -5
  548. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/cmd.json +0 -6
  549. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/collection-info.json +0 -37
  550. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document-nested.json +0 -8
  551. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document.json +0 -11
  552. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encryptedFields.json +0 -30
  553. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key-document.json +0 -32
  554. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key1-document.json +0 -30
  555. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/mongocryptd-reply.json +0 -18
  556. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +0 -48
  557. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +0 -59
  558. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +0 -29
  559. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +0 -331
  560. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/mongodb_reporter.js +0 -325
  561. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +0 -84
  562. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  563. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +0 -12
  564. data/ext/libmongocrypt/libmongocrypt/debian/build_snapshot.sh +0 -79
  565. data/ext/libmongocrypt/libmongocrypt/debian/changelog +0 -105
  566. data/ext/libmongocrypt/libmongocrypt/debian/compat +0 -1
  567. data/ext/libmongocrypt/libmongocrypt/debian/control +0 -41
  568. data/ext/libmongocrypt/libmongocrypt/debian/copyright +0 -129
  569. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +0 -23
  570. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.dirs +0 -2
  571. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.install +0 -5
  572. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.dirs +0 -1
  573. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.install +0 -1
  574. data/ext/libmongocrypt/libmongocrypt/debian/rules +0 -46
  575. data/ext/libmongocrypt/libmongocrypt/debian/source/format +0 -1
  576. data/ext/libmongocrypt/libmongocrypt/debian/source/lintian-overrides +0 -3
  577. data/ext/libmongocrypt/libmongocrypt/debian/source/options +0 -1
  578. data/ext/libmongocrypt/libmongocrypt/debian/watch +0 -3
  579. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  580. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/mongocryptd-reply.json +0 -72
  581. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  582. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  583. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  584. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  585. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  586. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  587. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  588. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  589. data.tar.gz.sig +0 -0
  590. metadata.gz.sig +0 -0
  591. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
  592. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
  593. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
  594. /data/ext/libmongocrypt/libmongocrypt/bindings/{java/mongocrypt/src/test/resources/fle2-find-range-explicit → python/test/data/fle2-find-rangePreview-explicit}/int32/rangeopts.json +0 -0
  595. /data/ext/libmongocrypt/libmongocrypt/{test/data/fle2-find-range-explicit/int32-nominmax → bindings/python/test/data/fle2-find-rangePreview-explicit/int32}/value-to-encrypt.json +0 -0
  596. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-decrypt-reply.txt → test/data/kms-aws/decrypt-response.txt} +0 -0
  597. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-encrypt-reply.txt → test/data/kms-aws/encrypt-response.txt} +0 -0
  598. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/decrypt-response.txt +0 -0
  599. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/encrypt-response.txt +0 -0
  600. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/oauth-response.txt +0 -0
@@ -16,597 +16,550 @@
16
16
 
17
17
  #define MONGOC_LOG_DOMAIN "csfle"
18
18
 
19
- #include <mongocrypt.h>
20
- #include <mongoc/mongoc.h>
21
- #include <kms_message/kms_b64.h>
22
19
  #include <fcntl.h>
20
+ #include <kms_message/kms_b64.h>
21
+ #include <mongoc/mongoc.h>
22
+ #include <mongocrypt.h>
23
23
 
24
24
  #include "util.h"
25
25
 
26
26
  const char *help_text = ""
27
27
  #include "HELP.autogen"
28
- ;
29
-
30
- static void
31
- _exit_help (void)
32
- {
33
- printf ("Usage: csfle <function> [options...]\n");
34
- printf ("%s", help_text);
35
- exit (0);
28
+ ;
29
+
30
+ static void _exit_help(void) {
31
+ printf("Usage: csfle <function> [options...]\n");
32
+ printf("%s", help_text);
33
+ exit(0);
36
34
  }
37
35
 
38
- static void
39
- set_kms_providers (mongocrypt_t *crypt, bson_t *args)
40
- {
41
- bson_t *kms_providers;
42
- mongocrypt_binary_t *bin;
36
+ static void set_kms_providers(mongocrypt_t *crypt, bson_t *args) {
37
+ bson_t *kms_providers;
38
+ mongocrypt_binary_t *bin;
43
39
 
44
- kms_providers = bson_get_json (args, "kms_providers_file");
45
- if (!kms_providers) {
46
- kms_providers = util_read_json_file (".csfle/kms_providers.json");
47
- }
40
+ kms_providers = bson_get_json(args, "kms_providers_file");
41
+ if (!kms_providers) {
42
+ kms_providers = util_read_json_file(".csfle/kms_providers.json");
43
+ }
48
44
 
49
- bin = util_bson_to_bin (kms_providers);
50
- if (!mongocrypt_setopt_kms_providers (crypt, bin)) {
51
- ERREXIT_MONGOCRYPT (crypt);
52
- }
53
- mongocrypt_binary_destroy (bin);
45
+ bin = util_bson_to_bin(kms_providers);
46
+ if (!mongocrypt_setopt_kms_providers(crypt, bin)) {
47
+ ERREXIT_MONGOCRYPT(crypt);
48
+ }
49
+ mongocrypt_binary_destroy(bin);
54
50
 
55
- bson_destroy (kms_providers);
51
+ bson_destroy(kms_providers);
56
52
  }
57
53
 
58
- static mongocrypt_t *
59
- crypt_new (bson_t *args)
60
- {
61
- mongocrypt_t *crypt;
62
- bson_t *schema_map;
63
- mongocrypt_binary_t *bin;
64
-
65
- crypt = mongocrypt_new ();
66
- if (!mongocrypt_setopt_log_handler (crypt, _log_to_stdout, NULL)) {
67
- ERREXIT_MONGOCRYPT (crypt);
68
- }
69
-
70
- set_kms_providers (crypt, args);
71
-
72
- schema_map = bson_get_json (args, "schema_map_file");
73
- if (schema_map) {
74
- bin = util_bson_to_bin (schema_map);
75
- if (!mongocrypt_setopt_schema_map (crypt, bin)) {
76
- ERREXIT_MONGOCRYPT (crypt);
77
- }
78
- mongocrypt_binary_destroy (bin);
79
- }
80
- bson_destroy (schema_map);
81
-
82
- if (!mongocrypt_init (crypt)) {
83
- ERREXIT_MONGOCRYPT (crypt);
84
- }
85
-
86
- return crypt;
54
+ static mongocrypt_t *crypt_new(bson_t *args) {
55
+ mongocrypt_t *crypt;
56
+ bson_t *schema_map;
57
+ mongocrypt_binary_t *bin;
58
+
59
+ crypt = mongocrypt_new();
60
+ if (!mongocrypt_setopt_log_handler(crypt, _log_to_stdout, NULL)) {
61
+ ERREXIT_MONGOCRYPT(crypt);
62
+ }
63
+
64
+ set_kms_providers(crypt, args);
65
+
66
+ schema_map = bson_get_json(args, "schema_map_file");
67
+ if (schema_map) {
68
+ bin = util_bson_to_bin(schema_map);
69
+ if (!mongocrypt_setopt_schema_map(crypt, bin)) {
70
+ ERREXIT_MONGOCRYPT(crypt);
71
+ }
72
+ mongocrypt_binary_destroy(bin);
73
+ }
74
+ bson_destroy(schema_map);
75
+
76
+ if (!mongocrypt_init(crypt)) {
77
+ ERREXIT_MONGOCRYPT(crypt);
78
+ }
79
+
80
+ return crypt;
87
81
  }
88
82
 
89
83
  typedef struct {
90
- mongoc_client_t *keyvault_client;
91
- mongoc_client_t *mongocryptd_client;
92
- mongoc_client_t *mongodb_client;
84
+ mongoc_client_t *keyvault_client;
85
+ mongoc_client_t *mongocryptd_client;
86
+ mongoc_client_t *mongodb_client;
93
87
 
94
- char *keyvault_db;
95
- char *keyvault_coll;
88
+ char *keyvault_db;
89
+ char *keyvault_coll;
96
90
 
97
- _state_machine_t machine;
91
+ _state_machine_t machine;
98
92
  } state_t;
99
93
 
100
- static void
101
- state_init (state_t *state, bson_t *args, mongocrypt_ctx_t *ctx)
102
- {
103
- const char *keyvault_ns;
104
- char *pos;
105
-
106
- state->keyvault_client = mongoc_client_new (
107
- bson_get_utf8 (args, "mongodb_uri", "mongodb://localhost:27017"));
108
- state->mongocryptd_client = mongoc_client_new (
109
- bson_get_utf8 (args, "mongocryptd_uri", "mongodb://localhost:27020"));
110
- state->mongodb_client = mongoc_client_new (
111
- bson_get_utf8 (args, "mongodb_uri", "mongodb://localhost:27017"));
112
-
113
- keyvault_ns = bson_get_utf8 (args, "keyvault_ns", "keyvault.datakeys");
114
- pos = strstr (keyvault_ns, ".");
115
- if (!pos) {
116
- ERREXIT ("Key vault collection namespace invalid: %s", keyvault_ns);
117
- }
118
- state->keyvault_db = bson_strndup (keyvault_ns, pos - keyvault_ns);
119
- state->keyvault_coll = bson_strdup (pos + 1);
120
-
121
- state->machine.ctx = ctx;
122
- state->machine.keyvault_coll = mongoc_client_get_collection (
123
- state->keyvault_client, state->keyvault_db, state->keyvault_coll);
124
- state->machine.mongocryptd_client = state->mongocryptd_client;
125
- state->machine.collinfo_client = state->mongodb_client;
126
- state->machine.db_name = bson_get_utf8 (args, "db", NULL);
127
- state->machine.trace = bson_get_bool (args, "trace", false);
128
- state->machine.tls_ca_file = bson_get_utf8 (args, "tls_ca_file", NULL);
129
- state->machine.tls_certificate_key_file =
130
- bson_get_utf8 (args, "tls_certificate_key_file", NULL);
94
+ static void state_init(state_t *state, bson_t *args, mongocrypt_ctx_t *ctx) {
95
+ const char *keyvault_ns;
96
+ char *pos;
97
+
98
+ state->keyvault_client = mongoc_client_new(bson_get_utf8(args, "mongodb_uri", "mongodb://localhost:27017"));
99
+ state->mongocryptd_client = mongoc_client_new(bson_get_utf8(args, "mongocryptd_uri", "mongodb://localhost:27020"));
100
+ state->mongodb_client = mongoc_client_new(bson_get_utf8(args, "mongodb_uri", "mongodb://localhost:27017"));
101
+
102
+ keyvault_ns = bson_get_utf8(args, "keyvault_ns", "keyvault.datakeys");
103
+ pos = strstr(keyvault_ns, ".");
104
+ if (!pos) {
105
+ ERREXIT("Key vault collection namespace invalid: %s", keyvault_ns);
106
+ }
107
+ state->keyvault_db = bson_strndup(keyvault_ns, pos - keyvault_ns);
108
+ state->keyvault_coll = bson_strdup(pos + 1);
109
+
110
+ state->machine.ctx = ctx;
111
+ state->machine.keyvault_coll =
112
+ mongoc_client_get_collection(state->keyvault_client, state->keyvault_db, state->keyvault_coll);
113
+ state->machine.mongocryptd_client = state->mongocryptd_client;
114
+ state->machine.collinfo_client = state->mongodb_client;
115
+ state->machine.db_name = bson_get_utf8(args, "db", NULL);
116
+ state->machine.trace = bson_get_bool(args, "trace", false);
117
+ state->machine.tls_ca_file = bson_get_utf8(args, "tls_ca_file", NULL);
118
+ state->machine.tls_certificate_key_file = bson_get_utf8(args, "tls_certificate_key_file", NULL);
131
119
  }
132
120
 
133
- static void
134
- state_cleanup (state_t *state)
135
- {
136
- mongoc_collection_destroy (state->machine.keyvault_coll);
137
- mongoc_client_destroy (state->keyvault_client);
138
- mongoc_client_destroy (state->mongocryptd_client);
139
- mongoc_client_destroy (state->mongodb_client);
140
- bson_free (state->keyvault_db);
141
- bson_free (state->keyvault_coll);
121
+ static void state_cleanup(state_t *state) {
122
+ mongoc_collection_destroy(state->machine.keyvault_coll);
123
+ mongoc_client_destroy(state->keyvault_client);
124
+ mongoc_client_destroy(state->mongocryptd_client);
125
+ mongoc_client_destroy(state->mongodb_client);
126
+ bson_free(state->keyvault_db);
127
+ bson_free(state->keyvault_coll);
142
128
  }
143
129
 
144
- static void
145
- fn_createdatakey (bson_t *args)
146
- {
147
- state_t state;
148
- mongocrypt_t *crypt;
149
- mongocrypt_ctx_t *ctx;
150
- const char *kms_provider;
151
- bson_t result;
152
- bson_error_t error;
153
- char *result_utf8;
154
- mongocrypt_binary_t *bin;
155
-
156
- crypt = crypt_new (args);
157
- ctx = mongocrypt_ctx_new (crypt);
158
-
159
- kms_provider = bson_req_utf8 (args, "kms_provider");
160
-
161
- if (bson_has_field (args, "key_material")) {
162
- const char *key_material_base64 =
163
- bson_get_utf8 (args, "key_material", NULL);
164
- uint8_t key_material[512];
165
-
166
- int len = kms_message_b64_pton (
167
- key_material_base64, key_material, sizeof (key_material));
168
- if (len < 0) {
169
- ERREXIT ("Could not base64 decode: %s", key_material_base64);
170
- }
171
-
172
- bson_t *key_material_bson = BCON_NEW (
173
- "keyMaterial", BCON_BIN (BSON_SUBTYPE_BINARY, key_material, len));
174
- mongocrypt_binary_t *key_material_bin = mongocrypt_binary_new_from_data (
175
- (uint8_t *) bson_get_data (key_material_bson), key_material_bson->len);
176
- if (!mongocrypt_ctx_setopt_key_material (ctx, key_material_bin)) {
177
- ERREXIT_CTX (ctx);
178
- }
179
- bson_destroy (key_material_bson);
180
- }
181
-
182
- /* Set the key encryption key (KEK). */
183
- if (0 == strcmp ("aws", kms_provider)) {
184
- bson_t aws_kek = BSON_INITIALIZER;
185
-
186
- BSON_APPEND_UTF8 (&aws_kek, "provider", "aws");
187
- BSON_APPEND_UTF8 (
188
- &aws_kek, "region", bson_req_utf8 (args, "aws_kek_region"));
189
- BSON_APPEND_UTF8 (&aws_kek, "key", bson_req_utf8 (args, "aws_kek_key"));
190
-
191
- if (bson_has_field (args, "aws_kek_endpoint")) {
192
- BSON_APPEND_UTF8 (&aws_kek,
193
- "endpoint",
194
- bson_get_utf8 (args, "aws_kek_endpoint", NULL));
195
- }
196
- bin = util_bson_to_bin (&aws_kek);
197
- if (!mongocrypt_ctx_setopt_key_encryption_key (ctx, bin)) {
198
- ERREXIT_CTX (ctx);
199
- }
200
- mongocrypt_binary_destroy (bin);
201
- bson_destroy (&aws_kek);
202
- } else if (0 == strcmp ("local", kms_provider)) {
203
- bson_t local_kek = BSON_INITIALIZER;
204
-
205
- BSON_APPEND_UTF8 (&local_kek, "provider", "local");
206
- bin = util_bson_to_bin (&local_kek);
207
- if (!mongocrypt_ctx_setopt_key_encryption_key (ctx, bin)) {
208
- ERREXIT_CTX (ctx);
209
- }
210
- mongocrypt_binary_destroy (bin);
211
- bson_destroy (&local_kek);
212
- } else if (0 == strcmp ("azure", kms_provider)) {
213
- bson_t azure_kek = BSON_INITIALIZER;
214
-
215
- BSON_APPEND_UTF8 (&azure_kek, "provider", "azure");
216
- BSON_APPEND_UTF8 (&azure_kek,
217
- "keyVaultEndpoint",
218
- bson_req_utf8 (args, "azure_kek_keyvaultendpoint"));
219
- BSON_APPEND_UTF8 (
220
- &azure_kek, "keyName", bson_req_utf8 (args, "azure_kek_keyname"));
221
- if (bson_has_field (args, "azure_kek_keyversion")) {
222
- BSON_APPEND_UTF8 (&azure_kek,
223
- "keyVersion",
224
- bson_req_utf8 (args, "azure_kek_keyversion"));
225
- }
226
-
227
- bin = util_bson_to_bin (&azure_kek);
228
- if (!mongocrypt_ctx_setopt_key_encryption_key (ctx, bin)) {
229
- ERREXIT_CTX (ctx);
230
- }
231
- mongocrypt_binary_destroy (bin);
232
- bson_destroy (&azure_kek);
233
- } else if (0 == strcmp ("gcp", kms_provider)) {
234
- bson_t gcp_kek = BSON_INITIALIZER;
235
-
236
- BSON_APPEND_UTF8 (&gcp_kek, "provider", "gcp");
237
- if (bson_has_field (args, "gcp_kek_endpoint")) {
238
- BSON_APPEND_UTF8 (
239
- &gcp_kek, "endpoint", bson_req_utf8 (args, "gcp_kek_endpoint"));
240
- }
241
-
242
- BSON_APPEND_UTF8 (
243
- &gcp_kek, "projectId", bson_req_utf8 (args, "gcp_kek_projectid"));
244
- BSON_APPEND_UTF8 (
245
- &gcp_kek, "location", bson_req_utf8 (args, "gcp_kek_location"));
246
- BSON_APPEND_UTF8 (
247
- &gcp_kek, "keyRing", bson_req_utf8 (args, "gcp_kek_keyring"));
248
- BSON_APPEND_UTF8 (
249
- &gcp_kek, "keyName", bson_req_utf8 (args, "gcp_kek_keyname"));
250
-
251
- if (bson_has_field (args, "gcp_kek_keyversion")) {
252
- BSON_APPEND_UTF8 (
253
- &gcp_kek, "keyVersion", bson_req_utf8 (args, "gcp_kek_keyversion"));
254
- }
255
-
256
- bin = util_bson_to_bin (&gcp_kek);
257
- if (!mongocrypt_ctx_setopt_key_encryption_key (ctx, bin)) {
258
- ERREXIT_CTX (ctx);
259
- }
260
- mongocrypt_binary_destroy (bin);
261
- bson_destroy (&gcp_kek);
262
- } else if (0 == strcmp ("kmip", kms_provider)) {
263
- bson_t kmip_kek = BSON_INITIALIZER;
264
-
265
- BSON_APPEND_UTF8 (&kmip_kek, "provider", "kmip");
266
- if (bson_has_field (args, "kmip_kek_endpoint")) {
267
- BSON_APPEND_UTF8 (
268
- &kmip_kek, "endpoint", bson_req_utf8 (args, "kmip_kek_endpoint"));
269
- }
270
-
271
- if (bson_has_field (args, "kmip_kek_keyid")) {
272
- BSON_APPEND_UTF8 (
273
- &kmip_kek, "keyId", bson_req_utf8 (args, "kmip_kek_keyid"));
274
- }
275
-
276
- bin = util_bson_to_bin (&kmip_kek);
277
- if (!mongocrypt_ctx_setopt_key_encryption_key (ctx, bin)) {
278
- ERREXIT_CTX (ctx);
279
- }
280
- mongocrypt_binary_destroy (bin);
281
- bson_destroy (&kmip_kek);
282
- } else {
283
- ERREXIT ("Unknown KMS provider: %s", kms_provider);
284
- }
285
-
286
- if (!mongocrypt_ctx_datakey_init (ctx)) {
287
- ERREXIT_CTX (ctx);
288
- }
289
-
290
- state_init (&state, args, ctx);
291
-
292
- if (state.machine.trace) {
293
- MONGOC_DEBUG ("Running state machine");
294
- }
295
-
296
- if (!_csfle_state_machine_run (&state.machine, &result, &error)) {
297
- ERREXIT_BSON (&error);
298
- }
299
-
300
- if (state.machine.trace) {
301
- MONGOC_DEBUG ("Finished running state machine");
302
- }
303
-
304
- if (!mongoc_collection_insert_one (
305
- state.machine.keyvault_coll, &result, NULL, NULL, &error)) {
306
- ERREXIT_BSON (&error);
307
- }
308
-
309
- result_utf8 = bson_as_canonical_extended_json (&result, NULL);
310
- printf ("%s\n", result_utf8);
311
- bson_free (result_utf8);
312
-
313
- bson_destroy (&result);
314
- mongocrypt_ctx_destroy (ctx);
315
- mongocrypt_destroy (crypt);
316
- state_cleanup (&state);
130
+ static void fn_createdatakey(bson_t *args) {
131
+ state_t state;
132
+ mongocrypt_t *crypt;
133
+ mongocrypt_ctx_t *ctx;
134
+ const char *kms_provider;
135
+ bson_t result;
136
+ bson_error_t error;
137
+ char *result_utf8;
138
+ mongocrypt_binary_t *bin;
139
+
140
+ crypt = crypt_new(args);
141
+ ctx = mongocrypt_ctx_new(crypt);
142
+
143
+ kms_provider = bson_req_utf8(args, "kms_provider");
144
+
145
+ if (bson_has_field(args, "key_material")) {
146
+ const char *key_material_base64 = bson_get_utf8(args, "key_material", NULL);
147
+ uint8_t key_material[512];
148
+
149
+ int len = kms_message_b64_pton(key_material_base64, key_material, sizeof(key_material));
150
+ if (len < 0) {
151
+ ERREXIT("Could not base64 decode: %s", key_material_base64);
152
+ }
153
+
154
+ bson_t *key_material_bson = BCON_NEW("keyMaterial", BCON_BIN(BSON_SUBTYPE_BINARY, key_material, len));
155
+ mongocrypt_binary_t *key_material_bin =
156
+ mongocrypt_binary_new_from_data((uint8_t *)bson_get_data(key_material_bson), key_material_bson->len);
157
+ if (!mongocrypt_ctx_setopt_key_material(ctx, key_material_bin)) {
158
+ ERREXIT_CTX(ctx);
159
+ }
160
+ bson_destroy(key_material_bson);
161
+ }
162
+
163
+ /* Set the key encryption key (KEK). */
164
+ if (0 == strcmp("aws", kms_provider)) {
165
+ bson_t aws_kek = BSON_INITIALIZER;
166
+
167
+ BSON_APPEND_UTF8(&aws_kek, "provider", "aws");
168
+ BSON_APPEND_UTF8(&aws_kek, "region", bson_req_utf8(args, "aws_kek_region"));
169
+ BSON_APPEND_UTF8(&aws_kek, "key", bson_req_utf8(args, "aws_kek_key"));
170
+
171
+ if (bson_has_field(args, "aws_kek_endpoint")) {
172
+ BSON_APPEND_UTF8(&aws_kek, "endpoint", bson_get_utf8(args, "aws_kek_endpoint", NULL));
173
+ }
174
+ bin = util_bson_to_bin(&aws_kek);
175
+ if (!mongocrypt_ctx_setopt_key_encryption_key(ctx, bin)) {
176
+ ERREXIT_CTX(ctx);
177
+ }
178
+ mongocrypt_binary_destroy(bin);
179
+ bson_destroy(&aws_kek);
180
+ } else if (0 == strcmp("local", kms_provider)) {
181
+ bson_t local_kek = BSON_INITIALIZER;
182
+
183
+ BSON_APPEND_UTF8(&local_kek, "provider", "local");
184
+ bin = util_bson_to_bin(&local_kek);
185
+ if (!mongocrypt_ctx_setopt_key_encryption_key(ctx, bin)) {
186
+ ERREXIT_CTX(ctx);
187
+ }
188
+ mongocrypt_binary_destroy(bin);
189
+ bson_destroy(&local_kek);
190
+ } else if (0 == strcmp("azure", kms_provider)) {
191
+ bson_t azure_kek = BSON_INITIALIZER;
192
+
193
+ BSON_APPEND_UTF8(&azure_kek, "provider", "azure");
194
+ BSON_APPEND_UTF8(&azure_kek, "keyVaultEndpoint", bson_req_utf8(args, "azure_kek_keyvaultendpoint"));
195
+ BSON_APPEND_UTF8(&azure_kek, "keyName", bson_req_utf8(args, "azure_kek_keyname"));
196
+ if (bson_has_field(args, "azure_kek_keyversion")) {
197
+ BSON_APPEND_UTF8(&azure_kek, "keyVersion", bson_req_utf8(args, "azure_kek_keyversion"));
198
+ }
199
+
200
+ bin = util_bson_to_bin(&azure_kek);
201
+ if (!mongocrypt_ctx_setopt_key_encryption_key(ctx, bin)) {
202
+ ERREXIT_CTX(ctx);
203
+ }
204
+ mongocrypt_binary_destroy(bin);
205
+ bson_destroy(&azure_kek);
206
+ } else if (0 == strcmp("gcp", kms_provider)) {
207
+ bson_t gcp_kek = BSON_INITIALIZER;
208
+
209
+ BSON_APPEND_UTF8(&gcp_kek, "provider", "gcp");
210
+ if (bson_has_field(args, "gcp_kek_endpoint")) {
211
+ BSON_APPEND_UTF8(&gcp_kek, "endpoint", bson_req_utf8(args, "gcp_kek_endpoint"));
212
+ }
213
+
214
+ BSON_APPEND_UTF8(&gcp_kek, "projectId", bson_req_utf8(args, "gcp_kek_projectid"));
215
+ BSON_APPEND_UTF8(&gcp_kek, "location", bson_req_utf8(args, "gcp_kek_location"));
216
+ BSON_APPEND_UTF8(&gcp_kek, "keyRing", bson_req_utf8(args, "gcp_kek_keyring"));
217
+ BSON_APPEND_UTF8(&gcp_kek, "keyName", bson_req_utf8(args, "gcp_kek_keyname"));
218
+
219
+ if (bson_has_field(args, "gcp_kek_keyversion")) {
220
+ BSON_APPEND_UTF8(&gcp_kek, "keyVersion", bson_req_utf8(args, "gcp_kek_keyversion"));
221
+ }
222
+
223
+ bin = util_bson_to_bin(&gcp_kek);
224
+ if (!mongocrypt_ctx_setopt_key_encryption_key(ctx, bin)) {
225
+ ERREXIT_CTX(ctx);
226
+ }
227
+ mongocrypt_binary_destroy(bin);
228
+ bson_destroy(&gcp_kek);
229
+ } else if (0 == strcmp("kmip", kms_provider)) {
230
+ bson_t kmip_kek = BSON_INITIALIZER;
231
+
232
+ BSON_APPEND_UTF8(&kmip_kek, "provider", "kmip");
233
+ if (bson_has_field(args, "kmip_kek_endpoint")) {
234
+ BSON_APPEND_UTF8(&kmip_kek, "endpoint", bson_req_utf8(args, "kmip_kek_endpoint"));
235
+ }
236
+
237
+ if (bson_has_field(args, "kmip_kek_keyid")) {
238
+ BSON_APPEND_UTF8(&kmip_kek, "keyId", bson_req_utf8(args, "kmip_kek_keyid"));
239
+ }
240
+
241
+ if (bson_has_field(args, "kmip_kek_delegated")) {
242
+ BSON_APPEND_BOOL(&kmip_kek, "delegated", bson_get_bool(args, "kmip_kek_delegated", true));
243
+ }
244
+
245
+ bin = util_bson_to_bin(&kmip_kek);
246
+ if (!mongocrypt_ctx_setopt_key_encryption_key(ctx, bin)) {
247
+ ERREXIT_CTX(ctx);
248
+ }
249
+ mongocrypt_binary_destroy(bin);
250
+ bson_destroy(&kmip_kek);
251
+ } else {
252
+ ERREXIT("Unknown KMS provider: %s", kms_provider);
253
+ }
254
+
255
+ if (!mongocrypt_ctx_datakey_init(ctx)) {
256
+ ERREXIT_CTX(ctx);
257
+ }
258
+
259
+ state_init(&state, args, ctx);
260
+
261
+ if (state.machine.trace) {
262
+ MONGOC_DEBUG("Running state machine");
263
+ }
264
+
265
+ if (!_csfle_state_machine_run(&state.machine, &result, &error)) {
266
+ ERREXIT_BSON(&error);
267
+ }
268
+
269
+ if (state.machine.trace) {
270
+ MONGOC_DEBUG("Finished running state machine");
271
+ }
272
+
273
+ if (!mongoc_collection_insert_one(state.machine.keyvault_coll, &result, NULL, NULL, &error)) {
274
+ ERREXIT_BSON(&error);
275
+ }
276
+
277
+ result_utf8 = bson_as_canonical_extended_json(&result, NULL);
278
+ printf("%s\n", result_utf8);
279
+ bson_free(result_utf8);
280
+
281
+ bson_destroy(&result);
282
+ mongocrypt_ctx_destroy(ctx);
283
+ mongocrypt_destroy(crypt);
284
+ state_cleanup(&state);
317
285
  }
318
286
 
319
- static void
320
- fn_autoencrypt (bson_t *args)
321
- {
322
- state_t state;
323
- mongocrypt_t *crypt;
324
- mongocrypt_ctx_t *ctx;
325
- const char *db;
326
- mongocrypt_binary_t *bin;
327
- bson_t *cmd;
328
- bson_t result;
329
- bson_error_t error;
330
- char *result_utf8;
331
-
332
- crypt = crypt_new (args);
333
- ctx = mongocrypt_ctx_new (crypt);
334
-
335
- cmd = bson_get_json (args, "command_file");
336
- if (!cmd) {
337
- const char *cmd_utf8 = bson_req_utf8 (args, "command");
338
- cmd = bson_new_from_json (
339
- (const uint8_t *) cmd_utf8, strlen (cmd_utf8), &error);
340
- if (!cmd) {
341
- ERREXIT_BSON (&error);
342
- }
343
- }
344
-
345
- db = bson_req_utf8 (args, "db");
346
- bin = util_bson_to_bin (cmd);
347
- if (!mongocrypt_ctx_encrypt_init (ctx, db, -1, bin)) {
348
- ERREXIT_CTX (ctx);
349
- }
350
-
351
- state_init (&state, args, ctx);
352
-
353
- if (state.machine.trace) {
354
- MONGOC_INFO ("Running state machine");
355
- }
356
-
357
- if (!_csfle_state_machine_run (&state.machine, &result, &error)) {
358
- ERREXIT_BSON (&error);
359
- }
360
-
361
- if (state.machine.trace) {
362
- MONGOC_INFO ("Finished running state machine");
363
- }
364
-
365
- result_utf8 = bson_as_canonical_extended_json (&result, NULL);
366
- printf ("%s\n", result_utf8);
367
- bson_free (result_utf8);
368
-
369
- bson_destroy (cmd);
370
- mongocrypt_binary_destroy (bin);
371
- bson_destroy (&result);
372
- mongocrypt_ctx_destroy (ctx);
373
- mongocrypt_destroy (crypt);
374
- state_cleanup (&state);
287
+ static void fn_autoencrypt(bson_t *args) {
288
+ state_t state;
289
+ mongocrypt_t *crypt;
290
+ mongocrypt_ctx_t *ctx;
291
+ const char *db;
292
+ mongocrypt_binary_t *bin;
293
+ bson_t *cmd;
294
+ bson_t result;
295
+ bson_error_t error;
296
+ char *result_utf8;
297
+
298
+ crypt = crypt_new(args);
299
+ ctx = mongocrypt_ctx_new(crypt);
300
+
301
+ cmd = bson_get_json(args, "command_file");
302
+ if (!cmd) {
303
+ const char *cmd_utf8 = bson_req_utf8(args, "command");
304
+ cmd = bson_new_from_json((const uint8_t *)cmd_utf8, strlen(cmd_utf8), &error);
305
+ if (!cmd) {
306
+ ERREXIT_BSON(&error);
307
+ }
308
+ }
309
+
310
+ db = bson_req_utf8(args, "db");
311
+ bin = util_bson_to_bin(cmd);
312
+ if (!mongocrypt_ctx_encrypt_init(ctx, db, -1, bin)) {
313
+ ERREXIT_CTX(ctx);
314
+ }
315
+
316
+ state_init(&state, args, ctx);
317
+
318
+ if (state.machine.trace) {
319
+ MONGOC_INFO("Running state machine");
320
+ }
321
+
322
+ if (!_csfle_state_machine_run(&state.machine, &result, &error)) {
323
+ ERREXIT_BSON(&error);
324
+ }
325
+
326
+ if (state.machine.trace) {
327
+ MONGOC_INFO("Finished running state machine");
328
+ }
329
+
330
+ result_utf8 = bson_as_canonical_extended_json(&result, NULL);
331
+ printf("%s\n", result_utf8);
332
+ bson_free(result_utf8);
333
+
334
+ bson_destroy(cmd);
335
+ mongocrypt_binary_destroy(bin);
336
+ bson_destroy(&result);
337
+ mongocrypt_ctx_destroy(ctx);
338
+ mongocrypt_destroy(crypt);
339
+ state_cleanup(&state);
375
340
  }
376
341
 
377
- static void
378
- fn_autodecrypt (bson_t *args)
379
- {
380
- state_t state;
381
- mongocrypt_t *crypt;
382
- mongocrypt_ctx_t *ctx;
383
- mongocrypt_binary_t *bin;
384
- bson_t *doc;
385
- bson_t result;
386
- bson_error_t error;
387
- char *result_utf8;
388
-
389
- crypt = crypt_new (args);
390
- ctx = mongocrypt_ctx_new (crypt);
391
-
392
- doc = bson_get_json (args, "document_file");
393
- if (!doc) {
394
- const char *doc_utf8 = bson_req_utf8 (args, "document");
395
- doc = bson_new_from_json (
396
- (const uint8_t *) doc_utf8, strlen (doc_utf8), &error);
397
- if (!doc) {
398
- ERREXIT_BSON (&error);
399
- }
400
- }
401
-
402
- bin = util_bson_to_bin (doc);
403
- if (!mongocrypt_ctx_decrypt_init (ctx, bin)) {
404
- ERREXIT_CTX (ctx);
405
- }
406
-
407
- state_init (&state, args, ctx);
408
-
409
- if (state.machine.trace) {
410
- MONGOC_INFO ("Running state machine");
411
- }
412
-
413
- if (!_csfle_state_machine_run (&state.machine, &result, &error)) {
414
- ERREXIT_BSON (&error);
415
- }
416
-
417
- if (state.machine.trace) {
418
- MONGOC_INFO ("Finished running state machine");
419
- }
420
-
421
- result_utf8 = bson_as_canonical_extended_json (&result, NULL);
422
- printf ("%s\n", result_utf8);
423
- bson_free (result_utf8);
424
-
425
- bson_destroy (doc);
426
- mongocrypt_binary_destroy (bin);
427
- bson_destroy (&result);
428
- mongocrypt_ctx_destroy (ctx);
429
- mongocrypt_destroy (crypt);
430
- state_cleanup (&state);
342
+ static void fn_autodecrypt(bson_t *args) {
343
+ state_t state;
344
+ mongocrypt_t *crypt;
345
+ mongocrypt_ctx_t *ctx;
346
+ mongocrypt_binary_t *bin;
347
+ bson_t *doc;
348
+ bson_t result;
349
+ bson_error_t error;
350
+ char *result_utf8;
351
+
352
+ crypt = crypt_new(args);
353
+ ctx = mongocrypt_ctx_new(crypt);
354
+
355
+ doc = bson_get_json(args, "document_file");
356
+ if (!doc) {
357
+ const char *doc_utf8 = bson_req_utf8(args, "document");
358
+ doc = bson_new_from_json((const uint8_t *)doc_utf8, strlen(doc_utf8), &error);
359
+ if (!doc) {
360
+ ERREXIT_BSON(&error);
361
+ }
362
+ }
363
+
364
+ bin = util_bson_to_bin(doc);
365
+ if (!mongocrypt_ctx_decrypt_init(ctx, bin)) {
366
+ ERREXIT_CTX(ctx);
367
+ }
368
+
369
+ state_init(&state, args, ctx);
370
+
371
+ if (state.machine.trace) {
372
+ MONGOC_INFO("Running state machine");
373
+ }
374
+
375
+ if (!_csfle_state_machine_run(&state.machine, &result, &error)) {
376
+ ERREXIT_BSON(&error);
377
+ }
378
+
379
+ if (state.machine.trace) {
380
+ MONGOC_INFO("Finished running state machine");
381
+ }
382
+
383
+ result_utf8 = bson_as_canonical_extended_json(&result, NULL);
384
+ printf("%s\n", result_utf8);
385
+ bson_free(result_utf8);
386
+
387
+ bson_destroy(doc);
388
+ mongocrypt_binary_destroy(bin);
389
+ bson_destroy(&result);
390
+ mongocrypt_ctx_destroy(ctx);
391
+ mongocrypt_destroy(crypt);
392
+ state_cleanup(&state);
431
393
  }
432
394
 
433
- static void
434
- fn_explicitencrypt (bson_t *args)
435
- {
436
- state_t state;
437
- mongocrypt_t *crypt;
438
- mongocrypt_ctx_t *ctx;
439
- const char *value;
440
- bson_t *value_doc;
441
- const char *key_id_base64;
442
- const char *key_alt_name;
443
- const char *algorithm;
444
- mongocrypt_binary_t *bin;
445
- bson_t result;
446
- bson_error_t error;
447
- char *result_utf8;
448
- uint8_t key_id[97];
449
-
450
- crypt = crypt_new (args);
451
- ctx = mongocrypt_ctx_new (crypt);
452
- value = bson_req_utf8 (args, "value");
453
- value_doc =
454
- bson_new_from_json ((const uint8_t *) value, strlen (value), &error);
455
- if (!value_doc) {
456
- ERREXIT_BSON (&error);
457
- }
458
- key_id_base64 = bson_get_utf8 (args, "key_id", NULL);
459
- if (key_id_base64) {
460
- int len = kms_message_b64_pton (key_id_base64, key_id, sizeof (key_id));
461
- if (len < 0) {
462
- ERREXIT ("Could not base64 decode: %s", key_id_base64);
463
- }
464
- bin = mongocrypt_binary_new_from_data (key_id, len);
465
- if (!mongocrypt_ctx_setopt_key_id (ctx, bin)) {
466
- ERREXIT_CTX (ctx);
467
- }
468
- mongocrypt_binary_destroy (bin);
469
- }
470
-
471
- key_alt_name = bson_get_utf8 (args, "key_alt_name", NULL);
472
- if (key_alt_name) {
473
- bson_t *wrapper;
474
-
475
- wrapper = BCON_NEW ("keyAltName", key_alt_name);
476
- bin = util_bson_to_bin (wrapper);
477
- if (!mongocrypt_ctx_setopt_key_alt_name (ctx, bin)) {
478
- ERREXIT_CTX (ctx);
479
- }
480
- mongocrypt_binary_destroy (bin);
481
- }
482
-
483
-
484
- algorithm = bson_req_utf8 (args, "algorithm");
485
- if (!mongocrypt_ctx_setopt_algorithm (ctx, algorithm, -1)) {
486
- ERREXIT_CTX (ctx);
487
- }
488
-
489
- bin = util_bson_to_bin (value_doc);
490
- if (!mongocrypt_ctx_explicit_encrypt_init (ctx, bin)) {
491
- ERREXIT_CTX (ctx);
492
- }
493
-
494
- state_init (&state, args, ctx);
495
-
496
- if (state.machine.trace) {
497
- MONGOC_INFO ("Running state machine");
498
- }
499
-
500
- if (!_csfle_state_machine_run (&state.machine, &result, &error)) {
501
- ERREXIT_BSON (&error);
502
- }
503
-
504
- if (state.machine.trace) {
505
- MONGOC_INFO ("Finished running state machine");
506
- }
507
-
508
- result_utf8 = bson_as_canonical_extended_json (&result, NULL);
509
- printf ("%s\n", result_utf8);
510
- bson_free (result_utf8);
511
-
512
- bson_destroy (value_doc);
513
- mongocrypt_binary_destroy (bin);
514
- bson_destroy (&result);
515
- mongocrypt_ctx_destroy (ctx);
516
- mongocrypt_destroy (crypt);
517
- state_cleanup (&state);
395
+ static void fn_explicitencrypt(bson_t *args) {
396
+ state_t state;
397
+ mongocrypt_t *crypt;
398
+ mongocrypt_ctx_t *ctx;
399
+ const char *value;
400
+ bson_t *value_doc;
401
+ const char *key_id_base64;
402
+ const char *key_alt_name;
403
+ const char *algorithm;
404
+ mongocrypt_binary_t *bin;
405
+ bson_t result;
406
+ bson_error_t error;
407
+ char *result_utf8;
408
+ uint8_t key_id[97];
409
+
410
+ crypt = crypt_new(args);
411
+ ctx = mongocrypt_ctx_new(crypt);
412
+ value = bson_req_utf8(args, "value");
413
+ value_doc = bson_new_from_json((const uint8_t *)value, strlen(value), &error);
414
+ if (!value_doc) {
415
+ ERREXIT_BSON(&error);
416
+ }
417
+ key_id_base64 = bson_get_utf8(args, "key_id", NULL);
418
+ if (key_id_base64) {
419
+ int len = kms_message_b64_pton(key_id_base64, key_id, sizeof(key_id));
420
+ if (len < 0) {
421
+ ERREXIT("Could not base64 decode: %s", key_id_base64);
422
+ }
423
+ bin = mongocrypt_binary_new_from_data(key_id, len);
424
+ if (!mongocrypt_ctx_setopt_key_id(ctx, bin)) {
425
+ ERREXIT_CTX(ctx);
426
+ }
427
+ mongocrypt_binary_destroy(bin);
428
+ }
429
+
430
+ key_alt_name = bson_get_utf8(args, "key_alt_name", NULL);
431
+ if (key_alt_name) {
432
+ bson_t *wrapper;
433
+
434
+ wrapper = BCON_NEW("keyAltName", key_alt_name);
435
+ bin = util_bson_to_bin(wrapper);
436
+ if (!mongocrypt_ctx_setopt_key_alt_name(ctx, bin)) {
437
+ ERREXIT_CTX(ctx);
438
+ }
439
+ mongocrypt_binary_destroy(bin);
440
+ }
441
+
442
+ algorithm = bson_req_utf8(args, "algorithm");
443
+ if (!mongocrypt_ctx_setopt_algorithm(ctx, algorithm, -1)) {
444
+ ERREXIT_CTX(ctx);
445
+ }
446
+
447
+ bin = util_bson_to_bin(value_doc);
448
+ if (!mongocrypt_ctx_explicit_encrypt_init(ctx, bin)) {
449
+ ERREXIT_CTX(ctx);
450
+ }
451
+
452
+ state_init(&state, args, ctx);
453
+
454
+ if (state.machine.trace) {
455
+ MONGOC_INFO("Running state machine");
456
+ }
457
+
458
+ if (!_csfle_state_machine_run(&state.machine, &result, &error)) {
459
+ ERREXIT_BSON(&error);
460
+ }
461
+
462
+ if (state.machine.trace) {
463
+ MONGOC_INFO("Finished running state machine");
464
+ }
465
+
466
+ result_utf8 = bson_as_canonical_extended_json(&result, NULL);
467
+ printf("%s\n", result_utf8);
468
+ bson_free(result_utf8);
469
+
470
+ bson_destroy(value_doc);
471
+ mongocrypt_binary_destroy(bin);
472
+ bson_destroy(&result);
473
+ mongocrypt_ctx_destroy(ctx);
474
+ mongocrypt_destroy(crypt);
475
+ state_cleanup(&state);
518
476
  }
519
477
 
520
- static void
521
- fn_explicitdecrypt (bson_t *args)
522
- {
523
- state_t state;
524
- mongocrypt_t *crypt;
525
- mongocrypt_ctx_t *ctx;
526
- const char *value;
527
- bson_t *value_doc;
528
- mongocrypt_binary_t *bin;
529
- bson_t result;
530
- bson_error_t error;
531
- char *result_utf8;
532
-
533
- crypt = crypt_new (args);
534
- ctx = mongocrypt_ctx_new (crypt);
535
- value = bson_req_utf8 (args, "value");
536
- value_doc =
537
- bson_new_from_json ((const uint8_t *) value, strlen (value), &error);
538
- if (!value_doc) {
539
- ERREXIT_BSON (&error);
540
- }
541
-
542
- bin = util_bson_to_bin (value_doc);
543
- if (!mongocrypt_ctx_explicit_decrypt_init (ctx, bin)) {
544
- ERREXIT_CTX (ctx);
545
- }
546
-
547
- state_init (&state, args, ctx);
548
-
549
- if (state.machine.trace) {
550
- MONGOC_INFO ("Running state machine");
551
- }
552
-
553
- if (!_csfle_state_machine_run (&state.machine, &result, &error)) {
554
- ERREXIT_BSON (&error);
555
- }
556
-
557
- if (state.machine.trace) {
558
- MONGOC_INFO ("Finished running state machine");
559
- }
560
-
561
- result_utf8 = bson_as_canonical_extended_json (&result, NULL);
562
- printf ("%s\n", result_utf8);
563
- bson_free (result_utf8);
564
-
565
- bson_destroy (value_doc);
566
- mongocrypt_binary_destroy (bin);
567
- bson_destroy (&result);
568
- mongocrypt_ctx_destroy (ctx);
569
- mongocrypt_destroy (crypt);
570
- state_cleanup (&state);
478
+ static void fn_explicitdecrypt(bson_t *args) {
479
+ state_t state;
480
+ mongocrypt_t *crypt;
481
+ mongocrypt_ctx_t *ctx;
482
+ const char *value;
483
+ bson_t *value_doc;
484
+ mongocrypt_binary_t *bin;
485
+ bson_t result;
486
+ bson_error_t error;
487
+ char *result_utf8;
488
+
489
+ crypt = crypt_new(args);
490
+ ctx = mongocrypt_ctx_new(crypt);
491
+ value = bson_req_utf8(args, "value");
492
+ value_doc = bson_new_from_json((const uint8_t *)value, strlen(value), &error);
493
+ if (!value_doc) {
494
+ ERREXIT_BSON(&error);
495
+ }
496
+
497
+ bin = util_bson_to_bin(value_doc);
498
+ if (!mongocrypt_ctx_explicit_decrypt_init(ctx, bin)) {
499
+ ERREXIT_CTX(ctx);
500
+ }
501
+
502
+ state_init(&state, args, ctx);
503
+
504
+ if (state.machine.trace) {
505
+ MONGOC_INFO("Running state machine");
506
+ }
507
+
508
+ if (!_csfle_state_machine_run(&state.machine, &result, &error)) {
509
+ ERREXIT_BSON(&error);
510
+ }
511
+
512
+ if (state.machine.trace) {
513
+ MONGOC_INFO("Finished running state machine");
514
+ }
515
+
516
+ result_utf8 = bson_as_canonical_extended_json(&result, NULL);
517
+ printf("%s\n", result_utf8);
518
+ bson_free(result_utf8);
519
+
520
+ bson_destroy(value_doc);
521
+ mongocrypt_binary_destroy(bin);
522
+ bson_destroy(&result);
523
+ mongocrypt_ctx_destroy(ctx);
524
+ mongocrypt_destroy(crypt);
525
+ state_cleanup(&state);
571
526
  }
572
527
 
573
- int
574
- main (int argc, char **argv)
575
- {
576
- bson_t args;
577
- bson_t *options_file_bson;
578
- char *fn;
579
-
580
- mongoc_init ();
581
-
582
- if (argc < 2) {
583
- _exit_help ();
584
- }
585
-
586
- fn = argv[1];
587
- bson_init (&args);
588
- args_parse (&args, argc - 2, argv + 2);
589
- options_file_bson = bson_get_json (&args, "options_file");
590
- if (options_file_bson) {
591
- bson_concat (&args, options_file_bson);
592
- }
593
-
594
- if (0 == strcmp (fn, "create_datakey")) {
595
- fn_createdatakey (&args);
596
- } else if (0 == strcmp (fn, "auto_encrypt")) {
597
- fn_autoencrypt (&args);
598
- } else if (0 == strcmp (fn, "auto_decrypt")) {
599
- fn_autodecrypt (&args);
600
- } else if (0 == strcmp (fn, "explicit_encrypt")) {
601
- fn_explicitencrypt (&args);
602
- } else if (0 == strcmp (fn, "explicit_decrypt")) {
603
- fn_explicitdecrypt (&args);
604
- } else {
605
- ERREXIT ("Unknown function: %s", fn);
606
- }
607
-
608
- bson_destroy (&args);
609
- bson_destroy (options_file_bson);
610
-
611
- mongoc_cleanup ();
528
+ int main(int argc, char **argv) {
529
+ bson_t args;
530
+ bson_t *options_file_bson;
531
+ char *fn;
532
+
533
+ mongoc_init();
534
+
535
+ if (argc < 2) {
536
+ _exit_help();
537
+ }
538
+
539
+ fn = argv[1];
540
+ bson_init(&args);
541
+ args_parse(&args, argc - 2, argv + 2);
542
+ options_file_bson = bson_get_json(&args, "options_file");
543
+ if (options_file_bson) {
544
+ bson_concat(&args, options_file_bson);
545
+ }
546
+
547
+ if (0 == strcmp(fn, "create_datakey")) {
548
+ fn_createdatakey(&args);
549
+ } else if (0 == strcmp(fn, "auto_encrypt")) {
550
+ fn_autoencrypt(&args);
551
+ } else if (0 == strcmp(fn, "auto_decrypt")) {
552
+ fn_autodecrypt(&args);
553
+ } else if (0 == strcmp(fn, "explicit_encrypt")) {
554
+ fn_explicitencrypt(&args);
555
+ } else if (0 == strcmp(fn, "explicit_decrypt")) {
556
+ fn_explicitdecrypt(&args);
557
+ } else {
558
+ ERREXIT("Unknown function: %s", fn);
559
+ }
560
+
561
+ bson_destroy(&args);
562
+ bson_destroy(options_file_bson);
563
+
564
+ mongoc_cleanup();
612
565
  }