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
@@ -14,1121 +14,946 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ #include "kms_message/kms_b64.h" // kms_message_raw_to_b64
17
18
  #include "mongocrypt-ctx-private.h"
18
19
  #include "mongocrypt.h"
19
- #include "test-mongocrypt.h"
20
20
  #include "test-mongocrypt-assert-match-bson.h"
21
+ #include "test-mongocrypt.h"
21
22
 
22
- static void
23
- _test_explicit_decrypt_init (_mongocrypt_tester_t *tester)
24
- {
25
- mongocrypt_t *crypt;
26
- mongocrypt_ctx_t *ctx;
27
- mongocrypt_binary_t *msg;
28
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
23
+ static void _test_explicit_decrypt_init(_mongocrypt_tester_t *tester) {
24
+ mongocrypt_t *crypt;
25
+ mongocrypt_ctx_t *ctx;
26
+ mongocrypt_binary_t *msg;
27
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
29
28
 
30
- msg = TEST_BSON ("{ 'v': { '$binary': { 'subType': '06', 'base64': "
29
+ msg = TEST_BSON("{ 'v': { '$binary': { 'subType': '06', 'base64': "
31
30
  "'AWFhYWFhYWFhYWFhYWFhYWECRTOW9yZzNDn5dGwuqsrJQNLtgMEKaujhs"
32
31
  "9aRWRp+7Yo3JK8N8jC8P0Xjll6C1CwLsE/"
33
32
  "iP5wjOMhVv1KMMyOCSCrHorXRsb2IKPtzl2lKTqQ=' } } }");
34
33
 
35
- /* NULL document. */
36
- ctx = mongocrypt_ctx_new (crypt);
37
- ASSERT_FAILS (
38
- mongocrypt_ctx_explicit_decrypt_init (ctx, NULL), ctx, "invalid msg");
39
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_ERROR);
40
- mongocrypt_ctx_destroy (ctx);
34
+ /* NULL document. */
35
+ ctx = mongocrypt_ctx_new(crypt);
36
+ ASSERT_FAILS(mongocrypt_ctx_explicit_decrypt_init(ctx, NULL), ctx, "invalid msg");
37
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_ERROR);
38
+ mongocrypt_ctx_destroy(ctx);
41
39
 
42
- /* Success. */
43
- ctx = mongocrypt_ctx_new (crypt);
44
- ASSERT_OK (mongocrypt_ctx_explicit_decrypt_init (ctx, msg), ctx);
45
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_NEED_MONGO_KEYS);
46
- mongocrypt_ctx_destroy (ctx);
40
+ /* Success. */
41
+ ctx = mongocrypt_ctx_new(crypt);
42
+ ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(ctx, msg), ctx);
43
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_MONGO_KEYS);
44
+ mongocrypt_ctx_destroy(ctx);
47
45
 
48
- mongocrypt_destroy (crypt);
46
+ mongocrypt_destroy(crypt);
49
47
  }
50
48
 
51
-
52
49
  /* Test individual ctx states. */
53
- static void
54
- _test_decrypt_init (_mongocrypt_tester_t *tester)
55
- {
56
- mongocrypt_t *crypt;
57
- mongocrypt_ctx_t *ctx;
58
- mongocrypt_binary_t *encrypted;
59
-
60
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
61
-
62
- encrypted = _mongocrypt_tester_encrypted_doc (tester);
63
-
64
- /* Success. */
65
- ctx = mongocrypt_ctx_new (crypt);
66
- ASSERT_OK (mongocrypt_ctx_decrypt_init (ctx, encrypted), ctx);
67
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_NEED_MONGO_KEYS);
68
- mongocrypt_ctx_destroy (ctx);
69
-
70
- /* NULL document. */
71
- ctx = mongocrypt_ctx_new (crypt);
72
- ASSERT_FAILS (mongocrypt_ctx_decrypt_init (ctx, NULL), ctx, "invalid doc");
73
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_ERROR);
74
- mongocrypt_ctx_destroy (ctx);
75
-
76
- mongocrypt_binary_destroy (encrypted);
77
- mongocrypt_destroy (crypt);
78
- }
79
-
50
+ static void _test_decrypt_init(_mongocrypt_tester_t *tester) {
51
+ mongocrypt_t *crypt;
52
+ mongocrypt_ctx_t *ctx;
53
+ mongocrypt_binary_t *encrypted;
80
54
 
81
- static void
82
- _test_decrypt_need_keys (_mongocrypt_tester_t *tester)
83
- {
84
- mongocrypt_t *crypt;
85
- mongocrypt_ctx_t *ctx;
86
- mongocrypt_binary_t *encrypted;
55
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
87
56
 
88
- encrypted = _mongocrypt_tester_encrypted_doc (tester);
57
+ encrypted = _mongocrypt_tester_encrypted_doc(tester);
89
58
 
90
- /* Success. */
91
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
92
- ctx = mongocrypt_ctx_new (crypt);
93
- ASSERT_OK (mongocrypt_ctx_decrypt_init (ctx, encrypted), ctx);
94
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
95
- ctx, TEST_FILE ("./test/example/key-document.json")),
96
- ctx);
97
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
98
- BSON_ASSERT (mongocrypt_ctx_state (ctx) == MONGOCRYPT_CTX_NEED_KMS);
99
- mongocrypt_ctx_destroy (ctx);
100
- mongocrypt_destroy (crypt); /* recreate crypt because of caching. */
59
+ /* Success. */
60
+ ctx = mongocrypt_ctx_new(crypt);
61
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, encrypted), ctx);
62
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_MONGO_KEYS);
63
+ mongocrypt_ctx_destroy(ctx);
101
64
 
102
- /* TODO: CDRIVER-3044 test that decryption warns when keys are not
103
- * found/inactive. */
65
+ /* NULL document. */
66
+ ctx = mongocrypt_ctx_new(crypt);
67
+ ASSERT_FAILS(mongocrypt_ctx_decrypt_init(ctx, NULL), ctx, "invalid doc");
68
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_ERROR);
69
+ mongocrypt_ctx_destroy(ctx);
104
70
 
105
- mongocrypt_binary_destroy (encrypted);
71
+ mongocrypt_binary_destroy(encrypted);
72
+ mongocrypt_destroy(crypt);
106
73
  }
107
74
 
75
+ static void _test_decrypt_need_keys(_mongocrypt_tester_t *tester) {
76
+ mongocrypt_t *crypt;
77
+ mongocrypt_ctx_t *ctx;
78
+ mongocrypt_binary_t *encrypted;
79
+
80
+ encrypted = _mongocrypt_tester_encrypted_doc(tester);
81
+
82
+ /* Success. */
83
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
84
+ ctx = mongocrypt_ctx_new(crypt);
85
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, encrypted), ctx);
86
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/example/key-document.json")), ctx);
87
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
88
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_KMS);
89
+ mongocrypt_ctx_destroy(ctx);
90
+ mongocrypt_destroy(crypt); /* recreate crypt because of caching. */
108
91
 
109
- static void
110
- _test_decrypt_ready (_mongocrypt_tester_t *tester)
111
- {
112
- mongocrypt_t *crypt;
113
- mongocrypt_ctx_t *ctx;
114
- mongocrypt_binary_t *encrypted, *decrypted;
115
- bson_t as_bson;
116
- bson_iter_t iter;
117
-
118
- encrypted = _mongocrypt_tester_encrypted_doc (tester);
119
- decrypted = mongocrypt_binary_new ();
120
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
121
-
122
- /* Success. */
123
- ctx = mongocrypt_ctx_new (crypt);
124
- ASSERT_OK (mongocrypt_ctx_decrypt_init (ctx, encrypted), ctx);
125
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
126
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, decrypted), ctx);
127
- BSON_ASSERT (_mongocrypt_binary_to_bson (decrypted, &as_bson));
128
- bson_iter_init (&iter, &as_bson);
129
- bson_iter_find_descendant (&iter, "filter.ssn", &iter);
130
- BSON_ASSERT (BSON_ITER_HOLDS_UTF8 (&iter));
131
- BSON_ASSERT (0 == strcmp (bson_iter_utf8 (&iter, NULL),
132
- _mongocrypt_tester_plaintext (tester)));
133
- mongocrypt_binary_destroy (decrypted);
134
- mongocrypt_ctx_destroy (ctx);
135
- mongocrypt_destroy (crypt);
136
- mongocrypt_binary_destroy (encrypted);
92
+ /* TODO: CDRIVER-3044 test that decryption warns when keys are not
93
+ * found/inactive. */
94
+
95
+ mongocrypt_binary_destroy(encrypted);
137
96
  }
138
97
 
98
+ static void _test_decrypt_ready(_mongocrypt_tester_t *tester) {
99
+ mongocrypt_t *crypt;
100
+ mongocrypt_ctx_t *ctx;
101
+ mongocrypt_binary_t *encrypted, *decrypted;
102
+ bson_t as_bson;
103
+ bson_iter_t iter;
104
+
105
+ encrypted = _mongocrypt_tester_encrypted_doc(tester);
106
+ decrypted = mongocrypt_binary_new();
107
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
108
+
109
+ /* Success. */
110
+ ctx = mongocrypt_ctx_new(crypt);
111
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, encrypted), ctx);
112
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
113
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, decrypted), ctx);
114
+ BSON_ASSERT(_mongocrypt_binary_to_bson(decrypted, &as_bson));
115
+ bson_iter_init(&iter, &as_bson);
116
+ bson_iter_find_descendant(&iter, "filter.ssn", &iter);
117
+ BSON_ASSERT(BSON_ITER_HOLDS_UTF8(&iter));
118
+ BSON_ASSERT(0 == strcmp(bson_iter_utf8(&iter, NULL), _mongocrypt_tester_plaintext(tester)));
119
+ mongocrypt_binary_destroy(decrypted);
120
+ mongocrypt_ctx_destroy(ctx);
121
+ mongocrypt_destroy(crypt);
122
+ mongocrypt_binary_destroy(encrypted);
123
+ }
139
124
 
140
125
  /* Test with empty AWS credentials. */
141
- void
142
- _test_decrypt_empty_aws (_mongocrypt_tester_t *tester)
143
- {
144
- mongocrypt_t *crypt;
145
- mongocrypt_ctx_t *ctx;
146
-
147
- crypt = mongocrypt_new ();
148
- ASSERT_OK (mongocrypt_setopt_kms_provider_aws (crypt, "", -1, "", -1),
149
- crypt);
150
- ASSERT_OK (mongocrypt_init (crypt), crypt);
151
-
152
- ctx = mongocrypt_ctx_new (crypt);
153
- ASSERT_OK (mongocrypt_ctx_decrypt_init (
154
- ctx, TEST_FILE ("./test/data/encrypted-cmd.json")),
155
- ctx);
156
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
157
- ASSERT_FAILS (mongocrypt_ctx_mongo_feed (
158
- ctx, TEST_FILE ("./test/example/key-document.json")),
126
+ void _test_decrypt_empty_aws(_mongocrypt_tester_t *tester) {
127
+ mongocrypt_t *crypt;
128
+ mongocrypt_ctx_t *ctx;
129
+
130
+ crypt = mongocrypt_new();
131
+ ASSERT_OK(mongocrypt_setopt_kms_provider_aws(crypt, "", -1, "", -1), crypt);
132
+ ASSERT_OK(_mongocrypt_init_for_test(crypt), crypt);
133
+
134
+ ctx = mongocrypt_ctx_new(crypt);
135
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, TEST_FILE("./test/data/encrypted-cmd.json")), ctx);
136
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
137
+ ASSERT_FAILS(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/example/key-document.json")),
159
138
  ctx,
160
139
  "failed to create KMS message");
161
140
 
162
- mongocrypt_ctx_destroy (ctx);
163
- mongocrypt_destroy (crypt);
141
+ mongocrypt_ctx_destroy(ctx);
142
+ mongocrypt_destroy(crypt);
164
143
  }
165
144
 
