libmongocrypt-helper 1.7.4.0.1002 → 1.8.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (396) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
  4. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
  6. data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
  7. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
  14. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
  15. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
  16. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
  19. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
  20. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
  21. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
  22. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
  23. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
  24. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
  25. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
  26. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
  27. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
  28. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
  31. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
  32. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
  33. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
  34. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
  35. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
  36. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
  37. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
  38. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
  39. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
  41. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
  44. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
  45. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
  46. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
  61. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
  62. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
  63. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  64. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  65. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
  66. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  67. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  68. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  69. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  70. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  71. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  72. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  73. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  74. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  75. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  76. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  77. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
  78. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  79. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  80. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  81. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  82. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  83. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  84. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  85. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
  86. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
  87. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  88. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
  89. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
  90. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  91. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  92. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  93. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  94. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
  95. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
  96. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
  97. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  98. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
  99. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
  100. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
  101. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  102. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  103. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  104. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  105. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
  106. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  107. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  108. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  109. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  110. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  111. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  112. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  113. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
  114. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
  115. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
  116. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
  117. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
  118. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
  119. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
  120. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
  121. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
  122. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
  123. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
  124. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
  125. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  126. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  127. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
  128. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
  129. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  130. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  131. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  132. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  133. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  134. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
  135. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
  136. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  137. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  138. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  139. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  140. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  141. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  142. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  143. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
  144. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  145. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  146. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
  147. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  148. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  149. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  150. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
  151. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
  152. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
  153. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  154. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  155. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  156. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  157. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  158. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  159. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
  160. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
  161. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  162. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
  163. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
  164. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  165. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
  166. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
  194. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
  195. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  196. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
  197. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  198. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  199. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  200. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
  202. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  203. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  231. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  243. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  244. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  245. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  246. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  247. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  248. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  249. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  250. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  251. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  252. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  253. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  261. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  262. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  263. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  271. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  272. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  276. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  277. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  281. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  282. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  283. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  284. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  285. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  286. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  288. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  303. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  314. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
  315. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  316. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  317. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  318. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
  319. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  320. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  323. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
  324. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  325. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  326. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  327. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  328. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
  329. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
  330. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
  331. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
  332. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  333. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
  334. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  335. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
  336. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
  337. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  338. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  339. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
  340. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  341. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  342. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
  343. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
  344. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
  345. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
  346. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  347. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  348. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
  349. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
  350. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  351. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
  352. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
  353. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  354. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  355. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  356. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  357. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  358. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  359. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
  360. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  361. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  362. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  363. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
  364. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  365. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
  366. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
  367. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
  368. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
  369. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
  370. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
  371. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
  372. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  373. data/lib/libmongocrypt_helper/version.rb +2 -2
  374. data.tar.gz.sig +0 -0
  375. metadata +154 -26
  376. metadata.gz.sig +0 -0
  377. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  378. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  379. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  380. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  381. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  382. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  383. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  384. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  392. /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
  393. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  394. /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
  395. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  396. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -16,1119 +16,941 @@
16
16
 
17
17
  #include "mongocrypt-ctx-private.h"
18
18
  #include "mongocrypt.h"
19
- #include "test-mongocrypt.h"
20
19
  #include "test-mongocrypt-assert-match-bson.h"
20
+ #include "test-mongocrypt.h"
21
21
 
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);
22
+ static void _test_explicit_decrypt_init(_mongocrypt_tester_t *tester) {
23
+ mongocrypt_t *crypt;
24
+ mongocrypt_ctx_t *ctx;
25
+ mongocrypt_binary_t *msg;
26
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
29
27
 
30
- msg = TEST_BSON ("{ 'v': { '$binary': { 'subType': '06', 'base64': "
28
+ msg = TEST_BSON("{ 'v': { '$binary': { 'subType': '06', 'base64': "
31
29
  "'AWFhYWFhYWFhYWFhYWFhYWECRTOW9yZzNDn5dGwuqsrJQNLtgMEKaujhs"
32
30
  "9aRWRp+7Yo3JK8N8jC8P0Xjll6C1CwLsE/"
33
31
  "iP5wjOMhVv1KMMyOCSCrHorXRsb2IKPtzl2lKTqQ=' } } }");
34
32
 
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);
33
+ /* NULL document. */
34
+ ctx = mongocrypt_ctx_new(crypt);
35
+ ASSERT_FAILS(mongocrypt_ctx_explicit_decrypt_init(ctx, NULL), ctx, "invalid msg");
36
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_ERROR);
37
+ mongocrypt_ctx_destroy(ctx);
41
38
 
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);
39
+ /* Success. */
40
+ ctx = mongocrypt_ctx_new(crypt);
41
+ ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(ctx, msg), ctx);
42
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_MONGO_KEYS);
43
+ mongocrypt_ctx_destroy(ctx);
47
44
 
48
- mongocrypt_destroy (crypt);
45
+ mongocrypt_destroy(crypt);
49
46
  }
50
47
 
51
-
52
48
  /* 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
-
49
+ static void _test_decrypt_init(_mongocrypt_tester_t *tester) {
50
+ mongocrypt_t *crypt;
51
+ mongocrypt_ctx_t *ctx;
52
+ mongocrypt_binary_t *encrypted;
80
53
 
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;
54
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
87
55
 
88
- encrypted = _mongocrypt_tester_encrypted_doc (tester);
56
+ encrypted = _mongocrypt_tester_encrypted_doc(tester);
89
57
 
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. */
58
+ /* Success. */
59
+ ctx = mongocrypt_ctx_new(crypt);
60
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, encrypted), ctx);
61
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_MONGO_KEYS);
62
+ mongocrypt_ctx_destroy(ctx);
101
63
 
102
- /* TODO: CDRIVER-3044 test that decryption warns when keys are not
103
- * found/inactive. */
64
+ /* NULL document. */
65
+ ctx = mongocrypt_ctx_new(crypt);
66
+ ASSERT_FAILS(mongocrypt_ctx_decrypt_init(ctx, NULL), ctx, "invalid doc");
67
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_ERROR);
68
+ mongocrypt_ctx_destroy(ctx);
104
69
 
105
- mongocrypt_binary_destroy (encrypted);
70
+ mongocrypt_binary_destroy(encrypted);
71
+ mongocrypt_destroy(crypt);
106
72
  }
107
73
 
74
+ static void _test_decrypt_need_keys(_mongocrypt_tester_t *tester) {
75
+ mongocrypt_t *crypt;
76
+ mongocrypt_ctx_t *ctx;
77
+ mongocrypt_binary_t *encrypted;
78
+
79
+ encrypted = _mongocrypt_tester_encrypted_doc(tester);
80
+
81
+ /* Success. */
82
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
83
+ ctx = mongocrypt_ctx_new(crypt);
84
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, encrypted), ctx);
85
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/example/key-document.json")), ctx);
86
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
87
+ BSON_ASSERT(mongocrypt_ctx_state(ctx) == MONGOCRYPT_CTX_NEED_KMS);
88
+ mongocrypt_ctx_destroy(ctx);
89
+ mongocrypt_destroy(crypt); /* recreate crypt because of caching. */
108
90
 
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);
91
+ /* TODO: CDRIVER-3044 test that decryption warns when keys are not
92
+ * found/inactive. */
93
+
94
+ mongocrypt_binary_destroy(encrypted);
137
95
  }
138
96
 
97
+ static void _test_decrypt_ready(_mongocrypt_tester_t *tester) {
98
+ mongocrypt_t *crypt;
99
+ mongocrypt_ctx_t *ctx;
100
+ mongocrypt_binary_t *encrypted, *decrypted;
101
+ bson_t as_bson;
102
+ bson_iter_t iter;
103
+
104
+ encrypted = _mongocrypt_tester_encrypted_doc(tester);
105
+ decrypted = mongocrypt_binary_new();
106
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
107
+
108
+ /* Success. */
109
+ ctx = mongocrypt_ctx_new(crypt);
110
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, encrypted), ctx);
111
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
112
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, decrypted), ctx);
113
+ BSON_ASSERT(_mongocrypt_binary_to_bson(decrypted, &as_bson));
114
+ bson_iter_init(&iter, &as_bson);
115
+ bson_iter_find_descendant(&iter, "filter.ssn", &iter);
116
+ BSON_ASSERT(BSON_ITER_HOLDS_UTF8(&iter));
117
+ BSON_ASSERT(0 == strcmp(bson_iter_utf8(&iter, NULL), _mongocrypt_tester_plaintext(tester)));
118
+ mongocrypt_binary_destroy(decrypted);
119
+ mongocrypt_ctx_destroy(ctx);
120
+ mongocrypt_destroy(crypt);
121
+ mongocrypt_binary_destroy(encrypted);
122
+ }
139
123
 
140
124
  /* 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")),
125
+ void _test_decrypt_empty_aws(_mongocrypt_tester_t *tester) {
126
+ mongocrypt_t *crypt;
127
+ mongocrypt_ctx_t *ctx;
128
+
129
+ crypt = mongocrypt_new();
130
+ ASSERT_OK(mongocrypt_setopt_kms_provider_aws(crypt, "", -1, "", -1), crypt);
131
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
132
+
133
+ ctx = mongocrypt_ctx_new(crypt);
134
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, TEST_FILE("./test/data/encrypted-cmd.json")), ctx);
135
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
136
+ ASSERT_FAILS(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/example/key-document.json")),
159
137
  ctx,
160
138
  "failed to create KMS message");
161
139
 
162
- mongocrypt_ctx_destroy (ctx);
163
- mongocrypt_destroy (crypt);
140
+ mongocrypt_ctx_destroy(ctx);
141
+ mongocrypt_destroy(crypt);
164
142
  }
165
143
 
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);
144
+ static void _test_decrypt_empty_binary(_mongocrypt_tester_t *tester) {
145
+ mongocrypt_t *crypt;
146
+ mongocrypt_ctx_t *ctx;
147
+ mongocrypt_binary_t *bin;
148
+ _mongocrypt_buffer_t encrypted;
149
+
150
+ bin = mongocrypt_binary_new();
151
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
152
+ ctx = mongocrypt_ctx_new(crypt);
153
+
154
+ /* Encrypt an empty binary value. */
155
+ mongocrypt_ctx_setopt_key_alt_name(ctx, TEST_BSON("{'keyAltName': 'keyDocumentName'}"));
156
+ mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
157
+ mongocrypt_ctx_explicit_encrypt_init(ctx, TEST_BSON("{'v': { '$binary': { 'base64': '', 'subType': '00' } } }"));
158
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
159
+ mongocrypt_ctx_finalize(ctx, bin);
160
+ /* Copy the encrypted ciphertext since it is tied to the lifetime of ctx. */
161
+ _mongocrypt_buffer_copy_from_binary(&encrypted, bin);
162
+ mongocrypt_ctx_destroy(ctx);
163
+
164
+ /* Decrypt it back. */
165
+ ctx = mongocrypt_ctx_new(crypt);
166
+ mongocrypt_ctx_explicit_decrypt_init(ctx, _mongocrypt_buffer_as_binary(&encrypted));
167
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
168
+ mongocrypt_ctx_finalize(ctx, bin);
169
+
170
+ mongocrypt_binary_destroy(bin);
171
+ mongocrypt_ctx_destroy(ctx);
172
+ _mongocrypt_buffer_cleanup(&encrypted);
173
+ mongocrypt_destroy(crypt);
203
174
  }
204
175
 
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'}}")),
176
+ static void _test_decrypt_per_ctx_credentials(_mongocrypt_tester_t *tester) {
177
+ mongocrypt_t *crypt;
178
+ mongocrypt_ctx_t *ctx;
179
+ mongocrypt_binary_t *bin;
180
+ _mongocrypt_buffer_t encrypted;
181
+
182
+ bin = mongocrypt_binary_new();
183
+ crypt = mongocrypt_new();
184
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
185
+ mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'aws': {}}"));
186
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
187
+ ctx = mongocrypt_ctx_new(crypt);
188
+
189
+ /* Encrypt an empty binary value. */
190
+ mongocrypt_ctx_setopt_key_alt_name(ctx, TEST_BSON("{'keyAltName': 'keyDocumentName'}"));
191
+ mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
192
+ mongocrypt_ctx_explicit_encrypt_init(ctx, TEST_BSON("{'v': { '$binary': { 'base64': '', 'subType': '00' } } }"));
193
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
194
+ ASSERT_OK(mongocrypt_ctx_provide_kms_providers(ctx,
195
+ TEST_BSON("{'aws':{'accessKeyId': 'example',"
196
+ "'secretAccessKey': 'example'}}")),
234
197
  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);