166
- static void
167
- _test_decrypt_empty_binary (_mongocrypt_tester_t *tester)
168
- {
169
- mongocrypt_t *crypt;
170
- mongocrypt_ctx_t *ctx;
171
- mongocrypt_binary_t *bin;
172
- _mongocrypt_buffer_t encrypted;
173
-
174
- bin = mongocrypt_binary_new ();
175
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
176
- ctx = mongocrypt_ctx_new (crypt);
177
-
178
- /* Encrypt an empty binary value. */
179
- mongocrypt_ctx_setopt_key_alt_name (
180
- ctx, TEST_BSON ("{'keyAltName': 'keyDocumentName'}"));
181
- mongocrypt_ctx_setopt_algorithm (
182
- ctx, MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
183
- mongocrypt_ctx_explicit_encrypt_init (
184
- ctx,
185
- TEST_BSON ("{'v': { '$binary': { 'base64': '', 'subType': '00' } } }"));
186
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
187
- mongocrypt_ctx_finalize (ctx, bin);
188
- /* Copy the encrypted ciphertext since it is tied to the lifetime of ctx. */
189
- _mongocrypt_buffer_copy_from_binary (&encrypted, bin);
190
- mongocrypt_ctx_destroy (ctx);
191
-
192
- /* Decrypt it back. */
193
- ctx = mongocrypt_ctx_new (crypt);
194
- mongocrypt_ctx_explicit_decrypt_init (
195
- ctx, _mongocrypt_buffer_as_binary (&encrypted));
196
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
197
- mongocrypt_ctx_finalize (ctx, bin);
198
-
199
- mongocrypt_binary_destroy (bin);
200
- mongocrypt_ctx_destroy (ctx);
201
- _mongocrypt_buffer_cleanup (&encrypted);
202
- mongocrypt_destroy (crypt);
145
+ static void _test_decrypt_empty_binary(_mongocrypt_tester_t *tester) {
146
+ mongocrypt_t *crypt;
147
+ mongocrypt_ctx_t *ctx;
148
+ mongocrypt_binary_t *bin;
149
+ _mongocrypt_buffer_t encrypted;
150
+
151
+ bin = mongocrypt_binary_new();
152
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
153
+ ctx = mongocrypt_ctx_new(crypt);
154
+
155
+ /* Encrypt an empty binary value. */
156
+ mongocrypt_ctx_setopt_key_alt_name(ctx, TEST_BSON("{'keyAltName': 'keyDocumentName'}"));
157
+ mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
158
+ mongocrypt_ctx_explicit_encrypt_init(ctx, TEST_BSON("{'v': { '$binary': { 'base64': '', 'subType': '00' } } }"));
159
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
160
+ mongocrypt_ctx_finalize(ctx, bin);
161
+ /* Copy the encrypted ciphertext since it is tied to the lifetime of ctx. */
162
+ _mongocrypt_buffer_copy_from_binary(&encrypted, bin);
163
+ mongocrypt_ctx_destroy(ctx);
164
+
165
+ /* Decrypt it back. */
166
+ ctx = mongocrypt_ctx_new(crypt);
167
+ mongocrypt_ctx_explicit_decrypt_init(ctx, _mongocrypt_buffer_as_binary(&encrypted));
168
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
169
+ mongocrypt_ctx_finalize(ctx, bin);
170
+
171
+ mongocrypt_binary_destroy(bin);
172
+ mongocrypt_ctx_destroy(ctx);
173
+ _mongocrypt_buffer_cleanup(&encrypted);
174
+ mongocrypt_destroy(crypt);
203
175
  }
204
176
 
205
- static void
206
- _test_decrypt_per_ctx_credentials (_mongocrypt_tester_t *tester)
207
- {
208
- mongocrypt_t *crypt;
209
- mongocrypt_ctx_t *ctx;
210
- mongocrypt_binary_t *bin;
211
- _mongocrypt_buffer_t encrypted;
212
-
213
- bin = mongocrypt_binary_new ();
214
- crypt = mongocrypt_new ();
215
- mongocrypt_setopt_use_need_kms_credentials_state (crypt);
216
- mongocrypt_setopt_kms_providers (crypt, TEST_BSON ("{'aws': {}}"));
217
- ASSERT_OK (mongocrypt_init (crypt), crypt);
218
- ctx = mongocrypt_ctx_new (crypt);
219
-
220
- /* Encrypt an empty binary value. */
221
- mongocrypt_ctx_setopt_key_alt_name (
222
- ctx, TEST_BSON ("{'keyAltName': 'keyDocumentName'}"));
223
- mongocrypt_ctx_setopt_algorithm (
224
- ctx, MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
225
- mongocrypt_ctx_explicit_encrypt_init (
226
- ctx,
227
- TEST_BSON ("{'v': { '$binary': { 'base64': '', 'subType': '00' } } }"));
228
- _mongocrypt_tester_run_ctx_to (
229
- tester, ctx, MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
230
- ASSERT_OK (mongocrypt_ctx_provide_kms_providers (
231
- ctx,
232
- TEST_BSON ("{'aws':{'accessKeyId': 'example',"
233
- "'secretAccessKey': 'example'}}")),
177
+ static void _test_decrypt_per_ctx_credentials(_mongocrypt_tester_t *tester) {
178
+ mongocrypt_t *crypt;
179
+ mongocrypt_ctx_t *ctx;
180
+ mongocrypt_binary_t *bin;
181
+ _mongocrypt_buffer_t encrypted;
182
+
183
+ bin = mongocrypt_binary_new();
184
+ crypt = mongocrypt_new();
185
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
186
+ mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'aws': {}}"));
187
+ ASSERT_OK(_mongocrypt_init_for_test(crypt), crypt);
188
+ ctx = mongocrypt_ctx_new(crypt);
189
+
190
+ /* Encrypt an empty binary value. */
191
+ mongocrypt_ctx_setopt_key_alt_name(ctx, TEST_BSON("{'keyAltName': 'keyDocumentName'}"));
192
+ mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
193
+ mongocrypt_ctx_explicit_encrypt_init(ctx, TEST_BSON("{'v': { '$binary': { 'base64': '', 'subType': '00' } } }"));
194
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
195
+ ASSERT_OK(mongocrypt_ctx_provide_kms_providers(ctx,
196
+ TEST_BSON("{'aws':{'accessKeyId': 'example',"
197
+ "'secretAccessKey': 'example'}}")),
234
198
  ctx);
235
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
236
- mongocrypt_ctx_finalize (ctx, bin);
237
- /* Copy the encrypted ciphertext since it is tied to the lifetime of ctx. */
238
- _mongocrypt_buffer_copy_from_binary (&encrypted, bin);
239
- mongocrypt_ctx_destroy (ctx);
240
-
241
- /* Decrypt it back. */
242
- ctx = mongocrypt_ctx_new (crypt);
243
- mongocrypt_ctx_explicit_decrypt_init (
244
- ctx, _mongocrypt_buffer_as_binary (&encrypted));
245
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
246
- mongocrypt_ctx_finalize (ctx, bin);
247
-
248
- mongocrypt_binary_destroy (bin);
249
- mongocrypt_ctx_destroy (ctx);
250
- _mongocrypt_buffer_cleanup (&encrypted);
251
- mongocrypt_destroy (crypt);
199
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
200
+ mongocrypt_ctx_finalize(ctx, bin);
201
+ /* Copy the encrypted ciphertext since it is tied to the lifetime of ctx. */
202
+ _mongocrypt_buffer_copy_from_binary(&encrypted, bin);
203
+ mongocrypt_ctx_destroy(ctx);
204
+
205
+ /* Decrypt it back. */
206
+ ctx = mongocrypt_ctx_new(crypt);
207
+ mongocrypt_ctx_explicit_decrypt_init(ctx, _mongocrypt_buffer_as_binary(&encrypted));
208
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
209
+ mongocrypt_ctx_finalize(ctx, bin);
210
+
211
+ mongocrypt_binary_destroy(bin);
212
+ mongocrypt_ctx_destroy(ctx);
213
+ _mongocrypt_buffer_cleanup(&encrypted);
214
+ mongocrypt_destroy(crypt);
252
215
  }
253
216
 
254
- static void
255
- _test_decrypt_per_ctx_credentials_local (_mongocrypt_tester_t *tester)
256
- {
257
- mongocrypt_t *crypt;
258
- mongocrypt_ctx_t *ctx;
259
- mongocrypt_binary_t *bin;
260
- _mongocrypt_buffer_t encrypted;
261
- /* local_kek is the KEK used to encrypt the keyMaterial in
262
- * ./test/data/key-document-local.json */
263
- const char *local_kek =
264
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
265
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
266
- /* local_uuid is the hex of the UUID of the key in
267
- * ./test/data/key-document-local.json */
268
- const char *local_uuid = "61616161616161616161616161616161";
269
- _mongocrypt_buffer_t local_uuid_buf;
270
-
271
- bin = mongocrypt_binary_new ();
272
- crypt = mongocrypt_new ();
273
- mongocrypt_setopt_use_need_kms_credentials_state (crypt);
274
- mongocrypt_setopt_kms_providers (crypt, TEST_BSON ("{'local': {}}"));
275
- ASSERT_OK (mongocrypt_init (crypt), crypt);
276
- ctx = mongocrypt_ctx_new (crypt);
277
-
278
- /* Encrypt an empty binary value. */
279
- _mongocrypt_buffer_copy_from_hex (&local_uuid_buf, local_uuid);
280
- mongocrypt_ctx_setopt_key_id (
281
- ctx, _mongocrypt_buffer_as_binary (&local_uuid_buf));
282
- mongocrypt_ctx_setopt_algorithm (
283
- ctx, MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
284
- mongocrypt_ctx_explicit_encrypt_init (
285
- ctx,
286
- TEST_BSON ("{'v': { '$binary': { 'base64': '', 'subType': '00' } } }"));
287
- _mongocrypt_tester_run_ctx_to (
288
- tester, ctx, MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
289
- ASSERT_OK (mongocrypt_ctx_provide_kms_providers (
290
- ctx,
291
- TEST_BSON ("{'local':{'key': { '$binary': {'base64': '%s', "
292
- "'subType': '00'}}}}",
293
- local_kek)),
217
+ static void _test_decrypt_per_ctx_credentials_local(_mongocrypt_tester_t *tester) {
218
+ mongocrypt_t *crypt;
219
+ mongocrypt_ctx_t *ctx;
220
+ mongocrypt_binary_t *bin;
221
+ _mongocrypt_buffer_t encrypted;
222
+ /* local_kek is the KEK used to encrypt the keyMaterial in
223
+ * ./test/data/key-document-local.json */
224
+ uint8_t local_kek_raw[MONGOCRYPT_KEY_LEN] = {0};
225
+ char *local_kek = kms_message_raw_to_b64(local_kek_raw, sizeof(local_kek_raw));
226
+
227
+ /* local_uuid is the hex of the UUID of the key in
228
+ * ./test/data/key-document-local.json */
229
+ const char *local_uuid = "61616161616161616161616161616161";
230
+ _mongocrypt_buffer_t local_uuid_buf;
231
+
232
+ bin = mongocrypt_binary_new();
233
+ crypt = mongocrypt_new();
234
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
235
+ mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'local': {}}"));
236
+ ASSERT_OK(_mongocrypt_init_for_test(crypt), crypt);
237
+ ctx = mongocrypt_ctx_new(crypt);
238
+
239
+ /* Encrypt an empty binary value. */
240
+ _mongocrypt_buffer_copy_from_hex(&local_uuid_buf, local_uuid);
241
+ mongocrypt_ctx_setopt_key_id(ctx, _mongocrypt_buffer_as_binary(&local_uuid_buf));
242
+ mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
243
+ mongocrypt_ctx_explicit_encrypt_init(ctx, TEST_BSON("{'v': { '$binary': { 'base64': '', 'subType': '00' } } }"));
244
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
245
+ ASSERT_OK(mongocrypt_ctx_provide_kms_providers(ctx,
246
+ TEST_BSON("{'local':{'key': { '$binary': {'base64': '%s', "
247
+ "'subType': '00'}}}}",
248
+ local_kek)),
294
249
  ctx);
295
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
296
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
297
- ctx, TEST_FILE ("./test/data/key-document-local.json")),
298
- ctx);
299
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
300
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
301
- mongocrypt_ctx_finalize (ctx, bin);
302
- /* Copy the encrypted ciphertext since it is tied to the lifetime of ctx. */
303
- _mongocrypt_buffer_copy_from_binary (&encrypted, bin);
304
- mongocrypt_ctx_destroy (ctx);
305
-
306
- /* Decrypt it back. */
307
- ctx = mongocrypt_ctx_new (crypt);
308
- mongocrypt_ctx_explicit_decrypt_init (
309
- ctx, _mongocrypt_buffer_as_binary (&encrypted));
310
- _mongocrypt_tester_run_ctx_to (tester, ctx, MONGOCRYPT_CTX_READY);
311
- mongocrypt_ctx_finalize (ctx, bin);
312
-
313
- _mongocrypt_buffer_cleanup (&local_uuid_buf);
314
- mongocrypt_binary_destroy (bin);
315
- mongocrypt_ctx_destroy (ctx);
316
- _mongocrypt_buffer_cleanup (&encrypted);
317
- mongocrypt_destroy (crypt);
250
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
251
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-local.json")), ctx);
252
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
253
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
254
+ mongocrypt_ctx_finalize(ctx, bin);
255
+ /* Copy the encrypted ciphertext since it is tied to the lifetime of ctx. */
256
+ _mongocrypt_buffer_copy_from_binary(&encrypted, bin);
257
+ mongocrypt_ctx_destroy(ctx);
258
+
259
+ /* Decrypt it back. */
260
+ ctx = mongocrypt_ctx_new(crypt);
261
+ mongocrypt_ctx_explicit_decrypt_init(ctx, _mongocrypt_buffer_as_binary(&encrypted));
262
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
263
+ mongocrypt_ctx_finalize(ctx, bin);
264
+
265
+ _mongocrypt_buffer_cleanup(&local_uuid_buf);
266
+ mongocrypt_binary_destroy(bin);
267
+ mongocrypt_ctx_destroy(ctx);
268
+ _mongocrypt_buffer_cleanup(&encrypted);
269
+ mongocrypt_destroy(crypt);
270
+ bson_free(local_kek);
318
271
  }
319
272
 
320
- static void
321
- _test_decrypt_fle2 (_mongocrypt_tester_t *tester)
322
- {
323
- _mongocrypt_buffer_t S_KeyId;
324
- _mongocrypt_buffer_t K_KeyId;
325
-
326
- if (!_aes_ctr_is_supported_by_os) {
327
- printf ("Common Crypto with no CTR support detected. Skipping.");
328
- return;
329
- }
330
-
331
- #define TEST_IEEV_BASE64 \
332
- "BxI0VngSNJh2EjQSNFZ4kBICQ7uhTd9C2oI8M1afRon0ZaYG0s6oTmt0aBZ9kO4S4mm5vId01" \
333
- "BsW7tBHytA8pDJ2IiWBCmah3OGH2M4ET7PSqekQD4gkUCo4JeEttx4yj05Ou4D6yZUmYfVKmE" \
334
- "ljge16NCxKm7Ir9gvmQsp8x1wqGBzpndA6gkqFxsxfvQ/" \
335
- "cIqOwMW9dGTTWsfKge+jYkCUIFMfms+XyC/8evQhjjA+qR6eEmV+N/" \
336
- "kwpR7Q7TJe0lwU5kw2kSe3/KiPKRZZTbn8znadvycfJ0cCWGad9SQ=="
337
-
338
- _mongocrypt_buffer_copy_from_hex (&S_KeyId,
339
- "12345678123498761234123456789012");
340
- _mongocrypt_buffer_copy_from_hex (&K_KeyId,
341
- "ABCDEFAB123498761234123456789012");
342
-
343
- /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
344
- {
345
- mongocrypt_t *crypt =
346
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
347
- mongocrypt_ctx_t *ctx;
348
- mongocrypt_binary_t *out;
349
- bson_t out_bson;
350
-
351
- ctx = mongocrypt_ctx_new (crypt);
352
- ASSERT_OK (
353
- mongocrypt_ctx_decrypt_init (
354
- ctx,
355
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
356
- "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
357
- ctx);
358
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
359
- */
360
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
361
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
362
- {
363
- mongocrypt_binary_t *filter = mongocrypt_binary_new ();
364
- ASSERT_OK (mongocrypt_ctx_mongo_op (ctx, filter), ctx);
365
- ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON (
366
- TEST_FILE ("./test/data/fle2-decrypt-ieev/first-filter.json"),
367
- filter);
368
- mongocrypt_binary_destroy (filter);
369
- }
370
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
371
- ctx,
372
- TEST_FILE ("./test/data/keys/"
373
- "12345678123498761234123456789012-local-"
374
- "document.json")),
375
- ctx);
376
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
377
- /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
378
- */
379
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
380
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
381
- {
382
- mongocrypt_binary_t *filter = mongocrypt_binary_new ();
383
- ASSERT_OK (mongocrypt_ctx_mongo_op (ctx, filter), ctx);
384
- ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON (
385
- TEST_FILE ("./test/data/fle2-decrypt-ieev/second-filter.json"),
386
- filter);
387
- mongocrypt_binary_destroy (filter);
388
- }
389
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
390
- ctx,
391
- TEST_FILE ("./test/data/keys/"
392
- "ABCDEFAB123498761234123456789012-local-"
393
- "document.json")),
394
- ctx);
395
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
396
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
397
- out = mongocrypt_binary_new ();
398
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
399
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
400
- _assert_match_bson (
401
- &out_bson,
402
- TMP_BSON ("{'plainText': 'sample', 'encrypted': 'value123'}"));
403
- mongocrypt_binary_destroy (out);
404
- mongocrypt_ctx_destroy (ctx);
405
- mongocrypt_destroy (crypt);
406
- }
407
-
408
- /* Test success with a non-local KMS provider. */
409
- {
410
- mongocrypt_t *crypt =
411
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
412
- mongocrypt_ctx_t *ctx;
413
- mongocrypt_binary_t *out;
414
- bson_t out_bson;
415
-
416
- ctx = mongocrypt_ctx_new (crypt);
417
- ASSERT_OK (
418
- mongocrypt_ctx_decrypt_init (
419
- ctx,
420
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
421
- "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
422
- ctx);
423
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
424
- */
425
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
426
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
427
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
428
- ctx,
429
- TEST_FILE ("./test/data/keys/"
430
- "12345678123498761234123456789012-aws-"
431
- "document.json")),
432
- ctx);
433
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
434
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
435
- {
436
- mongocrypt_kms_ctx_t *kms_ctx = mongocrypt_ctx_next_kms_ctx (ctx);
437
- ASSERT (kms_ctx);
438
- ASSERT_OK (mongocrypt_kms_ctx_feed (
439
- kms_ctx,
440
- TEST_FILE ("./test/data/keys/"
441
- "12345678123498761234123456789012-"
442
- "aws-decrypt-reply.txt")),
443
- kms_ctx);
444
- ASSERT (!mongocrypt_ctx_next_kms_ctx (ctx));
445
- ASSERT_OK (mongocrypt_ctx_kms_done (ctx), ctx);
446
- }
447
- /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
448
- */
449
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
450
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
451
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
452
- ctx,
453
- TEST_FILE ("./test/data/keys/"
454
- "ABCDEFAB123498761234123456789012-aws-"
455
- "document.json")),
456
- ctx);
457
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
458
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_NEED_KMS);
459
- {
460
- mongocrypt_kms_ctx_t *kms_ctx = mongocrypt_ctx_next_kms_ctx (ctx);
461
- ASSERT (kms_ctx);
462
- ASSERT_OK (mongocrypt_kms_ctx_feed (
463
- kms_ctx,
464
- TEST_FILE ("./test/data/keys/"
465
- "ABCDEFAB123498761234123456789012-"
466
- "aws-decrypt-reply.txt")),
467
- kms_ctx);
468
- ASSERT (!mongocrypt_ctx_next_kms_ctx (ctx));
469
- ASSERT_OK (mongocrypt_ctx_kms_done (ctx), ctx);
470
- }
471
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
472
- out = mongocrypt_binary_new ();
473
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
474
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
475
- _assert_match_bson (
476
- &out_bson,
477
- TMP_BSON ("{'plainText': 'sample', 'encrypted': 'value123'}"));
478
- mongocrypt_binary_destroy (out);
479
- mongocrypt_ctx_destroy (ctx);
480
- mongocrypt_destroy (crypt);
481
- }
482
-
483
- /* Test success with two FLE2IndexedEqualityEncryptedValue payloads. */
484
- {
485
- mongocrypt_t *crypt =
486
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
487
- mongocrypt_ctx_t *ctx;
488
- mongocrypt_binary_t *out;
489
- bson_t out_bson;
490
-
491
- ctx = mongocrypt_ctx_new (crypt);
492
- ASSERT_OK (
493
- mongocrypt_ctx_decrypt_init (
494
- ctx,
495
- TEST_BSON ("{'plainText':'sample','encrypted1':{'$binary':{'base64'"
496
- ":'" TEST_IEEV_BASE64 "','subType':'6'}}, "
497
- "'encrypted2':{'$binary':{'base64':'" TEST_IEEV_BASE64
498
- "','subType':'6'}}}")),
499
- ctx);
500
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
501
- */
502
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
503
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
504
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
505
- ctx,
506
- TEST_FILE ("./test/data/keys/"
507
- "12345678123498761234123456789012-local-"
508
- "document.json")),
509
- ctx);
510
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
511
- /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
512
- */
513
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
514
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
515
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
516
- ctx,
517
- TEST_FILE ("./test/data/keys/"
518
- "ABCDEFAB123498761234123456789012-local-"
519
- "document.json")),
520
- ctx);
521
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
522
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
523
- out = mongocrypt_binary_new ();
524
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
525
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
526
- _assert_match_bson (&out_bson,
527
- TMP_BSON ("{'plainText': 'sample', 'encrypted1': "
273
+ static void _test_decrypt_fle2(_mongocrypt_tester_t *tester) {
274
+ _mongocrypt_buffer_t S_KeyId;
275
+ _mongocrypt_buffer_t K_KeyId;
276
+
277
+ if (!_aes_ctr_is_supported_by_os) {
278
+ printf("Common Crypto with no CTR support detected. Skipping.");
279
+ return;
280
+ }
281
+
282
+ #define TEST_IEEV_BASE64 \
283
+ "BxI0VngSNJh2EjQSNFZ4kBICQ7uhTd9C2oI8M1afRon0ZaYG0s6oTmt0aBZ9kO4S4mm5vId01" \
284
+ "BsW7tBHytA8pDJ2IiWBCmah3OGH2M4ET7PSqekQD4gkUCo4JeEttx4yj05Ou4D6yZUmYfVKmE" \
285
+ "ljge16NCxKm7Ir9gvmQsp8x1wqGBzpndA6gkqFxsxfvQ/" \
286
+ "cIqOwMW9dGTTWsfKge+jYkCUIFMfms+XyC/8evQhjjA+qR6eEmV+N/" \
287
+ "kwpR7Q7TJe0lwU5kw2kSe3/KiPKRZZTbn8znadvycfJ0cCWGad9SQ=="
288
+
289
+ _mongocrypt_buffer_copy_from_hex(&S_KeyId, "12345678123498761234123456789012");
290
+ _mongocrypt_buffer_copy_from_hex(&K_KeyId, "ABCDEFAB123498761234123456789012");
291
+
292
+ /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
293
+ {
294
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
295
+ mongocrypt_ctx_t *ctx;
296
+ mongocrypt_binary_t *out;
297
+ bson_t out_bson;
298
+
299
+ ctx = mongocrypt_ctx_new(crypt);
300
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
301
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
302
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
303
+ ctx);
304
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
305
+ */
306
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
307
+ {
308
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
309
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
310
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/first-filter.json"), filter);
311
+ mongocrypt_binary_destroy(filter);
312
+ }
313
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
314
+ TEST_FILE("./test/data/keys/"
315
+ "12345678123498761234123456789012-local-"
316
+ "document.json")),
317
+ ctx);
318
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
319
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
320
+ */
321
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
322
+ {
323
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
324
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
325
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/second-filter.json"), filter);
326
+ mongocrypt_binary_destroy(filter);
327
+ }
328
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
329
+ TEST_FILE("./test/data/keys/"
330
+ "ABCDEFAB123498761234123456789012-local-"
331
+ "document.json")),
332
+ ctx);
333
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
334
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
335
+ out = mongocrypt_binary_new();
336
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
337
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
338
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123'}"));
339
+ mongocrypt_binary_destroy(out);
340
+ mongocrypt_ctx_destroy(ctx);
341
+ mongocrypt_destroy(crypt);
342
+ }
343
+
344
+ /* Test success with a non-local KMS provider. */
345
+ {
346
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
347
+ mongocrypt_ctx_t *ctx;
348
+ mongocrypt_binary_t *out;
349
+ bson_t out_bson;
350
+
351
+ ctx = mongocrypt_ctx_new(crypt);
352
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
353
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
354
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
355
+ ctx);
356
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
357
+ */
358
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
359
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
360
+ TEST_FILE("./test/data/keys/"
361
+ "12345678123498761234123456789012-aws-"
362
+ "document.json")),
363
+ ctx);
364
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
365
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
366
+ {
367
+ mongocrypt_kms_ctx_t *kms_ctx = mongocrypt_ctx_next_kms_ctx(ctx);
368
+ ASSERT(kms_ctx);
369
+ ASSERT_OK(mongocrypt_kms_ctx_feed(kms_ctx,
370
+ TEST_FILE("./test/data/keys/"
371
+ "12345678123498761234123456789012-"
372
+ "aws-decrypt-reply.txt")),
373
+ kms_ctx);
374
+ ASSERT(!mongocrypt_ctx_next_kms_ctx(ctx));
375
+ ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
376
+ }
377
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
378
+ */
379
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
380
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
381
+ TEST_FILE("./test/data/keys/"
382
+ "ABCDEFAB123498761234123456789012-aws-"
383
+ "document.json")),
384
+ ctx);
385
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
386
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
387
+ {
388
+ mongocrypt_kms_ctx_t *kms_ctx = mongocrypt_ctx_next_kms_ctx(ctx);
389
+ ASSERT(kms_ctx);
390
+ ASSERT_OK(mongocrypt_kms_ctx_feed(kms_ctx,
391
+ TEST_FILE("./test/data/keys/"
392
+ "ABCDEFAB123498761234123456789012-"
393
+ "aws-decrypt-reply.txt")),
394
+ kms_ctx);
395
+ ASSERT(!mongocrypt_ctx_next_kms_ctx(ctx));
396
+ ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
397
+ }
398
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
399
+ out = mongocrypt_binary_new();
400
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
401
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
402
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123'}"));
403
+ mongocrypt_binary_destroy(out);
404
+ mongocrypt_ctx_destroy(ctx);
405
+ mongocrypt_destroy(crypt);
406
+ }
407
+
408
+ /* Test success with two FLE2IndexedEqualityEncryptedValue payloads. */
409
+ {
410
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
411
+ mongocrypt_ctx_t *ctx;
412
+ mongocrypt_binary_t *out;
413
+ bson_t out_bson;
414
+
415
+ ctx = mongocrypt_ctx_new(crypt);
416
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
417
+ TEST_BSON("{'plainText':'sample','encrypted1':{'$binary':{'base64'"
418
+ ":'" TEST_IEEV_BASE64 "','subType':'6'}}, "
419
+ "'encrypted2':{'$binary':{'base64':'" TEST_IEEV_BASE64
420
+ "','subType':'6'}}}")),
421
+ ctx);
422
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
423
+ */
424
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
425
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
426
+ TEST_FILE("./test/data/keys/"
427
+ "12345678123498761234123456789012-local-"
428
+ "document.json")),
429
+ ctx);
430
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
431
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
432
+ */
433
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
434
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
435
+ TEST_FILE("./test/data/keys/"
436
+ "ABCDEFAB123498761234123456789012-local-"
437
+ "document.json")),
438
+ ctx);
439
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
440
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
441
+ out = mongocrypt_binary_new();
442
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
443
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
444
+ _assert_match_bson(&out_bson,
445
+ TMP_BSON("{'plainText': 'sample', 'encrypted1': "
528
446
  "'value123', 'encrypted2': 'value123'}"));