198
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
199
+ mongocrypt_ctx_finalize(ctx, bin);
200
+ /* Copy the encrypted ciphertext since it is tied to the lifetime of ctx. */
201
+ _mongocrypt_buffer_copy_from_binary(&encrypted, bin);
202
+ mongocrypt_ctx_destroy(ctx);
203
+
204
+ /* Decrypt it back. */
205
+ ctx = mongocrypt_ctx_new(crypt);
206
+ mongocrypt_ctx_explicit_decrypt_init(ctx, _mongocrypt_buffer_as_binary(&encrypted));
207
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
208
+ mongocrypt_ctx_finalize(ctx, bin);
209
+
210
+ mongocrypt_binary_destroy(bin);
211
+ mongocrypt_ctx_destroy(ctx);
212
+ _mongocrypt_buffer_cleanup(&encrypted);
213
+ mongocrypt_destroy(crypt);
252
214
  }
253
215
 
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)),
216
+ static void _test_decrypt_per_ctx_credentials_local(_mongocrypt_tester_t *tester) {
217
+ mongocrypt_t *crypt;
218
+ mongocrypt_ctx_t *ctx;
219
+ mongocrypt_binary_t *bin;
220
+ _mongocrypt_buffer_t encrypted;
221
+ /* local_kek is the KEK used to encrypt the keyMaterial in
222
+ * ./test/data/key-document-local.json */
223
+ const char *local_kek = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
224
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
225
+ /* local_uuid is the hex of the UUID of the key in
226
+ * ./test/data/key-document-local.json */
227
+ const char *local_uuid = "61616161616161616161616161616161";
228
+ _mongocrypt_buffer_t local_uuid_buf;
229
+
230
+ bin = mongocrypt_binary_new();
231
+ crypt = mongocrypt_new();
232
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
233
+ mongocrypt_setopt_kms_providers(crypt, TEST_BSON("{'local': {}}"));
234
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
235
+ ctx = mongocrypt_ctx_new(crypt);
236
+
237
+ /* Encrypt an empty binary value. */
238
+ _mongocrypt_buffer_copy_from_hex(&local_uuid_buf, local_uuid);
239
+ mongocrypt_ctx_setopt_key_id(ctx, _mongocrypt_buffer_as_binary(&local_uuid_buf));
240
+ mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
241
+ mongocrypt_ctx_explicit_encrypt_init(ctx, TEST_BSON("{'v': { '$binary': { 'base64': '', 'subType': '00' } } }"));
242
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_KMS_CREDENTIALS);
243
+ ASSERT_OK(mongocrypt_ctx_provide_kms_providers(ctx,
244
+ TEST_BSON("{'local':{'key': { '$binary': {'base64': '%s', "
245
+ "'subType': '00'}}}}",
246
+ local_kek)),
294
247
  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);
248
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_NEED_MONGO_KEYS);
249
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx, TEST_FILE("./test/data/key-document-local.json")), ctx);
250
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
251
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
252
+ mongocrypt_ctx_finalize(ctx, bin);
253
+ /* Copy the encrypted ciphertext since it is tied to the lifetime of ctx. */
254
+ _mongocrypt_buffer_copy_from_binary(&encrypted, bin);
255
+ mongocrypt_ctx_destroy(ctx);
256
+
257
+ /* Decrypt it back. */
258
+ ctx = mongocrypt_ctx_new(crypt);
259
+ mongocrypt_ctx_explicit_decrypt_init(ctx, _mongocrypt_buffer_as_binary(&encrypted));
260
+ _mongocrypt_tester_run_ctx_to(tester, ctx, MONGOCRYPT_CTX_READY);
261
+ mongocrypt_ctx_finalize(ctx, bin);
262
+
263
+ _mongocrypt_buffer_cleanup(&local_uuid_buf);
264
+ mongocrypt_binary_destroy(bin);
265
+ mongocrypt_ctx_destroy(ctx);
266
+ _mongocrypt_buffer_cleanup(&encrypted);
267
+ mongocrypt_destroy(crypt);
318
268
  }
319
269
 
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': "
270
+ static void _test_decrypt_fle2(_mongocrypt_tester_t *tester) {
271
+ _mongocrypt_buffer_t S_KeyId;
272
+ _mongocrypt_buffer_t K_KeyId;
273
+
274
+ if (!_aes_ctr_is_supported_by_os) {
275
+ printf("Common Crypto with no CTR support detected. Skipping.");
276
+ return;
277
+ }
278
+
279
+ #define TEST_IEEV_BASE64 \
280
+ "BxI0VngSNJh2EjQSNFZ4kBICQ7uhTd9C2oI8M1afRon0ZaYG0s6oTmt0aBZ9kO4S4mm5vId01" \
281
+ "BsW7tBHytA8pDJ2IiWBCmah3OGH2M4ET7PSqekQD4gkUCo4JeEttx4yj05Ou4D6yZUmYfVKmE" \
282
+ "ljge16NCxKm7Ir9gvmQsp8x1wqGBzpndA6gkqFxsxfvQ/" \
283
+ "cIqOwMW9dGTTWsfKge+jYkCUIFMfms+XyC/8evQhjjA+qR6eEmV+N/" \
284
+ "kwpR7Q7TJe0lwU5kw2kSe3/KiPKRZZTbn8znadvycfJ0cCWGad9SQ=="
285
+
286
+ _mongocrypt_buffer_copy_from_hex(&S_KeyId, "12345678123498761234123456789012");
287
+ _mongocrypt_buffer_copy_from_hex(&K_KeyId, "ABCDEFAB123498761234123456789012");
288
+
289
+ /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
290
+ {
291
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
292
+ mongocrypt_ctx_t *ctx;
293
+ mongocrypt_binary_t *out;
294
+ bson_t out_bson;
295
+
296
+ ctx = mongocrypt_ctx_new(crypt);
297
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
298
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
299
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
300
+ ctx);
301
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
302
+ */
303
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
304
+ {
305
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
306
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
307
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/first-filter.json"), filter);
308
+ mongocrypt_binary_destroy(filter);
309
+ }
310
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
311
+ TEST_FILE("./test/data/keys/"
312
+ "12345678123498761234123456789012-local-"
313
+ "document.json")),
314
+ ctx);
315
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
316
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
317
+ */
318
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
319
+ {
320
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
321
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
322
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/second-filter.json"), filter);
323
+ mongocrypt_binary_destroy(filter);
324
+ }
325
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
326
+ TEST_FILE("./test/data/keys/"
327
+ "ABCDEFAB123498761234123456789012-local-"
328
+ "document.json")),
329
+ ctx);
330
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
331
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
332
+ out = mongocrypt_binary_new();
333
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
334
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
335
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123'}"));
336
+ mongocrypt_binary_destroy(out);
337
+ mongocrypt_ctx_destroy(ctx);
338
+ mongocrypt_destroy(crypt);
339
+ }
340
+
341
+ /* Test success with a non-local KMS provider. */
342
+ {
343
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
344
+ mongocrypt_ctx_t *ctx;
345
+ mongocrypt_binary_t *out;
346
+ bson_t out_bson;
347
+
348
+ ctx = mongocrypt_ctx_new(crypt);
349
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
350
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
351
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
352
+ ctx);
353
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
354
+ */
355
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
356
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
357
+ TEST_FILE("./test/data/keys/"
358
+ "12345678123498761234123456789012-aws-"
359
+ "document.json")),
360
+ ctx);
361
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
362
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
363
+ {
364
+ mongocrypt_kms_ctx_t *kms_ctx = mongocrypt_ctx_next_kms_ctx(ctx);
365
+ ASSERT(kms_ctx);
366
+ ASSERT_OK(mongocrypt_kms_ctx_feed(kms_ctx,
367
+ TEST_FILE("./test/data/keys/"
368
+ "12345678123498761234123456789012-"
369
+ "aws-decrypt-reply.txt")),
370
+ kms_ctx);
371
+ ASSERT(!mongocrypt_ctx_next_kms_ctx(ctx));
372
+ ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
373
+ }
374
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
375
+ */
376
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
377
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
378
+ TEST_FILE("./test/data/keys/"
379
+ "ABCDEFAB123498761234123456789012-aws-"
380
+ "document.json")),
381
+ ctx);
382
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
383
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_KMS);
384
+ {
385
+ mongocrypt_kms_ctx_t *kms_ctx = mongocrypt_ctx_next_kms_ctx(ctx);
386
+ ASSERT(kms_ctx);
387
+ ASSERT_OK(mongocrypt_kms_ctx_feed(kms_ctx,
388
+ TEST_FILE("./test/data/keys/"
389
+ "ABCDEFAB123498761234123456789012-"
390
+ "aws-decrypt-reply.txt")),
391
+ kms_ctx);
392
+ ASSERT(!mongocrypt_ctx_next_kms_ctx(ctx));
393
+ ASSERT_OK(mongocrypt_ctx_kms_done(ctx), ctx);
394
+ }
395
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
396
+ out = mongocrypt_binary_new();
397
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
398
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
399
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123'}"));
400
+ mongocrypt_binary_destroy(out);
401
+ mongocrypt_ctx_destroy(ctx);
402
+ mongocrypt_destroy(crypt);
403
+ }
404
+
405
+ /* Test success with two FLE2IndexedEqualityEncryptedValue payloads. */
406
+ {
407
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
408
+ mongocrypt_ctx_t *ctx;
409
+ mongocrypt_binary_t *out;
410
+ bson_t out_bson;
411
+
412
+ ctx = mongocrypt_ctx_new(crypt);
413
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
414
+ TEST_BSON("{'plainText':'sample','encrypted1':{'$binary':{'base64'"
415
+ ":'" TEST_IEEV_BASE64 "','subType':'6'}}, "
416
+ "'encrypted2':{'$binary':{'base64':'" TEST_IEEV_BASE64
417
+ "','subType':'6'}}}")),
418
+ ctx);
419
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
420
+ */
421
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
422
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
423
+ TEST_FILE("./test/data/keys/"
424
+ "12345678123498761234123456789012-local-"
425
+ "document.json")),
426
+ ctx);
427
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
428
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
429
+ */
430
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
431
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
432
+ TEST_FILE("./test/data/keys/"
433
+ "ABCDEFAB123498761234123456789012-local-"
434
+ "document.json")),
435
+ ctx);
436
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
437
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
438
+ out = mongocrypt_binary_new();
439
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
440
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
441
+ _assert_match_bson(&out_bson,
442
+ TMP_BSON("{'plainText': 'sample', 'encrypted1': "
528
443
  "'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);
444
+ mongocrypt_binary_destroy(out);
445
+ mongocrypt_ctx_destroy(ctx);
446
+ mongocrypt_destroy(crypt);
447
+ }
448
+
449
+ /* Test success when S_Key is cached, K_Key is not cached. */
450
+ {
451
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
452
+ mongocrypt_ctx_t *ctx;
453
+ mongocrypt_binary_t *out;
454
+ bson_t out_bson;
455
+
456
+ ctx = mongocrypt_ctx_new(crypt);
457
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
458
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
459
+ "' " TEST_IEEV_BASE64 "','subType':'6'}}}")),
460
+ ctx);
461
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
462
+ */
463
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
464
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
465
+ TEST_FILE("./test/data/keys/"
466
+ "12345678123498761234123456789012-local-"
467
+ "document.json")),
468
+ ctx);
469
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
470
+ mongocrypt_ctx_destroy(ctx);
471
+
472
+ /* Create a new context. S_Key is cached in crypt. */
473
+ ctx = mongocrypt_ctx_new(crypt);
474
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
475
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
476
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
477
+ ctx);
478
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
479
+ */
480
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
481
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
482
+ TEST_FILE("./test/data/keys/"
483
+ "ABCDEFAB123498761234123456789012-local-"
484
+ "document.json")),
485
+ ctx);
486
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
487
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
488
+ out = mongocrypt_binary_new();
489
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
490
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
491
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123' }"));
492
+ mongocrypt_binary_destroy(out);
493
+ mongocrypt_ctx_destroy(ctx);
494
+ mongocrypt_destroy(crypt);
495
+ }
496
+
497
+ /* Test success when S_Key is cached, K_Key is cached. */
498
+ {
499
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
500
+ mongocrypt_ctx_t *ctx;
501
+ mongocrypt_binary_t *out;
502
+ bson_t out_bson;
503
+
504
+ ctx = mongocrypt_ctx_new(crypt);
505
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
506
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
507
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
508
+ ctx);
509
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
510
+ */
511
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
512
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
513
+ TEST_FILE("./test/data/keys/"
514
+ "12345678123498761234123456789012-local-"
515
+ "document.json")),
516
+ ctx);
517
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
518
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
519
+ */
520
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
521
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
522
+ TEST_FILE("./test/data/keys/"
523
+ "ABCDEFAB123498761234123456789012-local-"
524
+ "document.json")),
525
+ ctx);
526
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
527
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
528
+ mongocrypt_ctx_destroy(ctx);
529
+
530
+ /* Create a new ctx. S_Key and K_Key are cached in crypt. */
531
+ ctx = mongocrypt_ctx_new(crypt);
532
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
533
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
534
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
535
+ ctx);
536
+ out = mongocrypt_binary_new();
537
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
538
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
539
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
540
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123'}"));
541
+ mongocrypt_binary_destroy(out);
542
+ mongocrypt_ctx_destroy(ctx);
543
+ mongocrypt_destroy(crypt);
544
+ }
545
+
546
+ /* Test error when S_Key is not provided. */
547
+ {
548
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
549
+ mongocrypt_ctx_t *ctx;
550
+
551
+ ctx = mongocrypt_ctx_new(crypt);
552
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
553
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
554
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
555
+ ctx);
556
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
557
+ */
558
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
559
+ ASSERT_FAILS(mongocrypt_ctx_mongo_done(ctx), ctx, "not all keys requested were satisfied");
560
+ mongocrypt_ctx_destroy(ctx);
561
+ mongocrypt_destroy(crypt);
562
+ }
563
+
564
+ /* Test error when K_Key is not provided. */
565
+ {
566
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
567
+ mongocrypt_ctx_t *ctx;
568
+
569
+ ctx = mongocrypt_ctx_new(crypt);
570
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
571
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
572
+ "'" TEST_IEEV_BASE64 "','subType':'6'}}}")),
573
+ ctx);
574
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
575
+ */
576
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
577
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
578
+ TEST_FILE("./test/data/keys/"
579
+ "12345678123498761234123456789012-local-"
580
+ "document.json")),
581
+ ctx);
582
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
583
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
584
+ */
585
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
586
+ ASSERT_FAILS(mongocrypt_ctx_mongo_done(ctx), ctx, "not all keys requested were satisfied");
587
+ mongocrypt_ctx_destroy(ctx);
588
+ mongocrypt_destroy(crypt);
589
+ }
590
+
591
+ _mongocrypt_buffer_cleanup(&K_KeyId);
592
+ _mongocrypt_buffer_cleanup(&S_KeyId);
714
593
 