529
- mongocrypt_binary_destroy (out);
530
- mongocrypt_ctx_destroy (ctx);
531
- mongocrypt_destroy (crypt);
532
- }
533
-
534
- /* Test success when S_Key is cached, K_Key is not cached. */
535
- {
536
- mongocrypt_t *crypt =
537
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
538
- mongocrypt_ctx_t *ctx;
539
- mongocrypt_binary_t *out;
540
- bson_t out_bson;
541
-
542
- ctx = mongocrypt_ctx_new (crypt);
543
- ASSERT_OK (
544
- mongocrypt_ctx_decrypt_init (
545
- ctx,
546
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
547
- "' " TEST_IEEV_BASE64 "','subType':'6'}}}")),
548
- ctx);
549
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
550
- */
551
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
552
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
553
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
554
- ctx,
555
- TEST_FILE ("./test/data/keys/"
556
- "12345678123498761234123456789012-local-"
557
- "document.json")),
558
- ctx);
559
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
560
- mongocrypt_ctx_destroy (ctx);
561
-
562
- /* Create a new context. S_Key is cached in crypt. */
563
- ctx = mongocrypt_ctx_new (crypt);
564
- ASSERT_OK (
565
- mongocrypt_ctx_decrypt_init (
566
- ctx,
567
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
568
- "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
569
- ctx);
570
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
571
- */
572
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
573
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
574
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
575
- ctx,
576
- TEST_FILE ("./test/data/keys/"
577
- "ABCDEFAB123498761234123456789012-local-"
578
- "document.json")),
579
- ctx);
580
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
581
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
582
- out = mongocrypt_binary_new ();
583
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
584
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
585
- _assert_match_bson (
586
- &out_bson,
587
- TMP_BSON ("{'plainText': 'sample', 'encrypted': 'value123' }"));
588
- mongocrypt_binary_destroy (out);
589
- mongocrypt_ctx_destroy (ctx);
590
- mongocrypt_destroy (crypt);
591
- }
592
-
593
- /* Test success when S_Key is cached, K_Key is cached. */
594
- {
595
- mongocrypt_t *crypt =
596
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
597
- mongocrypt_ctx_t *ctx;
598
- mongocrypt_binary_t *out;
599
- bson_t out_bson;
600
-
601
- ctx = mongocrypt_ctx_new (crypt);
602
- ASSERT_OK (
603
- mongocrypt_ctx_decrypt_init (
604
- ctx,
605
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
606
- "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
607
- ctx);
608
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
609
- */
610
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
611
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
612
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
613
- ctx,
614
- TEST_FILE ("./test/data/keys/"
615
- "12345678123498761234123456789012-local-"
616
- "document.json")),
617
- ctx);
618
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
619
- /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
620
- */
621
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
622
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
623
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
624
- ctx,
625
- TEST_FILE ("./test/data/keys/"
626
- "ABCDEFAB123498761234123456789012-local-"
627
- "document.json")),
628
- ctx);
629
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
630
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
631
- mongocrypt_ctx_destroy (ctx);
632
-
633
- /* Create a new ctx. S_Key and K_Key are cached in crypt. */
634
- ctx = mongocrypt_ctx_new (crypt);
635
- ASSERT_OK (
636
- mongocrypt_ctx_decrypt_init (
637
- ctx,
638
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
639
- "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
640
- ctx);
641
- out = mongocrypt_binary_new ();
642
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
643
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
644
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
645
- _assert_match_bson (
646
- &out_bson,
647
- TMP_BSON ("{'plainText': 'sample', 'encrypted': 'value123'}"));
648
- mongocrypt_binary_destroy (out);
649
- mongocrypt_ctx_destroy (ctx);
650
- mongocrypt_destroy (crypt);
651
- }
652
-
653
- /* Test error when S_Key is not provided. */
654
- {
655
- mongocrypt_t *crypt =
656
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
657
- mongocrypt_ctx_t *ctx;
658
-
659
- ctx = mongocrypt_ctx_new (crypt);
660
- ASSERT_OK (
661
- mongocrypt_ctx_decrypt_init (
662
- ctx,
663
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
664
- "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
665
- ctx);
666
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
667
- */
668
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
669
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
670
- ASSERT_FAILS (mongocrypt_ctx_mongo_done (ctx),
671
- ctx,
672
- "not all keys requested were satisfied");
673
- mongocrypt_ctx_destroy (ctx);
674
- mongocrypt_destroy (crypt);
675
- }
676
-
677
- /* Test error when K_Key is not provided. */
678
- {
679
- mongocrypt_t *crypt =
680
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
681
- mongocrypt_ctx_t *ctx;
682
-
683
- ctx = mongocrypt_ctx_new (crypt);
684
- ASSERT_OK (
685
- mongocrypt_ctx_decrypt_init (
686
- ctx,
687
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
688
- "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
689
- ctx);
690
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
691
- */
692
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
693
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
694
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
695
- ctx,
696
- TEST_FILE ("./test/data/keys/"
697
- "12345678123498761234123456789012-local-"
698
- "document.json")),
699
- ctx);
700
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
701
- /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
702
- */
703
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
704
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
705
- ASSERT_FAILS (mongocrypt_ctx_mongo_done (ctx),
706
- ctx,
707
- "not all keys requested were satisfied");
708
- mongocrypt_ctx_destroy (ctx);
709
- mongocrypt_destroy (crypt);
710
- }
711
-
712
- _mongocrypt_buffer_cleanup (&K_KeyId);
713
- _mongocrypt_buffer_cleanup (&S_KeyId);
447
+ mongocrypt_binary_destroy(out);
448
+ mongocrypt_ctx_destroy(ctx);
449
+ mongocrypt_destroy(crypt);
450
+ }
451
+
452
+ /* Test success when S_Key is cached, K_Key is not cached. */
453
+ {
454
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
455
+ mongocrypt_ctx_t *ctx;
456
+ mongocrypt_binary_t *out;
457
+ bson_t out_bson;
458
+
459
+ ctx = mongocrypt_ctx_new(crypt);
460
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
461
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
462
+ "' " TEST_IEEV_BASE64 "','subType':'6'}}}")),
463
+ ctx);
464
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
465
+ */
466
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
467
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
468
+ TEST_FILE("./test/data/keys/"
469
+ "12345678123498761234123456789012-local-"
470
+ "document.json")),
471
+ ctx);
472
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
473
+ mongocrypt_ctx_destroy(ctx);
474
+
475
+ /* Create a new context. S_Key is cached in crypt. */
476
+ ctx = mongocrypt_ctx_new(crypt);
477
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
478
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
479
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
480
+ ctx);
481
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
482
+ */
483
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
484
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
485
+ TEST_FILE("./test/data/keys/"
486
+ "ABCDEFAB123498761234123456789012-local-"
487
+ "document.json")),
488
+ ctx);
489
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
490
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
491
+ out = mongocrypt_binary_new();
492
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
493
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
494
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123' }"));
495
+ mongocrypt_binary_destroy(out);
496
+ mongocrypt_ctx_destroy(ctx);
497
+ mongocrypt_destroy(crypt);
498
+ }
499
+
500
+ /* Test success when S_Key is cached, K_Key is cached. */
501
+ {
502
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
503
+ mongocrypt_ctx_t *ctx;
504
+ mongocrypt_binary_t *out;
505
+ bson_t out_bson;
506
+
507
+ ctx = mongocrypt_ctx_new(crypt);
508
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
509
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
510
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
511
+ ctx);
512
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
513
+ */
514
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
515
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
516
+ TEST_FILE("./test/data/keys/"
517
+ "12345678123498761234123456789012-local-"
518
+ "document.json")),
519
+ ctx);
520
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
521
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
522
+ */
523
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
524
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
525
+ TEST_FILE("./test/data/keys/"
526
+ "ABCDEFAB123498761234123456789012-local-"
527
+ "document.json")),
528
+ ctx);
529
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
530
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
531
+ mongocrypt_ctx_destroy(ctx);
532
+
533
+ /* Create a new ctx. S_Key and K_Key are cached in crypt. */
534
+ ctx = mongocrypt_ctx_new(crypt);
535
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
536
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
537
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
538
+ ctx);
539
+ out = mongocrypt_binary_new();
540
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
541
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
542
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
543
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123'}"));
544
+ mongocrypt_binary_destroy(out);
545
+ mongocrypt_ctx_destroy(ctx);
546
+ mongocrypt_destroy(crypt);
547
+ }
548
+
549
+ /* Test error when S_Key is not provided. */
550
+ {
551
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
552
+ mongocrypt_ctx_t *ctx;
553
+
554
+ ctx = mongocrypt_ctx_new(crypt);
555
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
556
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
557
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
558
+ ctx);
559
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
560
+ */
561
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
562
+ ASSERT_FAILS(mongocrypt_ctx_mongo_done(ctx), ctx, "not all keys requested were satisfied");
563
+ mongocrypt_ctx_destroy(ctx);
564
+ mongocrypt_destroy(crypt);
565
+ }
566
+
567
+ /* Test error when K_Key is not provided. */
568
+ {
569
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
570
+ mongocrypt_ctx_t *ctx;
571
+
572
+ ctx = mongocrypt_ctx_new(crypt);
573
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
574
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
575
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
576
+ ctx);
577
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
578
+ */
579
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
580
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
581
+ TEST_FILE("./test/data/keys/"
582
+ "12345678123498761234123456789012-local-"
583
+ "document.json")),
584
+ ctx);
585
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
586
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
587
+ */
588
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
589
+ ASSERT_FAILS(mongocrypt_ctx_mongo_done(ctx), ctx, "not all keys requested were satisfied");
590
+ mongocrypt_ctx_destroy(ctx);
591
+ mongocrypt_destroy(crypt);
592
+ }
593
+
594
+ _mongocrypt_buffer_cleanup(&K_KeyId);
595
+ _mongocrypt_buffer_cleanup(&S_KeyId);
714
596
 