715
594
  #undef TEST_IEEV_BASE64
716
595
  }
717
596
 
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);
597
+ static void _test_explicit_decrypt_fle2_ieev(_mongocrypt_tester_t *tester) {
598
+ _mongocrypt_buffer_t S_KeyId;
599
+ _mongocrypt_buffer_t K_KeyId;
600
+
601
+ if (!_aes_ctr_is_supported_by_os) {
602
+ printf("Common Crypto with no CTR support detected. Skipping.");
603
+ return;
604
+ }
605
+
606
+ #define TEST_IEEV_BASE64 \
607
+ "BxI0VngSNJh2EjQSNFZ4kBICQ7uhTd9C2oI8M1afRon0ZaYG0s6oTmt0aBZ9kO4S4mm5vId01" \
608
+ "BsW7tBHytA8pDJ2IiWBCmah3OGH2M4ET7PSqekQD4gkUCo4JeEttx4yj05Ou4D6yZUmYfVKmE" \
609
+ "ljge16NCxKm7Ir9gvmQsp8x1wqGBzpndA6gkqFxsxfvQ/" \
610
+ "cIqOwMW9dGTTWsfKge+jYkCUIFMfms+XyC/8evQhjjA+qR6eEmV+N/" \
611
+ "kwpR7Q7TJe0lwU5kw2kSe3/KiPKRZZTbn8znadvycfJ0cCWGad9SQ=="
612
+
613
+ _mongocrypt_buffer_copy_from_hex(&S_KeyId, "12345678123498761234123456789012");
614
+ _mongocrypt_buffer_copy_from_hex(&K_KeyId, "ABCDEFAB123498761234123456789012");
615
+
616
+ /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
617
+ {
618
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
619
+ mongocrypt_ctx_t *ctx;
620
+ mongocrypt_binary_t *out;
621
+ bson_t out_bson;
622
+
623
+ ctx = mongocrypt_ctx_new(crypt);
624
+ ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(
625
+ ctx,
626
+ TEST_BSON("{'v':{'$binary':{'base64': '" TEST_IEEV_BASE64 "','subType':'6'}}}")),
627
+ ctx);
628
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
629
+ */
630
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
631
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
632
+ TEST_FILE("./test/data/keys/"
633
+ "12345678123498761234123456789012-local-"
634
+ "document.json")),
635
+ ctx);
636
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
637
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
638
+ */
639
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
640
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
641
+ TEST_FILE("./test/data/keys/"
642
+ "ABCDEFAB123498761234123456789012-local-"
643
+ "document.json")),
644
+ ctx);
645
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
646
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
647
+ out = mongocrypt_binary_new();
648
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
649
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
650
+ _assert_match_bson(&out_bson, TMP_BSON("{'v': 'value123'}"));
651
+ mongocrypt_binary_destroy(out);
652
+ mongocrypt_ctx_destroy(ctx);
653
+ mongocrypt_destroy(crypt);
654
+ }
655
+ _mongocrypt_buffer_cleanup(&K_KeyId);
656
+ _mongocrypt_buffer_cleanup(&S_KeyId);
788
657
 
789
658
  #undef TEST_IEEV_BASE64
790
659
  }