715
597
  #undef TEST_IEEV_BASE64
716
598
  }
717
599
 
718
- static void
719
- _test_explicit_decrypt_fle2_ieev (_mongocrypt_tester_t *tester)
720
- {
721
- _mongocrypt_buffer_t S_KeyId;
722
- _mongocrypt_buffer_t K_KeyId;
723
-
724
- if (!_aes_ctr_is_supported_by_os) {
725
- printf ("Common Crypto with no CTR support detected. Skipping.");
726
- return;
727
- }
728
-
729
- #define TEST_IEEV_BASE64 \
730
- "BxI0VngSNJh2EjQSNFZ4kBICQ7uhTd9C2oI8M1afRon0ZaYG0s6oTmt0aBZ9kO4S4mm5vId01" \
731
- "BsW7tBHytA8pDJ2IiWBCmah3OGH2M4ET7PSqekQD4gkUCo4JeEttx4yj05Ou4D6yZUmYfVKmE" \
732
- "ljge16NCxKm7Ir9gvmQsp8x1wqGBzpndA6gkqFxsxfvQ/" \
733
- "cIqOwMW9dGTTWsfKge+jYkCUIFMfms+XyC/8evQhjjA+qR6eEmV+N/" \
734
- "kwpR7Q7TJe0lwU5kw2kSe3/KiPKRZZTbn8znadvycfJ0cCWGad9SQ=="
735
-
736
- _mongocrypt_buffer_copy_from_hex (&S_KeyId,
737
- "12345678123498761234123456789012");
738
- _mongocrypt_buffer_copy_from_hex (&K_KeyId,
739
- "ABCDEFAB123498761234123456789012");
740
-
741
- /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
742
- {
743
- mongocrypt_t *crypt =
744
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
745
- mongocrypt_ctx_t *ctx;
746
- mongocrypt_binary_t *out;
747
- bson_t out_bson;
748
-
749
- ctx = mongocrypt_ctx_new (crypt);
750
- ASSERT_OK (mongocrypt_ctx_explicit_decrypt_init (
751
- ctx,
752
- TEST_BSON ("{'v':{'$binary':{'base64': '" TEST_IEEV_BASE64
753
- "','subType':'6'}}}")),
754
- ctx);
755
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
756
- */
757
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
758
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
759
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
760
- ctx,
761
- TEST_FILE ("./test/data/keys/"
762
- "12345678123498761234123456789012-local-"
763
- "document.json")),
764
- ctx);
765
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
766
- /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
767
- */
768
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
769
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
770
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
771
- ctx,
772
- TEST_FILE ("./test/data/keys/"
773
- "ABCDEFAB123498761234123456789012-local-"
774
- "document.json")),
775
- ctx);
776
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
777
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
778
- out = mongocrypt_binary_new ();
779
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
780
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
781
- _assert_match_bson (&out_bson, TMP_BSON ("{'v': 'value123'}"));
782
- mongocrypt_binary_destroy (out);
783
- mongocrypt_ctx_destroy (ctx);
784
- mongocrypt_destroy (crypt);
785
- }
786
- _mongocrypt_buffer_cleanup (&K_KeyId);
787
- _mongocrypt_buffer_cleanup (&S_KeyId);
600
+ static void _test_explicit_decrypt_fle2_ieev(_mongocrypt_tester_t *tester) {
601
+ _mongocrypt_buffer_t S_KeyId;
602
+ _mongocrypt_buffer_t K_KeyId;
603
+
604
+ if (!_aes_ctr_is_supported_by_os) {
605
+ printf("Common Crypto with no CTR support detected. Skipping.");
606
+ return;
607
+ }
608
+
609
+ #define TEST_IEEV_BASE64 \
610
+ "BxI0VngSNJh2EjQSNFZ4kBICQ7uhTd9C2oI8M1afRon0ZaYG0s6oTmt0aBZ9kO4S4mm5vId01" \
611
+ "BsW7tBHytA8pDJ2IiWBCmah3OGH2M4ET7PSqekQD4gkUCo4JeEttx4yj05Ou4D6yZUmYfVKmE" \
612
+ "ljge16NCxKm7Ir9gvmQsp8x1wqGBzpndA6gkqFxsxfvQ/" \
613
+ "cIqOwMW9dGTTWsfKge+jYkCUIFMfms+XyC/8evQhjjA+qR6eEmV+N/" \
614
+ "kwpR7Q7TJe0lwU5kw2kSe3/KiPKRZZTbn8znadvycfJ0cCWGad9SQ=="
615
+
616
+ _mongocrypt_buffer_copy_from_hex(&S_KeyId, "12345678123498761234123456789012");
617
+ _mongocrypt_buffer_copy_from_hex(&K_KeyId, "ABCDEFAB123498761234123456789012");
618
+
619
+ /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
620
+ {
621
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
622
+ mongocrypt_ctx_t *ctx;
623
+ mongocrypt_binary_t *out;
624
+ bson_t out_bson;
625
+
626
+ ctx = mongocrypt_ctx_new(crypt);
627
+ ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(
628
+ ctx,
629
+ TEST_BSON("{'v':{'$binary':{'base64': '" TEST_IEEV_BASE64 "','subType':'6'}}}")),
630
+ ctx);
631
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
632
+ */
633
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
634
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
635
+ TEST_FILE("./test/data/keys/"
636
+ "12345678123498761234123456789012-local-"
637
+ "document.json")),
638
+ ctx);
639
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
640
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
641
+ */
642
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
643
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
644
+ TEST_FILE("./test/data/keys/"
645
+ "ABCDEFAB123498761234123456789012-local-"
646
+ "document.json")),
647
+ ctx);
648
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
649
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
650
+ out = mongocrypt_binary_new();
651
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
652
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
653
+ _assert_match_bson(&out_bson, TMP_BSON("{'v': 'value123'}"));
654
+ mongocrypt_binary_destroy(out);
655
+ mongocrypt_ctx_destroy(ctx);
656
+ mongocrypt_destroy(crypt);
657
+ }
658
+ _mongocrypt_buffer_cleanup(&K_KeyId);
659
+ _mongocrypt_buffer_cleanup(&S_KeyId);
788
660
 