791
660
 
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
- }
661
+ #define TEST_IUP_BASE64 \
662
+ "BHEBAAAFZAAgAAAAAHb62aV7+mqmaGcotPLdG3KP7S8diFwWMLM/" \
663
+ "5rYtqLrEBXMAIAAAAAAVJ6OWHRv3OtCozHpt3ZzfBhaxZirLv3B+" \
664
+ "G8PuaaO4EgVjACAAAAAAsZXWOWA+UiCBbrJNB6bHflB/" \
665
+ "cn7pWSvwWN2jw4FPeIUFcABQAAAAAMdD1nV2nqeI1eXEQNskDflCy8I7/" \
666
+ "HvvqDKJ6XxjhrPQWdLqjz+8GosGUsB7A8ee/uG9/" \
667
+ "guENuL25XD+" \
668
+ "Fxxkv1LLXtavHOlLF7iW0u9yabqqBXUAEAAAAAQSNFZ4EjSYdhI0EjRWeJASEHQAAgAAAAV2A" \
669
+ "E0AAAAAq83vqxI0mHYSNBI0VniQEkzZZBBDgeZh+h+gXEmOrSFtVvkUcnHWj/" \
670
+ "rfPW7iJ0G3UJ8zpuBmUM/VjOMJCY4+eDqdTiPIwX+/vNXegc8FZQAgAAAAAOuac/" \
671
+ "eRLYakKX6B0vZ1r3QodOQFfjqJD+xlGiPu4/PsAA=="
672
+
673
+ static void _test_decrypt_fle2_iup(_mongocrypt_tester_t *tester) {
674
+ if (!_aes_ctr_is_supported_by_os) {
675
+ printf("Common Crypto with no CTR support detected. Skipping.");
676
+ return;
677
+ }
678
+
679
+ /* Test success with an FLE2InsertUpdatePayload. */
680
+ {
681
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
682
+ mongocrypt_ctx_t *ctx;
683
+ mongocrypt_binary_t *out;
684
+ bson_t out_bson;
685
+
686
+ ctx = mongocrypt_ctx_new(crypt);
687
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
688
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
689
+ "'" TEST_IUP_BASE64 "','subType':'6'}}}")),
690
+ ctx);
691
+
692
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
693
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
694
+ TEST_FILE("./test/data/keys/"
695
+ "ABCDEFAB123498761234123456789012-local-document.json")),
696
+ ctx);
697
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
698
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
699
+ out = mongocrypt_binary_new();
700
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
701
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
702
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 'value123'}"));
703
+ mongocrypt_binary_destroy(out);
704
+ mongocrypt_ctx_destroy(ctx);
705
+ mongocrypt_destroy(crypt);
706
+ }
848
707
  }
708
+
849
709
  #undef TEST_IUP_BASE64
850
710
 
851
711
  /* 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);
712
+ static void _test_decrypt_wrong_binary_subtype(_mongocrypt_tester_t *tester) {
713
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
714
+ mongocrypt_ctx_t *ctx = mongocrypt_ctx_new(crypt);
715
+ /* Use subtype 0. */
716
+ ASSERT_FAILS(
717
+ mongocrypt_ctx_explicit_decrypt_init(ctx,
718
+ TEST_BSON("{'v': { '$binary': { 'base64': 'AAAA', 'subType': '00' }}}")),
719
+ ctx,
720
+ "decryption expected BSON binary subtype 6, got 0");
721
+ mongocrypt_ctx_destroy(ctx);
722
+ mongocrypt_destroy(crypt);
868
723
  }