789
661
  #undef TEST_IEEV_BASE64
790
662
  }
791
663
 
792
- #define TEST_IUP_BASE64 \
793
- "BHEBAAAFZAAgAAAAAHb62aV7+mqmaGcotPLdG3KP7S8diFwWMLM/" \
794
- "5rYtqLrEBXMAIAAAAAAVJ6OWHRv3OtCozHpt3ZzfBhaxZirLv3B+" \
795
- "G8PuaaO4EgVjACAAAAAAsZXWOWA+UiCBbrJNB6bHflB/" \
796
- "cn7pWSvwWN2jw4FPeIUFcABQAAAAAMdD1nV2nqeI1eXEQNskDflCy8I7/" \
797
- "HvvqDKJ6XxjhrPQWdLqjz+8GosGUsB7A8ee/uG9/" \
798
- "guENuL25XD+" \
799
- "Fxxkv1LLXtavHOlLF7iW0u9yabqqBXUAEAAAAAQSNFZ4EjSYdhI0EjRWeJASEHQAAgAAAAV2A" \
800
- "E0AAAAAq83vqxI0mHYSNBI0VniQEkzZZBBDgeZh+h+gXEmOrSFtVvkUcnHWj/" \
801
- "rfPW7iJ0G3UJ8zpuBmUM/VjOMJCY4+eDqdTiPIwX+/vNXegc8FZQAgAAAAAOuac/" \
802
- "eRLYakKX6B0vZ1r3QodOQFfjqJD+xlGiPu4/PsAA=="
803
-
804
- static void
805
- _test_decrypt_fle2_iup (_mongocrypt_tester_t *tester)
806
- {
807
- if (!_aes_ctr_is_supported_by_os) {
808
- printf ("Common Crypto with no CTR support detected. Skipping.");
809
- return;
810
- }
811
-
812
- /* Test success with an FLE2InsertUpdatePayload. */
813
- {
814
- mongocrypt_t *crypt =
815
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
816
- mongocrypt_ctx_t *ctx;
817
- mongocrypt_binary_t *out;
818
- bson_t out_bson;
819
-
820
- ctx = mongocrypt_ctx_new (crypt);
821
- ASSERT_OK (
822
- mongocrypt_ctx_decrypt_init (
823
- ctx,
824
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
825
- "'" TEST_IUP_BASE64 "','subType':'6'}}}")),
826
- ctx);
827
-
828
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
829
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
830
- ASSERT_OK (
831
- mongocrypt_ctx_mongo_feed (
832
- ctx,
833
- TEST_FILE ("./test/data/keys/"
834
- "ABCDEFAB123498761234123456789012-local-document.json")),
835
- ctx);
836
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
837
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
838
- out = mongocrypt_binary_new ();
839
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
840
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
841
- _assert_match_bson (
842
- &out_bson,
843
- TMP_BSON ("{'plainText': 'sample', 'encrypted': 'value123'}"));
844
- mongocrypt_binary_destroy (out);
845
- mongocrypt_ctx_destroy (ctx);
846
- mongocrypt_destroy (crypt);
847
- }
664
+ #define TEST_IUP_BASE64 \
665
+ "BHEBAAAFZAAgAAAAAHb62aV7+mqmaGcotPLdG3KP7S8diFwWMLM/" \
666
+ "5rYtqLrEBXMAIAAAAAAVJ6OWHRv3OtCozHpt3ZzfBhaxZirLv3B+" \
667
+ "G8PuaaO4EgVjACAAAAAAsZXWOWA+UiCBbrJNB6bHflB/" \
668
+ "cn7pWSvwWN2jw4FPeIUFcABQAAAAAMdD1nV2nqeI1eXEQNskDflCy8I7/" \
669
+ "HvvqDKJ6XxjhrPQWdLqjz+8GosGUsB7A8ee/uG9/" \
670
+ "guENuL25XD+" \
671
+ "Fxxkv1LLXtavHOlLF7iW0u9yabqqBXUAEAAAAAQSNFZ4EjSYdhI0EjRWeJASEHQAAgAAAAV2A" \
672
+ "E0AAAAAq83vqxI0mHYSNBI0VniQEkzZZBBDgeZh+h+gXEmOrSFtVvkUcnHWj/" \
673
+ "rfPW7iJ0G3UJ8zpuBmUM/VjOMJCY4+eDqdTiPIwX+/vNXegc8FZQAgAAAAAOuac/" \
674
+ "eRLYakKX6B0vZ1r3QodOQFfjqJD+xlGiPu4/PsAA=="
675
+
676
+ static void _test_decrypt_fle2_iup(_mongocrypt_tester_t *tester) {
677
+ if (!_aes_ctr_is_supported_by_os) {
678
+ printf("Common Crypto with no CTR support detected. Skipping.");
679
+ return;
680
+ }
681
+
682
+ /* Test success with an FLE2InsertUpdatePayload. */
683
+ {
684
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
685
+ mongocrypt_ctx_t *ctx;
686
+ mongocrypt_binary_t *out;
687
+ bson_t out_bson;
688
+
689
+ ctx = mongocrypt_ctx_new(crypt);
690
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
691
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
692
+ "'" TEST_IUP_BASE64 "','subType':'6'}}}")),
693
+ ctx);
694
+
695
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
696
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
697
+ TEST_FILE("./test/data/keys/"
698
+ "ABCDEFAB123498761234123456789012-local-document.json")),
699
+ ctx);
700
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
701
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
702
+ out = mongocrypt_binary_new();
703
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
704
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
705
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123'}"));
706
+ mongocrypt_binary_destroy(out);
707
+ mongocrypt_ctx_destroy(ctx);
708
+ mongocrypt_destroy(crypt);
709
+ }
848
710
  }