869
724
 
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="
725
+ #define TEST_IREV_BASE64 \
726
+ "CRI0VngSNJh2EjQSNFZ4kBIQsPF0Ii0Hfv7ZMhnNt/yt+mviydF8EUw0YlO+amC3IF8dX2J/" \
727
+ "GmRZRnihW3VqJYoLMk0BIit0x9YQiQEEQPxPcTXnCx4t1fquOY7cRGqIAWTDHuQ9AdUw94EY1" \
728
+ "J55mq9UhwD7flh0ySR/SbkTwjIU32U1iM6Bv4AriE4smI87Yd0V7Z7kDoDx7afx9vM/" \
729
+ "+h9NWZvpfYcZ+P32sfILb3BdXT5zLrkyc5Xb3myDxE9abTrR8ePG0YuEmeqwGE4bZ6QHKzd/" \
730
+ "RLmHciWstKOtER5uRpo3p570wGO8QE9QtQoJp/7N7Su30dK/" \
731
+ "bk59hVvlNO6i3nUPwqMd13DePobNGn84q3Fag5O4Kw8P4EGfomFWzxydlVQ0SppGVfan9tIj1" \
732
+ "CFu5doYYT4adzX7L9HinKsTWE5ctD9Qxhhzb2cVs5JO96j4mpwOaloF/" \
733
+ "4qJhyqlzTEpoCXGQ0X9aeEplibFxQ7FJkaFfYzIDIxA2d6lzwVel3j+VwQ7zOP/" \
734
+ "bCnaFu6EP1OQw3ZarsaWGENf45DFuK5RsKX198vZTlqtH24YhAL1+noQTMtpTOp/" \
735
+ "6vrczOXkr7dJGQ6RAfliq1maD18PN5yjdyNhr7BXsrK6f01DX2Xr4s51AARxQ/" \
736
+ "0U5hmb4HjKg8Sbno4Th+Wza3I0RMgM0YzhRUJz+BXzx2l9NPdeyuECdQ1Q2wP1MNOCBy/" \
737
+ "QBJmc+" \
738
+ "RWYK57oWCuv5vmkpN8IlriyRv0PGRhYr4ZcLkDdzmuyfK6SGAvIPD4veDJRj3cXEazyMh6g+" \
739
+ "rvwt70laxo2IOhvUXDc89WvarthTOzlFt5FNrA8uXhUYyL1q1XSWYCiCu5vRv77BvRUJjf2B6" \
740
+ "5kaIKUAGDhYuhch2yU6O9VsHLik3xOGSwIUZJbdMyHY+eA8ZlWZeKJbpjz7a/" \
741
+ "TyBQU6VNG4+Z5SXJjURogkODNkx21QS0Z1+b7ZnCSXf1OQceomkDrREB7vyD2HX5rN2/" \
742
+ "KIBMgH3J7DnG2VpNhYJ9Ve1hMDGcrQggjkCpdP7lloc6QiH837tD/81gYmr95IbuIHe/" \
743
+ "x20oHh9heGHUELnCQ6hXYWOBvSFlGcqZs/" \
744
+ "f0qxn5Fe2OfQPRzEstxoW99IdPvgotDnL2vaz2JNFvFqiofc2pIP7XvpFKIoQO7q8LX9z7ah1" \
745
+ "Yh8cbi6us8g5y9WzOfh882jU7vQT+31a1ZaeDMbFV1Cemc+/" \
746
+ "d0HNksi1qMJtcjrH2MQgXJ3BTyAuJH9OFK8iGqSzHhop9hp5z8mvx834PPjgBfZGt4w/" \
747
+ "7qeie+T4sooGVVqA6F3jl8YfFdIUAwkxe5GBQVVvaRLYm/" \
748
+ "4SLGBf54Dexi7e0+rL2sG5DeKygNdFzMc6lRO+" \
749
+ "gvmAMmDucRm4bxmu7ycNZCQUcuSKoMUWWu6A6eUiyBCQUxrrlX/" \
750
+ "3CkRXkQQ6JCwZZMvTgBokYx3WQR6LpW70xWLXyQhav4ZnHKzgITSOe7mUkMJ35NDMD+" \
751
+ "qsxXY7sWbGz+b60DWF7yaMVzDPzIGjWLpckMRMxgN3bQ5SE/mFxdjoZD5yYb84q/" \
752
+ "O7EjwGA9MSTp9MFEZt7VV3f5TDWiNUZKmjUgOdjBoTSAkVzAO2nqqQNg23x6Z6FQDBeefRkfc" \
753
+ "9FoUiBqHuN4fU/zc4Hkthp1McwIkYwRdlgPceD/" \
754
+ "BSNbkNRNAnzghBhCquIqpXd8AptBX2qO67rfT7COhpn/" \
755
+ "fzVo3ueCRTaM2DtjD3uuH4rMNb3LDjyJFX1DZ5eEWkGq9UE/" \
756
+ "AFivfeia4cA0a8Z1LzZcW7WvE5Y1WIZN4gy9SZcNgHEQq8Ad8Q4fAbxe8XJ6/" \
757
+ "tNvG+AvAuLEvNJtbhC/4Ei/" \
758
+ "JoXplvutDlW5d6g4KEWj4GICqggM5ZSv0TCkbfFkLdaJrOHrn+oI++" \
759
+ "krv1U4yQk6P18Mg2bE18ibe+LdWNsqn01V7yDmS+" \
760
+ "VAvqQF8f2p4rOOyWsGc7CoyXSrq9LCuGq9eMPR6auo+" \
761
+ "tyS1Nek2t6SgpOpzBBDdQnC5sHC1OWTW3ui7w4H0NKCuZOiMncbSDOlegn8C0zZa6Z5iYAce8" \
762
+ "a8Ow3jryBEnKBaguhjjOMG8iX/eka8XP+UTxvso4fKVVOXQwobZMdYbf/" \
763
+ "sXNJbMbWrFc1S9rdlXL/" \
764
+ "nnYvYrRMnOBJ27Mz5vvtOpd4fyQ+wi1q+" \
765
+ "5VvuLDM8u51B4oaYqpGUZZ3qVS5BBYm9cDxgMtcdoXjOSopHasdAhron+" \
766
+ "NdbGFBxyrUGKnnVXYocEuvsvwhBEA3HUUVV94m3C0agh2eVpmCIyWrs+" \
767
+ "grkpAaNLZwXVuzegttJ0GoTxzQnDIWkvlvkS3ZGo25spfPp+/Nda4SZAYRNmtnGfB2TRl0Wx/" \
768
+ "o/" \
769
+ "V2vx+9qnGyDq52CSkMftpfnsMXAnAv6ps7U+" \
770
+ "mgbgNPUFjv1Y0xKaeJdshu1HyEmq5aYqHJSfF2EzvPfH4d0Ijz1lsxMxL4IsqB7kufcOR4FFn" \
771
+ "aYXKIXLjRwM5VZNAK/3dvCb3l9H7QMOiJPbdoxAd123aymjz9N/" \
772
+ "2O33wMaG6OE8pXp0iYEaW7DOr0FfT913JeUnPNPcqqsA9YXod2UuNWZElTW/" \
773
+ "saL32v9akNwA4Jd7Y5VgI4y+XyDH3kAU0Uc8g6YCx/hqcn4pd2+ryH+/" \
774
+ "5nVQhnCE0KNOjjrFS92RNLD71GUhWR+VXMw2tKXBUSKnt9Ai4LLJrdvFbwrdqK+" \
775
+ "AjBUVqI3MgylNxRw2395ppAbheE1pAcoqLoDOGyOs66Y8kJGpaqs0AmdmZHw2OA26btw+" \
776
+ "ceBN+UgScsB5P5wNIup1AvU5J7h1vlFBNygg3WO/MJGCz48xgJ/" \
777
+ "klg9wCLQ+vXtrhYJz15RgguADFLBrTcV/Miel20KulnprI+/" \
778
+ "lXtRvEAoGJSc0UZ8J7UVTf8kvYzT3hF7XzZzlhKxPYebjdnp2la4o2PkyZXcc/" \
779
+ "gFLa7ickR28ZPUigwpW0lK5sJIwWbnZmP5wbQNhiGO8QL9gVpFOnu0xHpu8MqBvfZGf2HiE+" \
780
+ "qBUSR89v88gz6u/TVP9zVH1dnk9PE54Uw3yPdxL/" \
781
+ "feukvF71sEI6WWd2fdupgRlDGzASrKSAsFbaZobwUViEIFbWo7zPYVZyMglCrD1Xoxdd6EBeU" \
782
+ "SJDkS1nhiHOR/7FpIhae8fggAD+StXR7725vzcwIOX21ozRcE2iWw6OP99vDoqLQ8VYzYS0/" \
783
+ "f3WMME6b5ndYz25uC0AiULXYI="
929
784
 
930
785
  /* 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
- }
786
+ static void _test_decrypt_fle2_irev(_mongocrypt_tester_t *tester) {
787
+ if (!_aes_ctr_is_supported_by_os) {
788
+ printf("Common Crypto with no CTR support detected. Skipping.");
789
+ return;
790
+ }
791
+
792
+ /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
793
+ {
794
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
795
+ mongocrypt_ctx_t *ctx;
796
+ mongocrypt_binary_t *out;
797
+ bson_t out_bson;
798
+
799
+ ctx = mongocrypt_ctx_new(crypt);
800
+ ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx,
801
+ TEST_BSON("{'plainText':'sample','encrypted':{'$binary':{'base64':"
802
+ "'" TEST_IREV_BASE64 "','subType':'6'}}}")),
803
+ ctx);
804
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
805
+ */
806
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
807
+ {
808
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
809
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
810
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/first-filter.json"), filter);
811
+ mongocrypt_binary_destroy(filter);
812
+ }
813
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
814
+ TEST_FILE("./test/data/keys/"
815
+ "12345678123498761234123456789012-local-"
816
+ "document.json")),
817
+ ctx);
818
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
819
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
820
+ */
821
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
822
+ {
823
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
824
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
825
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/second-filter.json"), filter);
826
+ mongocrypt_binary_destroy(filter);
827
+ }
828
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
829
+ TEST_FILE("./test/data/keys/"
830
+ "ABCDEFAB123498761234123456789012-local-"
831
+ "document.json")),
832
+ ctx);
833
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
834
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
835
+ out = mongocrypt_binary_new();
836
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
837
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
838
+ _assert_match_bson(&out_bson, TMP_BSON("{'plainText': 'sample', 'encrypted': 123456}"));
839
+ mongocrypt_binary_destroy(out);
840
+ mongocrypt_ctx_destroy(ctx);
841
+ mongocrypt_destroy(crypt);
842
+ }
1002
843
  }