711
+
849
712
  #undef TEST_IUP_BASE64
850
713
 
851
714
  /* Test decrypting a BSON binary non-subtype 6 is an error. */
852
- static void
853
- _test_decrypt_wrong_binary_subtype (_mongocrypt_tester_t *tester)
854
- {
855
- mongocrypt_t *crypt =
856
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
857
- mongocrypt_ctx_t *ctx = mongocrypt_ctx_new (crypt);
858
- /* Use subtype 0. */
859
- ASSERT_FAILS (
860
- mongocrypt_ctx_explicit_decrypt_init (
861
- ctx,
862
- TEST_BSON (
863
- "{'v': { '$binary': { 'base64': 'AAAA', 'subType': '00' }}}")),
864
- ctx,
865
- "decryption expected BSON binary subtype 6, got 0");
866
- mongocrypt_ctx_destroy (ctx);
867
- mongocrypt_destroy (crypt);
715
+ static void _test_decrypt_wrong_binary_subtype(_mongocrypt_tester_t *tester) {
716
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
717
+ mongocrypt_ctx_t *ctx = mongocrypt_ctx_new(crypt);
718
+ /* Use subtype 0. */
719
+ ASSERT_FAILS(
720
+ mongocrypt_ctx_explicit_decrypt_init(ctx,
721
+ TEST_BSON("{'v': { '$binary': { 'base64': 'AAAA', 'subType': '00' }}}")),
722
+ ctx,
723
+ "decryption expected BSON binary subtype 6, got 0");
724
+ mongocrypt_ctx_destroy(ctx);
725
+ mongocrypt_destroy(crypt);
868
726
  }
869
727
 
870
- #define TEST_IREV_BASE64 \
871
- "CRI0VngSNJh2EjQSNFZ4kBIQsPF0Ii0Hfv7ZMhnNt/yt+mviydF8EUw0YlO+amC3IF8dX2J/" \
872
- "GmRZRnihW3VqJYoLMk0BIit0x9YQiQEEQPxPcTXnCx4t1fquOY7cRGqIAWTDHuQ9AdUw94EY1" \
873
- "J55mq9UhwD7flh0ySR/SbkTwjIU32U1iM6Bv4AriE4smI87Yd0V7Z7kDoDx7afx9vM/" \
874
- "+h9NWZvpfYcZ+P32sfILb3BdXT5zLrkyc5Xb3myDxE9abTrR8ePG0YuEmeqwGE4bZ6QHKzd/" \
875
- "RLmHciWstKOtER5uRpo3p570wGO8QE9QtQoJp/7N7Su30dK/" \
876
- "bk59hVvlNO6i3nUPwqMd13DePobNGn84q3Fag5O4Kw8P4EGfomFWzxydlVQ0SppGVfan9tIj1" \
877
- "CFu5doYYT4adzX7L9HinKsTWE5ctD9Qxhhzb2cVs5JO96j4mpwOaloF/" \
878
- "4qJhyqlzTEpoCXGQ0X9aeEplibFxQ7FJkaFfYzIDIxA2d6lzwVel3j+VwQ7zOP/" \
879
- "bCnaFu6EP1OQw3ZarsaWGENf45DFuK5RsKX198vZTlqtH24YhAL1+noQTMtpTOp/" \
880
- "6vrczOXkr7dJGQ6RAfliq1maD18PN5yjdyNhr7BXsrK6f01DX2Xr4s51AARxQ/" \
881
- "0U5hmb4HjKg8Sbno4Th+Wza3I0RMgM0YzhRUJz+BXzx2l9NPdeyuECdQ1Q2wP1MNOCBy/" \
882
- "QBJmc+" \
883
- "RWYK57oWCuv5vmkpN8IlriyRv0PGRhYr4ZcLkDdzmuyfK6SGAvIPD4veDJRj3cXEazyMh6g+" \
884
- "rvwt70laxo2IOhvUXDc89WvarthTOzlFt5FNrA8uXhUYyL1q1XSWYCiCu5vRv77BvRUJjf2B6" \
885
- "5kaIKUAGDhYuhch2yU6O9VsHLik3xOGSwIUZJbdMyHY+eA8ZlWZeKJbpjz7a/" \
886
- "TyBQU6VNG4+Z5SXJjURogkODNkx21QS0Z1+b7ZnCSXf1OQceomkDrREB7vyD2HX5rN2/" \
887
- "KIBMgH3J7DnG2VpNhYJ9Ve1hMDGcrQggjkCpdP7lloc6QiH837tD/81gYmr95IbuIHe/" \
888
- "x20oHh9heGHUELnCQ6hXYWOBvSFlGcqZs/" \
889
- "f0qxn5Fe2OfQPRzEstxoW99IdPvgotDnL2vaz2JNFvFqiofc2pIP7XvpFKIoQO7q8LX9z7ah1" \
890
- "Yh8cbi6us8g5y9WzOfh882jU7vQT+31a1ZaeDMbFV1Cemc+/" \
891
- "d0HNksi1qMJtcjrH2MQgXJ3BTyAuJH9OFK8iGqSzHhop9hp5z8mvx834PPjgBfZGt4w/" \
892
- "7qeie+T4sooGVVqA6F3jl8YfFdIUAwkxe5GBQVVvaRLYm/" \
893
- "4SLGBf54Dexi7e0+rL2sG5DeKygNdFzMc6lRO+" \
894
- "gvmAMmDucRm4bxmu7ycNZCQUcuSKoMUWWu6A6eUiyBCQUxrrlX/" \
895
- "3CkRXkQQ6JCwZZMvTgBokYx3WQR6LpW70xWLXyQhav4ZnHKzgITSOe7mUkMJ35NDMD+" \
896
- "qsxXY7sWbGz+b60DWF7yaMVzDPzIGjWLpckMRMxgN3bQ5SE/mFxdjoZD5yYb84q/" \
897
- "O7EjwGA9MSTp9MFEZt7VV3f5TDWiNUZKmjUgOdjBoTSAkVzAO2nqqQNg23x6Z6FQDBeefRkfc" \
898
- "9FoUiBqHuN4fU/zc4Hkthp1McwIkYwRdlgPceD/" \
899
- "BSNbkNRNAnzghBhCquIqpXd8AptBX2qO67rfT7COhpn/" \
900
- "fzVo3ueCRTaM2DtjD3uuH4rMNb3LDjyJFX1DZ5eEWkGq9UE/" \
901
- "AFivfeia4cA0a8Z1LzZcW7WvE5Y1WIZN4gy9SZcNgHEQq8Ad8Q4fAbxe8XJ6/" \
902
- "tNvG+AvAuLEvNJtbhC/4Ei/" \
903
- "JoXplvutDlW5d6g4KEWj4GICqggM5ZSv0TCkbfFkLdaJrOHrn+oI++" \
904
- "krv1U4yQk6P18Mg2bE18ibe+LdWNsqn01V7yDmS+" \
905
- "VAvqQF8f2p4rOOyWsGc7CoyXSrq9LCuGq9eMPR6auo+" \
906
- "tyS1Nek2t6SgpOpzBBDdQnC5sHC1OWTW3ui7w4H0NKCuZOiMncbSDOlegn8C0zZa6Z5iYAce8" \
907
- "a8Ow3jryBEnKBaguhjjOMG8iX/eka8XP+UTxvso4fKVVOXQwobZMdYbf/" \
908
- "sXNJbMbWrFc1S9rdlXL/" \
909
- "nnYvYrRMnOBJ27Mz5vvtOpd4fyQ+wi1q+" \
910
- "5VvuLDM8u51B4oaYqpGUZZ3qVS5BBYm9cDxgMtcdoXjOSopHasdAhron+" \
911
- "NdbGFBxyrUGKnnVXYocEuvsvwhBEA3HUUVV94m3C0agh2eVpmCIyWrs+" \
912
- "grkpAaNLZwXVuzegttJ0GoTxzQnDIWkvlvkS3ZGo25spfPp+/Nda4SZAYRNmtnGfB2TRl0Wx/" \
913
- "o/" \
914
- "V2vx+9qnGyDq52CSkMftpfnsMXAnAv6ps7U+" \
915
- "mgbgNPUFjv1Y0xKaeJdshu1HyEmq5aYqHJSfF2EzvPfH4d0Ijz1lsxMxL4IsqB7kufcOR4FFn" \
916
- "aYXKIXLjRwM5VZNAK/3dvCb3l9H7QMOiJPbdoxAd123aymjz9N/" \
917
- "2O33wMaG6OE8pXp0iYEaW7DOr0FfT913JeUnPNPcqqsA9YXod2UuNWZElTW/" \
918
- "saL32v9akNwA4Jd7Y5VgI4y+XyDH3kAU0Uc8g6YCx/hqcn4pd2+ryH+/" \
919
- "5nVQhnCE0KNOjjrFS92RNLD71GUhWR+VXMw2tKXBUSKnt9Ai4LLJrdvFbwrdqK+" \
920
- "AjBUVqI3MgylNxRw2395ppAbheE1pAcoqLoDOGyOs66Y8kJGpaqs0AmdmZHw2OA26btw+" \
921
- "ceBN+UgScsB5P5wNIup1AvU5J7h1vlFBNygg3WO/MJGCz48xgJ/" \
922
- "klg9wCLQ+vXtrhYJz15RgguADFLBrTcV/Miel20KulnprI+/" \
923
- "lXtRvEAoGJSc0UZ8J7UVTf8kvYzT3hF7XzZzlhKxPYebjdnp2la4o2PkyZXcc/" \
924
- "gFLa7ickR28ZPUigwpW0lK5sJIwWbnZmP5wbQNhiGO8QL9gVpFOnu0xHpu8MqBvfZGf2HiE+" \
925
- "qBUSR89v88gz6u/TVP9zVH1dnk9PE54Uw3yPdxL/" \
926
- "feukvF71sEI6WWd2fdupgRlDGzASrKSAsFbaZobwUViEIFbWo7zPYVZyMglCrD1Xoxdd6EBeU" \
927
- "SJDkS1nhiHOR/7FpIhae8fggAD+StXR7725vzcwIOX21ozRcE2iWw6OP99vDoqLQ8VYzYS0/" \
928
- "f3WMME6b5ndYz25uC0AiULXYI="
728
+ #define TEST_IREV_BASE64 \
729
+ "CRI0VngSNJh2EjQSNFZ4kBIQsPF0Ii0Hfv7ZMhnNt/yt+mviydF8EUw0YlO+amC3IF8dX2J/" \
730
+ "GmRZRnihW3VqJYoLMk0BIit0x9YQiQEEQPxPcTXnCx4t1fquOY7cRGqIAWTDHuQ9AdUw94EY1" \
731
+ "J55mq9UhwD7flh0ySR/SbkTwjIU32U1iM6Bv4AriE4smI87Yd0V7Z7kDoDx7afx9vM/" \
732
+ "+h9NWZvpfYcZ+P32sfILb3BdXT5zLrkyc5Xb3myDxE9abTrR8ePG0YuEmeqwGE4bZ6QHKzd/" \
733
+ "RLmHciWstKOtER5uRpo3p570wGO8QE9QtQoJp/7N7Su30dK/" \
734
+ "bk59hVvlNO6i3nUPwqMd13DePobNGn84q3Fag5O4Kw8P4EGfomFWzxydlVQ0SppGVfan9tIj1" \
735
+ "CFu5doYYT4adzX7L9HinKsTWE5ctD9Qxhhzb2cVs5JO96j4mpwOaloF/" \
736
+ "4qJhyqlzTEpoCXGQ0X9aeEplibFxQ7FJkaFfYzIDIxA2d6lzwVel3j+VwQ7zOP/" \
737
+ "bCnaFu6EP1OQw3ZarsaWGENf45DFuK5RsKX198vZTlqtH24YhAL1+noQTMtpTOp/" \
738
+ "6vrczOXkr7dJGQ6RAfliq1maD18PN5yjdyNhr7BXsrK6f01DX2Xr4s51AARxQ/" \
739
+ "0U5hmb4HjKg8Sbno4Th+Wza3I0RMgM0YzhRUJz+BXzx2l9NPdeyuECdQ1Q2wP1MNOCBy/" \
740
+ "QBJmc+" \
741
+ "RWYK57oWCuv5vmkpN8IlriyRv0PGRhYr4ZcLkDdzmuyfK6SGAvIPD4veDJRj3cXEazyMh6g+" \
742
+ "rvwt70laxo2IOhvUXDc89WvarthTOzlFt5FNrA8uXhUYyL1q1XSWYCiCu5vRv77BvRUJjf2B6" \
743
+ "5kaIKUAGDhYuhch2yU6O9VsHLik3xOGSwIUZJbdMyHY+eA8ZlWZeKJbpjz7a/" \
744
+ "TyBQU6VNG4+Z5SXJjURogkODNkx21QS0Z1+b7ZnCSXf1OQceomkDrREB7vyD2HX5rN2/" \
745
+ "KIBMgH3J7DnG2VpNhYJ9Ve1hMDGcrQggjkCpdP7lloc6QiH837tD/81gYmr95IbuIHe/" \
746
+ "x20oHh9heGHUELnCQ6hXYWOBvSFlGcqZs/" \
747
+ "f0qxn5Fe2OfQPRzEstxoW99IdPvgotDnL2vaz2JNFvFqiofc2pIP7XvpFKIoQO7q8LX9z7ah1" \
748
+ "Yh8cbi6us8g5y9WzOfh882jU7vQT+31a1ZaeDMbFV1Cemc+/" \
749
+ "d0HNksi1qMJtcjrH2MQgXJ3BTyAuJH9OFK8iGqSzHhop9hp5z8mvx834PPjgBfZGt4w/" \
750
+ "7qeie+T4sooGVVqA6F3jl8YfFdIUAwkxe5GBQVVvaRLYm/" \
751
+ "4SLGBf54Dexi7e0+rL2sG5DeKygNdFzMc6lRO+" \
752
+ "gvmAMmDucRm4bxmu7ycNZCQUcuSKoMUWWu6A6eUiyBCQUxrrlX/" \
753
+ "3CkRXkQQ6JCwZZMvTgBokYx3WQR6LpW70xWLXyQhav4ZnHKzgITSOe7mUkMJ35NDMD+" \
754
+ "qsxXY7sWbGz+b60DWF7yaMVzDPzIGjWLpckMRMxgN3bQ5SE/mFxdjoZD5yYb84q/" \
755
+ "O7EjwGA9MSTp9MFEZt7VV3f5TDWiNUZKmjUgOdjBoTSAkVzAO2nqqQNg23x6Z6FQDBeefRkfc" \
756
+ "9FoUiBqHuN4fU/zc4Hkthp1McwIkYwRdlgPceD/" \
757
+ "BSNbkNRNAnzghBhCquIqpXd8AptBX2qO67rfT7COhpn/" \
758
+ "fzVo3ueCRTaM2DtjD3uuH4rMNb3LDjyJFX1DZ5eEWkGq9UE/" \
759
+ "AFivfeia4cA0a8Z1LzZcW7WvE5Y1WIZN4gy9SZcNgHEQq8Ad8Q4fAbxe8XJ6/" \
760
+ "tNvG+AvAuLEvNJtbhC/4Ei/" \
761
+ "JoXplvutDlW5d6g4KEWj4GICqggM5ZSv0TCkbfFkLdaJrOHrn+oI++" \
762
+ "krv1U4yQk6P18Mg2bE18ibe+LdWNsqn01V7yDmS+" \
763
+ "VAvqQF8f2p4rOOyWsGc7CoyXSrq9LCuGq9eMPR6auo+" \
764
+ "tyS1Nek2t6SgpOpzBBDdQnC5sHC1OWTW3ui7w4H0NKCuZOiMncbSDOlegn8C0zZa6Z5iYAce8" \
765
+ "a8Ow3jryBEnKBaguhjjOMG8iX/eka8XP+UTxvso4fKVVOXQwobZMdYbf/" \
766
+ "sXNJbMbWrFc1S9rdlXL/" \
767
+ "nnYvYrRMnOBJ27Mz5vvtOpd4fyQ+wi1q+" \
768
+ "5VvuLDM8u51B4oaYqpGUZZ3qVS5BBYm9cDxgMtcdoXjOSopHasdAhron+" \
769
+ "NdbGFBxyrUGKnnVXYocEuvsvwhBEA3HUUVV94m3C0agh2eVpmCIyWrs+" \
770
+ "grkpAaNLZwXVuzegttJ0GoTxzQnDIWkvlvkS3ZGo25spfPp+/Nda4SZAYRNmtnGfB2TRl0Wx/" \
771
+ "o/" \
772
+ "V2vx+9qnGyDq52CSkMftpfnsMXAnAv6ps7U+" \
773
+ "mgbgNPUFjv1Y0xKaeJdshu1HyEmq5aYqHJSfF2EzvPfH4d0Ijz1lsxMxL4IsqB7kufcOR4FFn" \
774
+ "aYXKIXLjRwM5VZNAK/3dvCb3l9H7QMOiJPbdoxAd123aymjz9N/" \
775
+ "2O33wMaG6OE8pXp0iYEaW7DOr0FfT913JeUnPNPcqqsA9YXod2UuNWZElTW/" \
776
+ "saL32v9akNwA4Jd7Y5VgI4y+XyDH3kAU0Uc8g6YCx/hqcn4pd2+ryH+/" \
777
+ "5nVQhnCE0KNOjjrFS92RNLD71GUhWR+VXMw2tKXBUSKnt9Ai4LLJrdvFbwrdqK+" \
778
+ "AjBUVqI3MgylNxRw2395ppAbheE1pAcoqLoDOGyOs66Y8kJGpaqs0AmdmZHw2OA26btw+" \
779
+ "ceBN+UgScsB5P5wNIup1AvU5J7h1vlFBNygg3WO/MJGCz48xgJ/" \
780
+ "klg9wCLQ+vXtrhYJz15RgguADFLBrTcV/Miel20KulnprI+/" \
781
+ "lXtRvEAoGJSc0UZ8J7UVTf8kvYzT3hF7XzZzlhKxPYebjdnp2la4o2PkyZXcc/" \
782
+ "gFLa7ickR28ZPUigwpW0lK5sJIwWbnZmP5wbQNhiGO8QL9gVpFOnu0xHpu8MqBvfZGf2HiE+" \
783
+ "qBUSR89v88gz6u/TVP9zVH1dnk9PE54Uw3yPdxL/" \
784
+ "feukvF71sEI6WWd2fdupgRlDGzASrKSAsFbaZobwUViEIFbWo7zPYVZyMglCrD1Xoxdd6EBeU" \
785
+ "SJDkS1nhiHOR/7FpIhae8fggAD+StXR7725vzcwIOX21ozRcE2iWw6OP99vDoqLQ8VYzYS0/" \
786
+ "f3WMME6b5ndYz25uC0AiULXYI="
929
787
 
930
788
  /* Test decrypting FLE2IndexedRangeEncryptedValue */
931
- static void
932
- _test_decrypt_fle2_irev (_mongocrypt_tester_t *tester)
933
- {
934
- if (!_aes_ctr_is_supported_by_os) {
935
- printf ("Common Crypto with no CTR support detected. Skipping.");
936
- return;
937
- }
938
-
939
- /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
940
- {
941
- mongocrypt_t *crypt =
942
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
943
- mongocrypt_ctx_t *ctx;
944
- mongocrypt_binary_t *out;
945
- bson_t out_bson;
946
-
947
- ctx = mongocrypt_ctx_new (crypt);
948
- ASSERT_OK (
949
- mongocrypt_ctx_decrypt_init (
950
- ctx,
951
- TEST_BSON ("{'plainText':'sample','encrypted':{'$binary':{'base64':"
952
- "'" TEST_IREV_BASE64 "','subType':'6'}}}")),
953
- ctx);
954
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
955
- */
956
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
957
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
958
- {
959
- mongocrypt_binary_t *filter = mongocrypt_binary_new ();
960
- ASSERT_OK (mongocrypt_ctx_mongo_op (ctx, filter), ctx);
961
- ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON (
962
- TEST_FILE ("./test/data/fle2-decrypt-ieev/first-filter.json"),
963
- filter);
964
- mongocrypt_binary_destroy (filter);
965
- }
966
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
967
- ctx,
968
- TEST_FILE ("./test/data/keys/"
969
- "12345678123498761234123456789012-local-"
970
- "document.json")),
971
- ctx);
972
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
973
- /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
974
- */
975
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
976
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
977
- {
978
- mongocrypt_binary_t *filter = mongocrypt_binary_new ();
979
- ASSERT_OK (mongocrypt_ctx_mongo_op (ctx, filter), ctx);
980
- ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON (
981
- TEST_FILE ("./test/data/fle2-decrypt-ieev/second-filter.json"),
982
- filter);
983
- mongocrypt_binary_destroy (filter);
984
- }
985
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
986
- ctx,
987
- TEST_FILE ("./test/data/keys/"
988
- "ABCDEFAB123498761234123456789012-local-"
989
- "document.json")),
990
- ctx);
991
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
992
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
993
- out = mongocrypt_binary_new ();
994
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
995
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
996
- _assert_match_bson (
997
- &out_bson, TMP_BSON ("{'plainText': 'sample', 'encrypted': 123456}"));
998
- mongocrypt_binary_destroy (out);
999
- mongocrypt_ctx_destroy (ctx);
1000
- mongocrypt_destroy (crypt);
1001
- }
789
+ static void _test_decrypt_fle2_irev(_mongocrypt_tester_t *tester) {
790
+ if (!_aes_ctr_is_supported_by_os) {
791
+ printf("Common Crypto with no CTR support detected. Skipping.");
792
+ return;
793
+ }
794
+
795
+ /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
796
+ {
797
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
798
+ mongocrypt_ctx_t *ctx;
799
+ mongocrypt_binary_t *out;
800
+ bson_t out_bson;
801
+
802
+ ctx = mongocrypt_ctx_new(crypt);
803
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
804
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
805
+ "'" TEST_IREV_BASE64 "','subType':'6'}}}")),
806
+ ctx);
807
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
808
+ */
809
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
810
+ {
811
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
812
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
813
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/first-filter.json"), filter);
814
+ mongocrypt_binary_destroy(filter);
815
+ }
816
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
817
+ TEST_FILE("./test/data/keys/"
818
+ "12345678123498761234123456789012-local-"
819
+ "document.json")),
820
+ ctx);
821
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
822
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
823
+ */
824
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
825
+ {
826
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
827
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
828
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/second-filter.json"), filter);
829
+ mongocrypt_binary_destroy(filter);
830
+ }
831
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
832
+ TEST_FILE("./test/data/keys/"
833
+ "ABCDEFAB123498761234123456789012-local-"
834
+ "document.json")),
835
+ ctx);
836
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
837
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
838
+ out = mongocrypt_binary_new();
839
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
840
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
841
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 123456}"));
842
+ mongocrypt_binary_destroy(out);
843
+ mongocrypt_ctx_destroy(ctx);
844
+ mongocrypt_destroy(crypt);
845
+ }
1002
846
  }
1003
847
 
1004
848
  // Test explicitly decrypting an FLE2IndexedRangeEncryptedValue.
1005
- static void
1006
- _test_explicit_decrypt_fle2_irev (_mongocrypt_tester_t *tester)
1007
- {
1008
- if (!_aes_ctr_is_supported_by_os) {
1009
- printf ("Common Crypto with no CTR support detected. Skipping.");
1010
- return;
1011
- }
1012
-
1013
- mongocrypt_t *crypt =
1014
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
1015
- mongocrypt_ctx_t *ctx;
1016
- mongocrypt_binary_t *out;
1017
- bson_t out_bson;
1018
-
1019
- ctx = mongocrypt_ctx_new (crypt);
1020
- ASSERT_OK (mongocrypt_ctx_explicit_decrypt_init (
1021
- ctx,
1022
- TEST_BSON ("{'v': {'$binary':{'base64':'" TEST_IREV_BASE64
1023
- "','subType':'6'}}}")),
849
+ static void _test_explicit_decrypt_fle2_irev(_mongocrypt_tester_t *tester) {
850
+ if (!_aes_ctr_is_supported_by_os) {
851
+ printf("Common Crypto with no CTR support detected. Skipping.");
852
+ return;
853
+ }
854
+
855
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
856
+ mongocrypt_ctx_t *ctx;
857
+ mongocrypt_binary_t *out;
858
+ bson_t out_bson;
859
+
860
+ ctx = mongocrypt_ctx_new(crypt);
861
+ ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(
862
+ ctx,
863
+ TEST_BSON("{'v': {'$binary':{'base64':'" TEST_IREV_BASE64 "','subType':'6'}}}")),
1024
864
  ctx);
1025
- /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
1026
- */
1027
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
1028
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
1029
- {
1030
- mongocrypt_binary_t *filter = mongocrypt_binary_new ();
1031
- ASSERT_OK (mongocrypt_ctx_mongo_op (ctx, filter), ctx);
1032
- ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON (
1033
- TEST_FILE ("./test/data/fle2-decrypt-ieev/first-filter.json"), filter);
1034
- mongocrypt_binary_destroy (filter);
1035
- }
1036
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
1037
- ctx,
1038
- TEST_FILE ("./test/data/keys/"
1039
- "12345678123498761234123456789012-local-"
1040
- "document.json")),
865
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
866
+ */
867
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
868
+ {
869
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
870
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
871
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/first-filter.json"), filter);
872
+ mongocrypt_binary_destroy(filter);
873
+ }
874
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
875
+ TEST_FILE("./test/data/keys/"
876
+ "12345678123498761234123456789012-local-"
877
+ "document.json")),
1041
878
  ctx);