1003
844
 
1004
845
  // 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'}}}")),
846
+ static void _test_explicit_decrypt_fle2_irev(_mongocrypt_tester_t *tester) {
847
+ if (!_aes_ctr_is_supported_by_os) {
848
+ printf("Common Crypto with no CTR support detected. Skipping.");
849
+ return;
850
+ }
851
+
852
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
853
+ mongocrypt_ctx_t *ctx;
854
+ mongocrypt_binary_t *out;
855
+ bson_t out_bson;
856
+
857
+ ctx = mongocrypt_ctx_new(crypt);
858
+ ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(
859
+ ctx,
860
+ TEST_BSON("{'v': {'$binary':{'base64':'" TEST_IREV_BASE64 "','subType':'6'}}}")),
1024
861
  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")),
862
+ /* The first transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests S_Key.
863
+ */
864
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
865
+ {
866
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
867
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
868
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/first-filter.json"), filter);
869
+ mongocrypt_binary_destroy(filter);
870
+ }
871
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
872
+ TEST_FILE("./test/data/keys/"
873
+ "12345678123498761234123456789012-local-"
874
+ "document.json")),
1041
875
  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")),
876
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
877
+ /* The second transition to MONGOCRYPT_CTX_NEED_MONGO_KEYS requests K_Key.
878
+ */
879
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
880
+ {
881
+ mongocrypt_binary_t *filter = mongocrypt_binary_new();
882
+ ASSERT_OK(mongocrypt_ctx_mongo_op(ctx, filter), ctx);
883
+ ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(TEST_FILE("./test/data/fle2-decrypt-ieev/second-filter.json"), filter);
884
+ mongocrypt_binary_destroy(filter);
885
+ }
886
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
887
+ TEST_FILE("./test/data/keys/"
888
+ "ABCDEFAB123498761234123456789012-local-"
889
+ "document.json")),
1060
890
  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);
891
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
892
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
893
+ out = mongocrypt_binary_new();
894
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
895
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
896
+ _assert_match_bson(&out_bson, TMP_BSON("{'v': 123456}"));
897
+ mongocrypt_binary_destroy(out);
898
+ mongocrypt_ctx_destroy(ctx);
899
+ mongocrypt_destroy(crypt);
1070
900
  }
1071
901
 
1072
902
  #undef TEST_IREV_BASE64
1073
903
 
1074
904
  // 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")),
905
+ static void _test_explicit_decrypt_fle2_iup_with_edges(_mongocrypt_tester_t *tester) {
906
+ if (!_aes_ctr_is_supported_by_os) {
907
+ printf("Common Crypto with no CTR support detected. Skipping.");
908
+ return;
909
+ }
910
+
911
+ /* Test success with an FLE2IndexedEqualityEncryptedValue payload. */
912
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
913
+ mongocrypt_ctx_t *ctx;
914
+ mongocrypt_binary_t *out;
915
+ bson_t out_bson;
916
+
917
+ ctx = mongocrypt_ctx_new(crypt);
918
+ ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(ctx,
919
+ TEST_FILE("./test/data/fle2-insert-range-explicit/int32/"
920
+ "encrypted-payload.json")),
1095
921
  ctx);
1096
922
 
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")),
923
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_NEED_MONGO_KEYS);
924
+ ASSERT_OK(mongocrypt_ctx_mongo_feed(ctx,
925
+ TEST_FILE("./test/data/keys/"
926
+ "ABCDEFAB123498761234123456789012-local-"
927
+ "document.json")),
1104
928
  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);
929
+ ASSERT_OK(mongocrypt_ctx_mongo_done(ctx), ctx);
930
+ ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_READY);
931
+ out = mongocrypt_binary_new();
932
+ ASSERT_OK(mongocrypt_ctx_finalize(ctx, out), ctx);
933
+ ASSERT(_mongocrypt_binary_to_bson(out, &out_bson));
934
+ _assert_match_bson(&out_bson, TMP_BSON("{'v': 123456}"));
935
+ mongocrypt_binary_destroy(out);
936
+ mongocrypt_ctx_destroy(ctx);
937
+ mongocrypt_destroy(crypt);
1114
938
  }
1115
939
 
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);
940
+ void _mongocrypt_tester_install_ctx_decrypt(_mongocrypt_tester_t *tester) {
941
+ INSTALL_TEST(_test_explicit_decrypt_init);
942
+ INSTALL_TEST(_test_decrypt_init);
943
+ INSTALL_TEST(_test_decrypt_need_keys);
944
+ INSTALL_TEST(_test_decrypt_ready);
945
+ INSTALL_TEST(_test_decrypt_empty_aws);
946
+ INSTALL_TEST(_test_decrypt_empty_binary);
947
+ INSTALL_TEST(_test_decrypt_per_ctx_credentials);
948
+ INSTALL_TEST(_test_decrypt_per_ctx_credentials_local);
949
+ INSTALL_TEST(_test_decrypt_fle2);
950
+ INSTALL_TEST(_test_explicit_decrypt_fle2_ieev);
951
+ INSTALL_TEST(_test_decrypt_fle2_iup);
952
+ INSTALL_TEST(_test_decrypt_wrong_binary_subtype);
953
+ INSTALL_TEST(_test_decrypt_fle2_irev);
954
+ INSTALL_TEST(_test_explicit_decrypt_fle2_irev);
955
+ INSTALL_TEST(_test_explicit_decrypt_fle2_iup_with_edges);
1134
956
  }