1042
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
1043
- /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
1044
- */
1045
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
1046
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
1047
- {
1048
- mongocrypt_binary_t *filter = mongocrypt_binary_new ();
1049
- ASSERT_OK (mongocrypt_ctx_mongo_op (ctx, filter), ctx);
1050
- ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON (
1051
- TEST_FILE ("./test/data/fle2-decrypt-ieev/second-filter.json"),
1052
- filter);
1053
- mongocrypt_binary_destroy (filter);
1054
- }
1055
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
1056
- ctx,
1057
- TEST_FILE ("./test/data/keys/"
1058
- "ABCDEFAB123498761234123456789012-local-"
1059
- "document.json")),
879
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
880
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
881
+ */
882
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
883
+ {
884
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
885
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
886
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/second-filter.json"), filter);
887
+ mongocrypt_binary_destroy(filter);
888
+ }
889
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
890
+ TEST_FILE("./test/data/keys/"
891
+ "ABCDEFAB123498761234123456789012-local-"
892
+ "document.json")),
1060
893
  ctx);
1061
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
1062
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
1063
- out = mongocrypt_binary_new ();
1064
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
1065
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
1066
- _assert_match_bson (&out_bson, TMP_BSON ("{'v': 123456}"));
1067
- mongocrypt_binary_destroy (out);
1068
- mongocrypt_ctx_destroy (ctx);
1069
- mongocrypt_destroy (crypt);
894
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
895
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
896
+ out = mongocrypt_binary_new();
897
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
898
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
899
+ _assert_match_bson(&out_bson, TMP_BSON("{'v': 123456}"));
900
+ mongocrypt_binary_destroy(out);
901
+ mongocrypt_ctx_destroy(ctx);
902
+ mongocrypt_destroy(crypt);
1070
903
  }
1071
904
 
1072
905
  #undef TEST_IREV_BASE64
1073
906
 
1074
907
  // Test explicitly decrypting an FLE2InsertUpdatePayload with edges.
1075
- static void
1076
- _test_explicit_decrypt_fle2_iup_with_edges (_mongocrypt_tester_t *tester)
1077
- {
1078
- if (!_aes_ctr_is_supported_by_os) {
1079
- printf ("Common Crypto with no CTR support detected. Skipping.");
1080
- return;
1081
- }
1082
-
1083
- /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
1084
- mongocrypt_t *crypt =
1085
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
1086
- mongocrypt_ctx_t *ctx;
1087
- mongocrypt_binary_t *out;
1088
- bson_t out_bson;
1089
-
1090
- ctx = mongocrypt_ctx_new (crypt);
1091
- ASSERT_OK (mongocrypt_ctx_explicit_decrypt_init (
1092
- ctx,
1093
- TEST_FILE ("./test/data/fle2-insert-range-explicit/int32/"
1094
- "encrypted-payload.json")),
908
+ static void _test_explicit_decrypt_fle2_iup_with_edges(_mongocrypt_tester_t *tester) {
909
+ if (!_aes_ctr_is_supported_by_os) {
910
+ printf("Common Crypto with no CTR support detected. Skipping.");
911
+ return;
912
+ }
913
+
914
+ /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
915
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
916
+ mongocrypt_ctx_t *ctx;
917
+ mongocrypt_binary_t *out;
918
+ bson_t out_bson;
919
+
920
+ ctx = mongocrypt_ctx_new(crypt);
921
+ ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(ctx,
922
+ TEST_FILE("./test/data/fle2-insert-range-explicit/int32/"
923
+ "encrypted-payload.json")),
1095
924
  ctx);
1096
925
 
1097
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx),
1098
- MONGOCRYPT_CTX_NEED_MONGO_KEYS);
1099
- ASSERT_OK (mongocrypt_ctx_mongo_feed (
1100
- ctx,
1101
- TEST_FILE ("./test/data/keys/"
1102
- "ABCDEFAB123498761234123456789012-local-"
1103
- "document.json")),
926
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
927
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
928
+ TEST_FILE("./test/data/keys/"
929
+ "ABCDEFAB123498761234123456789012-local-"
930
+ "document.json")),
1104
931
  ctx);
1105
- ASSERT_OK (mongocrypt_ctx_mongo_done (ctx), ctx);
1106
- ASSERT_STATE_EQUAL (mongocrypt_ctx_state (ctx), MONGOCRYPT_CTX_READY);
1107
- out = mongocrypt_binary_new ();
1108
- ASSERT_OK (mongocrypt_ctx_finalize (ctx, out), ctx);
1109
- ASSERT (_mongocrypt_binary_to_bson (out, &out_bson));
1110
- _assert_match_bson (&out_bson, TMP_BSON ("{'v': 123456}"));
1111
- mongocrypt_binary_destroy (out);
1112
- mongocrypt_ctx_destroy (ctx);
1113
- mongocrypt_destroy (crypt);
932
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
933
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
934
+ out = mongocrypt_binary_new();
935
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
936
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
937
+ _assert_match_bson(&out_bson, TMP_BSON("{'v': 123456}"));
938
+ mongocrypt_binary_destroy(out);
939
+ mongocrypt_ctx_destroy(ctx);
940
+ mongocrypt_destroy(crypt);
1114
941
  }
1115
942
 
1116
- void
1117
- _mongocrypt_tester_install_ctx_decrypt (_mongocrypt_tester_t *tester)
1118
- {
1119
- INSTALL_TEST (_test_explicit_decrypt_init);
1120
- INSTALL_TEST (_test_decrypt_init);
1121
- INSTALL_TEST (_test_decrypt_need_keys);
1122
- INSTALL_TEST (_test_decrypt_ready);
1123
- INSTALL_TEST (_test_decrypt_empty_aws);
1124
- INSTALL_TEST (_test_decrypt_empty_binary);
1125
- INSTALL_TEST (_test_decrypt_per_ctx_credentials);
1126
- INSTALL_TEST (_test_decrypt_per_ctx_credentials_local);
1127
- INSTALL_TEST (_test_decrypt_fle2);
1128
- INSTALL_TEST (_test_explicit_decrypt_fle2_ieev);
1129
- INSTALL_TEST (_test_decrypt_fle2_iup);
1130
- INSTALL_TEST (_test_decrypt_wrong_binary_subtype);
1131
- INSTALL_TEST (_test_decrypt_fle2_irev);
1132
- INSTALL_TEST (_test_explicit_decrypt_fle2_irev);
1133
- INSTALL_TEST (_test_explicit_decrypt_fle2_iup_with_edges);
943
+ void _mongocrypt_tester_install_ctx_decrypt(_mongocrypt_tester_t *tester) {
944
+ INSTALL_TEST(_test_explicit_decrypt_init);
945
+ INSTALL_TEST(_test_decrypt_init);
946
+ INSTALL_TEST(_test_decrypt_need_keys);
947
+ INSTALL_TEST(_test_decrypt_ready);
948
+ INSTALL_TEST(_test_decrypt_empty_aws);
949
+ INSTALL_TEST(_test_decrypt_empty_binary);
950
+ INSTALL_TEST(_test_decrypt_per_ctx_credentials);
951
+ INSTALL_TEST(_test_decrypt_per_ctx_credentials_local);
952
+ INSTALL_TEST(_test_decrypt_fle2);
953
+ INSTALL_TEST(_test_explicit_decrypt_fle2_ieev);
954
+ INSTALL_TEST(_test_decrypt_fle2_iup);
955
+ INSTALL_TEST(_test_decrypt_wrong_binary_subtype);
956
+ INSTALL_TEST(_test_decrypt_fle2_irev);
957
+ INSTALL_TEST(_test_explicit_decrypt_fle2_irev);
958
+ INSTALL_TEST(_test_explicit_decrypt_fle2_iup_with_edges);
1134
959
  }