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
@@ -18,1284 +18,1097 @@
18
18
 
19
19
  #include <stdarg.h>
20
20
 
21
- #include "test-mongocrypt.h"
22
21
  #include "mongocrypt-binary-private.h"
22
+ #include "test-mongocrypt.h"
23
23
 
24
24
  /* An orphaned UTF-8 continuation byte (10xxxxxx) is malformed UTF-8. */
25
- static char invalid_utf8[] = {(char) 0x80, (char) 0x00};
25
+ static char invalid_utf8[] = {(char)0x80, (char)0x00};
26
26
 
27
27
  /* Convenience macros for setting options */
28
- #define ASSERT_MASTERKEY_AWS_OK(region, region_len, cmk, cmk_len) \
29
- ASSERT_OK (mongocrypt_ctx_setopt_masterkey_aws ( \
30
- ctx, region, region_len, cmk, cmk_len), \
31
- ctx);
32
- #define ASSERT_MASTERKEY_AWS_FAILS(region, region_len, cmk, cmk_len, msg) \
33
- ASSERT_FAILS (mongocrypt_ctx_setopt_masterkey_aws ( \
34
- ctx, region, region_len, cmk, cmk_len), \
35
- ctx, \
36
- msg);
37
-
38
- #define ASSERT_MASTERKEY_LOCAL_OK \
39
- ASSERT_OK (mongocrypt_ctx_setopt_masterkey_local (ctx), ctx);
40
- #define ASSERT_MASTERKEY_LOCAL_FAILS(msg) \
41
- ASSERT_FAILS (mongocrypt_ctx_setopt_masterkey_local (ctx), ctx, msg);
42
-
43
- #define ASSERT_KEY_ENCRYPTION_KEY_OK(bin) \
44
- ASSERT_OK (mongocrypt_ctx_setopt_key_encryption_key (ctx, bin), ctx);
45
- #define ASSERT_KEY_ENCRYPTION_KEY_FAILS(bin, msg) \
46
- ASSERT_FAILS (mongocrypt_ctx_setopt_key_encryption_key (ctx, bin), ctx, msg);
47
-
48
- #define ASSERT_KEY_ID_OK(key_id) \
49
- ASSERT_OK (mongocrypt_ctx_setopt_key_id (ctx, key_id), ctx);
50
- #define ASSERT_KEY_ID_FAILS(key_id, msg) \
51
- ASSERT_FAILS (mongocrypt_ctx_setopt_key_id (ctx, key_id), ctx, msg);
52
-
53
- #define ASSERT_KEY_ALT_NAME_OK(key_alt_name) \
54
- ASSERT_OK (mongocrypt_ctx_setopt_key_alt_name (ctx, key_alt_name), ctx);
55
- #define ASSERT_KEY_ALT_NAME_FAILS(key_alt_name, msg) \
56
- ASSERT_FAILS ( \
57
- mongocrypt_ctx_setopt_key_alt_name (ctx, key_alt_name), ctx, msg);
58
-
59
- #define ASSERT_KEY_MATERIAL_OK(key_material) \
60
- ASSERT_OK (mongocrypt_ctx_setopt_key_material (ctx, key_material), ctx);
61
- #define ASSERT_KEY_MATERIAL_FAILS(key_material, msg) \
62
- ASSERT_FAILS ( \
63
- mongocrypt_ctx_setopt_key_material (ctx, key_material), ctx, msg);
64
-
65
- #define ASSERT_ALGORITHM_OK(algo, algo_len) \
66
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (ctx, algo, algo_len), ctx);
67
- #define ASSERT_ALGORITHM_FAILS(algo, algo_len, msg) \
68
- ASSERT_FAILS ( \
69
- mongocrypt_ctx_setopt_algorithm (ctx, algo, algo_len), ctx, msg);
70
-
71
- #define ASSERT_QUERY_TYPE_OK(qt, qt_len) \
72
- ASSERT_OK (mongocrypt_ctx_setopt_query_type (ctx, qt, qt_len), ctx);
73
- #define ASSERT_QUERY_TYPE_FAILS(qt, qt_len, msg) \
74
- ASSERT_FAILS (mongocrypt_ctx_setopt_query_type (ctx, qt, qt_len), ctx, msg);
75
-
76
- #define ASSERT_ENDPOINT_OK(endpoint, endpoint_len) \
77
- ASSERT_OK (mongocrypt_ctx_setopt_masterkey_aws_endpoint ( \
78
- ctx, endpoint, endpoint_len), \
79
- ctx);
80
- #define ASSERT_ENDPOINT_FAILS(endpoint, endpoint_len, msg) \
81
- ASSERT_FAILS (mongocrypt_ctx_setopt_masterkey_aws_endpoint ( \
82
- ctx, endpoint, endpoint_len), \
83
- ctx, \
84
- msg);
85
-
86
- #define ASSERT_DATAKEY_INIT_OK \
87
- ASSERT_OK (mongocrypt_ctx_datakey_init (ctx), ctx);
88
- #define ASSERT_DATAKEY_INIT_FAILS(msg) \
89
- ASSERT_FAILS (mongocrypt_ctx_datakey_init (ctx), ctx, msg);
90
-
91
- #define ASSERT_ENCRYPT_INIT_OK(db, db_len, cmd) \
92
- ASSERT_OK (mongocrypt_ctx_encrypt_init (ctx, db, db_len, cmd), ctx);
93
- #define ENCRYPT_INIT_FAILS(db, db_len, cmd, msg) \
94
- ASSERT_FAILS (mongocrypt_ctx_encrypt_init (ctx, db, db_len, cmd), ctx, msg);
95
-
96
- #define ASSERT_EX_ENCRYPT_INIT_OK(bin) \
97
- ASSERT_OK (mongocrypt_ctx_explicit_encrypt_init (ctx, bin), ctx);
98
- #define ASSERT_EX_ENCRYPT_INIT_FAILS(bin, msg) \
99
- ASSERT_FAILS (mongocrypt_ctx_explicit_encrypt_init (ctx, bin), ctx, msg);
100
-
101
- #define ASSERT_EX_ENCRYPT_EXPRESSION_INIT_OK(bin) \
102
- ASSERT_OK (mongocrypt_ctx_explicit_encrypt_expression_init (ctx, bin), ctx);
103
- #define ASSERT_EX_ENCRYPT_EXPRESSION_INIT_FAILS(bin, msg) \
104
- ASSERT_FAILS ( \
105
- mongocrypt_ctx_explicit_encrypt_expression_init (ctx, bin), ctx, msg);
106
-
107
- #define ASSERT_DECRYPT_INIT_OK(bin) \
108
- ASSERT_OK (mongocrypt_ctx_decrypt_init (ctx, bin), ctx);
109
- #define ASSERT_DECRYPT_INIT_FAILS(bin, msg) \
110
- ASSERT_FAILS (mongocrypt_ctx_decrypt_init (ctx, bin), ctx, msg);
111
-
112
- #define ASSERT_EX_DECRYPT_INIT_OK(bin) \
113
- ASSERT_OK (mongocrypt_ctx_explicit_decrypt_init (ctx, bin), ctx);
114
- #define ASSERT_EX_DECRYPT_INIT_FAILS(bin, msg) \
115
- ASSERT_FAILS (mongocrypt_ctx_explicit_decrypt_init (ctx, bin), ctx, msg);
116
-
117
- #define REFRESH \
118
- do { \
119
- mongocrypt_ctx_destroy (ctx); \
120
- ctx = mongocrypt_ctx_new (crypt); \
121
- } while (0)
28
+ #define ASSERT_MASTERKEY_AWS_OK(region, region_len, cmk, cmk_len) \
29
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws(ctx, region, region_len, cmk, cmk_len), ctx);
30
+ #define ASSERT_MASTERKEY_AWS_FAILS(region, region_len, cmk, cmk_len, msg) \
31
+ ASSERT_FAILS(mongocrypt_ctx_setopt_masterkey_aws(ctx, region, region_len, cmk, cmk_len), ctx, msg);
32
+
33
+ #define ASSERT_MASTERKEY_LOCAL_OK ASSERT_OK(mongocrypt_ctx_setopt_masterkey_local(ctx), ctx);
34
+ #define ASSERT_MASTERKEY_LOCAL_FAILS(msg) ASSERT_FAILS(mongocrypt_ctx_setopt_masterkey_local(ctx), ctx, msg);
35
+
36
+ #define ASSERT_KEY_ENCRYPTION_KEY_OK(bin) ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx, bin), ctx);
37
+ #define ASSERT_KEY_ENCRYPTION_KEY_FAILS(bin, msg) \
38
+ ASSERT_FAILS(mongocrypt_ctx_setopt_key_encryption_key(ctx, bin), ctx, msg);
39
+
40
+ #define ASSERT_KEY_ID_OK(key_id) ASSERT_OK(mongocrypt_ctx_setopt_key_id(ctx, key_id), ctx);
41
+ #define ASSERT_KEY_ID_FAILS(key_id, msg) ASSERT_FAILS(mongocrypt_ctx_setopt_key_id(ctx, key_id), ctx, msg);
42
+
43
+ #define ASSERT_KEY_ALT_NAME_OK(key_alt_name) ASSERT_OK(mongocrypt_ctx_setopt_key_alt_name(ctx, key_alt_name), ctx);
44
+ #define ASSERT_KEY_ALT_NAME_FAILS(key_alt_name, msg) \
45
+ ASSERT_FAILS(mongocrypt_ctx_setopt_key_alt_name(ctx, key_alt_name), ctx, msg);
46
+
47
+ #define ASSERT_KEY_MATERIAL_OK(key_material) ASSERT_OK(mongocrypt_ctx_setopt_key_material(ctx, key_material), ctx);
48
+ #define ASSERT_KEY_MATERIAL_FAILS(key_material, msg) \
49
+ ASSERT_FAILS(mongocrypt_ctx_setopt_key_material(ctx, key_material), ctx, msg);
50
+
51
+ #define ASSERT_ALGORITHM_OK(algo, algo_len) ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, algo, algo_len), ctx);
52
+ #define ASSERT_ALGORITHM_FAILS(algo, algo_len, msg) \
53
+ ASSERT_FAILS(mongocrypt_ctx_setopt_algorithm(ctx, algo, algo_len), ctx, msg);
54
+
55
+ #define ASSERT_QUERY_TYPE_OK(qt, qt_len) ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, qt, qt_len), ctx);
56
+ #define ASSERT_QUERY_TYPE_FAILS(qt, qt_len, msg) \
57
+ ASSERT_FAILS(mongocrypt_ctx_setopt_query_type(ctx, qt, qt_len), ctx, msg);
58
+
59
+ #define ASSERT_ENDPOINT_OK(endpoint, endpoint_len) \
60
+ ASSERT_OK(mongocrypt_ctx_setopt_masterkey_aws_endpoint(ctx, endpoint, endpoint_len), ctx);
61
+ #define ASSERT_ENDPOINT_FAILS(endpoint, endpoint_len, msg) \
62
+ ASSERT_FAILS(mongocrypt_ctx_setopt_masterkey_aws_endpoint(ctx, endpoint, endpoint_len), ctx, msg);
63
+
64
+ #define ASSERT_DATAKEY_INIT_OK ASSERT_OK(mongocrypt_ctx_datakey_init(ctx), ctx);
65
+ #define ASSERT_DATAKEY_INIT_FAILS(msg) ASSERT_FAILS(mongocrypt_ctx_datakey_init(ctx), ctx, msg);
66
+
67
+ #define ASSERT_ENCRYPT_INIT_OK(db, db_len, cmd) ASSERT_OK(mongocrypt_ctx_encrypt_init(ctx, db, db_len, cmd), ctx);
68
+ #define ENCRYPT_INIT_FAILS(db, db_len, cmd, msg) \
69
+ ASSERT_FAILS(mongocrypt_ctx_encrypt_init(ctx, db, db_len, cmd), ctx, msg);
70
+
71
+ #define ASSERT_EX_ENCRYPT_INIT_OK(bin) ASSERT_OK(mongocrypt_ctx_explicit_encrypt_init(ctx, bin), ctx);
72
+ #define ASSERT_EX_ENCRYPT_INIT_FAILS(bin, msg) ASSERT_FAILS(mongocrypt_ctx_explicit_encrypt_init(ctx, bin), ctx, msg);
73
+
74
+ #define ASSERT_EX_ENCRYPT_EXPRESSION_INIT_OK(bin) \
75
+ ASSERT_OK(mongocrypt_ctx_explicit_encrypt_expression_init(ctx, bin), ctx);
76
+ #define ASSERT_EX_ENCRYPT_EXPRESSION_INIT_FAILS(bin, msg) \
77
+ ASSERT_FAILS(mongocrypt_ctx_explicit_encrypt_expression_init(ctx, bin), ctx, msg);
78
+
79
+ #define ASSERT_DECRYPT_INIT_OK(bin) ASSERT_OK(mongocrypt_ctx_decrypt_init(ctx, bin), ctx);
80
+ #define ASSERT_DECRYPT_INIT_FAILS(bin, msg) ASSERT_FAILS(mongocrypt_ctx_decrypt_init(ctx, bin), ctx, msg);
81
+
82
+ #define ASSERT_EX_DECRYPT_INIT_OK(bin) ASSERT_OK(mongocrypt_ctx_explicit_decrypt_init(ctx, bin), ctx);
83
+ #define ASSERT_EX_DECRYPT_INIT_FAILS(bin, msg) ASSERT_FAILS(mongocrypt_ctx_explicit_decrypt_init(ctx, bin), ctx, msg);
84
+
85
+ #define REFRESH \
86
+ do { \
87
+ mongocrypt_ctx_destroy(ctx); \
88
+ ctx = mongocrypt_ctx_new(crypt); \
89
+ } while (0)
122
90
 
123
91
  #define DET MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR
124
92
  #define RAND MONGOCRYPT_ALGORITHM_RANDOM_STR
125
93
 
126
94
  /* Test valid and invalid options */
127
- static void
128
- _test_setopt_masterkey_aws (_mongocrypt_tester_t *tester)
129
- {
130
- mongocrypt_t *crypt;
131
- mongocrypt_ctx_t *ctx = NULL;
132
-
133
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
134
-
135
- REFRESH;
136
- ASSERT_MASTERKEY_AWS_FAILS (NULL, 0, "cmk", 3, "invalid region");
137
- REFRESH;
138
- ASSERT_MASTERKEY_AWS_FAILS ("region", 6, NULL, 0, "invalid cmk");
139
- REFRESH;
140
- ASSERT_MASTERKEY_AWS_FAILS ("region", 0, "cmk", 0, "invalid region");
141
- REFRESH;
142
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
143
- REFRESH;
144
- ASSERT_MASTERKEY_AWS_FAILS ("region", -2, "cmk", -1, "invalid region");
145
- REFRESH;
146
- ASSERT_MASTERKEY_AWS_FAILS ("region", -1, "cmk", -2, "invalid cmk");
147
-
148
- /* Test invalid UTF 8 */
149
- REFRESH;
150
- ASSERT_MASTERKEY_AWS_FAILS (invalid_utf8, -1, "cmk", -2, "invalid region");
151
-
152
- /* Test double setting. */
153
- REFRESH;
154
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
155
- ASSERT_MASTERKEY_AWS_FAILS (
156
- "region", -1, "cmk", -1, "master key already set");
157
-
158
- /* Cannot be set with local masterkey. */
159
- REFRESH;
160
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
161
- ASSERT_MASTERKEY_LOCAL_FAILS ("master key already set");
162
-
163
- /* Cannot be set after entering error state. */
164
- REFRESH;
165
- _mongocrypt_ctx_fail_w_msg (ctx, "test");
166
- ASSERT_MASTERKEY_AWS_FAILS ("region", -1, "cmk", -1, "test");
167
-
168
- mongocrypt_ctx_destroy (ctx);
169
- mongocrypt_destroy (crypt);
95
+ static void _test_setopt_masterkey_aws(_mongocrypt_tester_t *tester) {
96
+ mongocrypt_t *crypt;
97
+ mongocrypt_ctx_t *ctx = NULL;
98
+
99
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
100
+
101
+ REFRESH;
102
+ ASSERT_MASTERKEY_AWS_FAILS(NULL, 0, "cmk", 3, "invalid region");
103
+ REFRESH;
104
+ ASSERT_MASTERKEY_AWS_FAILS("region", 6, NULL, 0, "invalid cmk");
105
+ REFRESH;
106
+ ASSERT_MASTERKEY_AWS_FAILS("region", 0, "cmk", 0, "invalid region");
107
+ REFRESH;
108
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
109
+ REFRESH;
110
+ ASSERT_MASTERKEY_AWS_FAILS("region", -2, "cmk", -1, "invalid region");
111
+ REFRESH;
112
+ ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -2, "invalid cmk");
113
+
114
+ /* Test invalid UTF 8 */
115
+ REFRESH;
116
+ ASSERT_MASTERKEY_AWS_FAILS(invalid_utf8, -1, "cmk", -2, "invalid region");
117
+
118
+ /* Test double setting. */
119
+ REFRESH;
120
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
121
+ ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -1, "master key already set");
122
+
123
+ /* Cannot be set with local masterkey. */
124
+ REFRESH;
125
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
126
+ ASSERT_MASTERKEY_LOCAL_FAILS("master key already set");
127
+
128
+ /* Cannot be set after entering error state. */
129
+ REFRESH;
130
+ _mongocrypt_ctx_fail_w_msg(ctx, "test");
131
+ ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -1, "test");
132
+
133
+ mongocrypt_ctx_destroy(ctx);
134
+ mongocrypt_destroy(crypt);
170
135
  }
171
136
 
137
+ static void _test_setopt_masterkey_local(_mongocrypt_tester_t *tester) {
138
+ mongocrypt_t *crypt;
139
+ mongocrypt_ctx_t *ctx = NULL;
172
140
 
173
- static void
174
- _test_setopt_masterkey_local (_mongocrypt_tester_t *tester)
175
- {
176
- mongocrypt_t *crypt;
177
- mongocrypt_ctx_t *ctx = NULL;
141
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
178
142
 
179
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
143
+ /* Test double setting. */
144
+ REFRESH;
145
+ ASSERT_MASTERKEY_LOCAL_OK;
146
+ ASSERT_MASTERKEY_LOCAL_FAILS("master key already set");
180
147
 
181
- /* Test double setting. */
182
- REFRESH;
183
- ASSERT_MASTERKEY_LOCAL_OK;
184
- ASSERT_MASTERKEY_LOCAL_FAILS ("master key already set");
148
+ /* Cannot be set with aws masterkey. */
149
+ REFRESH;
150
+ ASSERT_MASTERKEY_LOCAL_OK;
151
+ ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -1, "master key already set");
185
152
 
186
- /* Cannot be set with aws masterkey. */
187
- REFRESH;
188
- ASSERT_MASTERKEY_LOCAL_OK;
189
- ASSERT_MASTERKEY_AWS_FAILS (
190
- "region", -1, "cmk", -1, "master key already set");
153
+ REFRESH;
154
+ _mongocrypt_ctx_fail_w_msg(ctx, "test");
155
+ ASSERT_MASTERKEY_LOCAL_FAILS("test");
191
156
 
192
- REFRESH;
193
- _mongocrypt_ctx_fail_w_msg (ctx, "test");
194
- ASSERT_MASTERKEY_LOCAL_FAILS ("test");
195
-
196
- mongocrypt_ctx_destroy (ctx);
197
- mongocrypt_destroy (crypt);
157
+ mongocrypt_ctx_destroy(ctx);
158
+ mongocrypt_destroy(crypt);
198
159
  }
199
160
 
200
- static void
201
- _test_setopt_key_encryption_key_azure (_mongocrypt_tester_t *tester)
202
- {
203
- mongocrypt_t *crypt;
204
- mongocrypt_ctx_t *ctx = NULL;
205
-
206
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
207
-
208
- /* Test double setting. */
209
- REFRESH;
210
- ASSERT_KEY_ENCRYPTION_KEY_OK (
211
- TEST_BSON ("{'provider': 'azure', 'keyName': '', "
212
- "'keyVaultEndpoint': 'example.com' }"));
213
- ASSERT_KEY_ENCRYPTION_KEY_FAILS (
214
- TEST_BSON ("{'provider': 'azure', 'keyName': '', "
215
- "'keyVaultEndpoint': 'example.com' }"),
216
- "key encryption key already set");
217
-
218
- /* Cannot be set when another masterkey is set. */
219
- REFRESH;
220
- ASSERT_MASTERKEY_LOCAL_OK;
221
- ASSERT_KEY_ENCRYPTION_KEY_FAILS (
222
- TEST_BSON ("{'provider': 'azure', 'keyName': '', "
223
- "'keyVaultEndpoint': 'example.com' }"),
224
- "key encryption key already set");
225
-
226
- REFRESH;
227
- _mongocrypt_ctx_fail_w_msg (ctx, "test");
228
- ASSERT_KEY_ENCRYPTION_KEY_FAILS (
229
- TEST_BSON ("{'provider': 'azure', 'keyName': '', "
230
- "'keyVaultEndpoint': 'example.com' }"),
231
- "test");
232
-
233
- mongocrypt_ctx_destroy (ctx);
234
- mongocrypt_destroy (crypt);
161
+ static void _test_setopt_key_encryption_key_azure(_mongocrypt_tester_t *tester) {
162
+ mongocrypt_t *crypt;
163
+ mongocrypt_ctx_t *ctx = NULL;
164
+
165
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
166
+
167
+ /* Test double setting. */
168
+ REFRESH;
169
+ ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
170
+ "'keyVaultEndpoint': 'example.com' }"));
171
+ ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'azure', 'keyName': '', "
172
+ "'keyVaultEndpoint': 'example.com' }"),
173
+ "key encryption key already set");
174
+
175
+ /* Cannot be set when another masterkey is set. */
176
+ REFRESH;
177
+ ASSERT_MASTERKEY_LOCAL_OK;
178
+ ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'azure', 'keyName': '', "
179
+ "'keyVaultEndpoint': 'example.com' }"),
180
+ "key encryption key already set");
181
+
182
+ REFRESH;
183
+ _mongocrypt_ctx_fail_w_msg(ctx, "test");
184
+ ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'azure', 'keyName': '', "
185
+ "'keyVaultEndpoint': 'example.com' }"),
186
+ "test");
187
+
188
+ mongocrypt_ctx_destroy(ctx);
189
+ mongocrypt_destroy(crypt);
235
190
  }
236
191
 
237
- static void
238
- _test_setopt_key_encryption_key_gcp (_mongocrypt_tester_t *tester)
239
- {
240
- mongocrypt_t *crypt;
241
- mongocrypt_ctx_t *ctx = NULL;
242
-
243
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
244
-
245
- /* Test double setting. */
246
- REFRESH;
247
- ASSERT_KEY_ENCRYPTION_KEY_OK (
248
- TEST_BSON ("{'provider': 'gcp', 'projectId': 'proj', 'location': "
249
- "'google.com', 'keyRing': 'ring', 'keyName': 'key' }"));
250
- ASSERT_KEY_ENCRYPTION_KEY_FAILS (
251
- TEST_BSON ("{'provider': 'gcp', 'projectId': 'proj', 'location': "
252
- "'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
253
- "key encryption key already set");
254
-
255
- /* Cannot be set when another masterkey is set. */
256
- REFRESH;
257
- ASSERT_MASTERKEY_LOCAL_OK;
258
- ASSERT_KEY_ENCRYPTION_KEY_FAILS (
259
- TEST_BSON ("{'provider': 'gcp', 'projectId': 'proj', 'location': "
260
- "'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
261
- "key encryption key already set");
262
-
263
- REFRESH;
264
- _mongocrypt_ctx_fail_w_msg (ctx, "test");
265
- ASSERT_KEY_ENCRYPTION_KEY_FAILS (
266
- TEST_BSON ("{'provider': 'gcp', 'projectId': 'proj', 'location': "
267
- "'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
268
- "test");
269
-
270
- mongocrypt_ctx_destroy (ctx);
271
- mongocrypt_destroy (crypt);
192
+ static void _test_setopt_key_encryption_key_gcp(_mongocrypt_tester_t *tester) {
193
+ mongocrypt_t *crypt;
194
+ mongocrypt_ctx_t *ctx = NULL;
195
+
196
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
197
+
198
+ /* Test double setting. */
199
+ REFRESH;
200
+ ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'gcp', 'projectId': 'proj', 'location': "
201
+ "'google.com', 'keyRing': 'ring', 'keyName': 'key' }"));
202
+ ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'gcp', 'projectId': 'proj', 'location': "
203
+ "'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
204
+ "key encryption key already set");
205
+
206
+ /* Cannot be set when another masterkey is set. */
207
+ REFRESH;
208
+ ASSERT_MASTERKEY_LOCAL_OK;
209
+ ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'gcp', 'projectId': 'proj', 'location': "
210
+ "'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
211
+ "key encryption key already set");
212
+
213
+ REFRESH;
214
+ _mongocrypt_ctx_fail_w_msg(ctx, "test");
215
+ ASSERT_KEY_ENCRYPTION_KEY_FAILS(TEST_BSON("{'provider': 'gcp', 'projectId': 'proj', 'location': "
216
+ "'google.com', 'keyRing': 'ring', 'keyName': 'key' }"),
217
+ "test");
218
+
219
+ mongocrypt_ctx_destroy(ctx);
220
+ mongocrypt_destroy(crypt);
272
221
  }
273
222
 
223
+ static void _test_setopt_key_id(_mongocrypt_tester_t *tester) {
224
+ mongocrypt_t *crypt;
225
+ mongocrypt_ctx_t *ctx = NULL;
274
226
 
275
- static void
276
- _test_setopt_key_id (_mongocrypt_tester_t *tester)
277
- {
278
- mongocrypt_t *crypt;
279
- mongocrypt_ctx_t *ctx = NULL;
280
-
281
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
227
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
282
228
 
283
- /* Test double setting. */
284
- REFRESH;
285
- ASSERT_KEY_ID_OK (TEST_BIN (16));
286
- ASSERT_KEY_ID_FAILS (TEST_BIN (16), "option already set");
229
+ /* Test double setting. */
230
+ REFRESH;
231
+ ASSERT_KEY_ID_OK(TEST_BIN(16));
232
+ ASSERT_KEY_ID_FAILS(TEST_BIN(16), "option already set");
287
233
 
288
- /* Test NULL/empty input */
289
- REFRESH;
290
- ASSERT_KEY_ID_FAILS (NULL, "option must be non-NULL");
234
+ /* Test NULL/empty input */
235
+ REFRESH;
236
+ ASSERT_KEY_ID_FAILS(NULL, "option must be non-NULL");
291
237
 
292
- REFRESH;
293
- ASSERT_KEY_ID_FAILS (TEST_BIN (0), "option must be non-NULL");
238
+ REFRESH;
239
+ ASSERT_KEY_ID_FAILS(TEST_BIN(0), "option must be non-NULL");
294
240
 
295
- /* Test wrong length */
296
- REFRESH;
297
- ASSERT_KEY_ID_FAILS (TEST_BIN (5), "expected 16 byte UUID");
241
+ /* Test wrong length */
242
+ REFRESH;
243
+ ASSERT_KEY_ID_FAILS(TEST_BIN(5), "expected 16 byte UUID");
298
244
 
299
- REFRESH;
300
- _mongocrypt_ctx_fail_w_msg (ctx, "test");
301
- ASSERT_KEY_ID_FAILS (TEST_BIN (16), "test");
245
+ REFRESH;
246
+ _mongocrypt_ctx_fail_w_msg(ctx, "test");
247
+ ASSERT_KEY_ID_FAILS(TEST_BIN(16), "test");
302
248
 
303
- mongocrypt_ctx_destroy (ctx);
304
- mongocrypt_destroy (crypt);
249
+ mongocrypt_ctx_destroy(ctx);
250
+ mongocrypt_destroy(crypt);
305
251
  }
306
252
 
253
+ static void _test_setopt_key_alt_name(_mongocrypt_tester_t *tester) {
254
+ mongocrypt_t *crypt;
255
+ mongocrypt_ctx_t *ctx = NULL;
307
256
 
308
- static void
309
- _test_setopt_key_alt_name (_mongocrypt_tester_t *tester)
310
- {
311
- mongocrypt_t *crypt;
312
- mongocrypt_ctx_t *ctx = NULL;
257
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
313
258
 
314
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
259
+ /* Test double setting - actually succeeds since multiple key alt names
260
+ * allowed for data keys. */
261
+ REFRESH;
262
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
263
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'def'}"));
315
264
 
316
- /* Test double setting - actually succeeds since multiple key alt names
317
- * allowed for data keys. */
318
- REFRESH;
319
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
320
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'def'}"));
265
+ /* Test NULL/empty input */
266
+ REFRESH;
267
+ ASSERT_KEY_ALT_NAME_FAILS(NULL, "option must be non-NULL");
321
268
 
322
- /* Test NULL/empty input */
323
- REFRESH;
324
- ASSERT_KEY_ALT_NAME_FAILS (NULL, "option must be non-NULL");
269
+ REFRESH;
270
+ ASSERT_KEY_ALT_NAME_FAILS(TEST_BIN(0), "option must be non-NULL");
325
271
 
326
- REFRESH;
327
- ASSERT_KEY_ALT_NAME_FAILS (TEST_BIN (0), "option must be non-NULL");
272
+ /* Test wrong type */
273
+ REFRESH;
274
+ REFRESH;
275
+ ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'keyAltName': 1}"), "keyAltName expected to be UTF8");
328
276
 
329
- /* Test wrong type */
330
- REFRESH;
331
- REFRESH;
332
- ASSERT_KEY_ALT_NAME_FAILS (TEST_BSON ("{'keyAltName': 1}"),
333
- "keyAltName expected to be UTF8");
277
+ /* Test missing key */
278
+ REFRESH;
279
+ ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'keyAltNames': 'abc'}"), "keyAltName must have field 'keyAltName'");
334
280
 
335
- /* Test missing key */
336
- REFRESH;
337
- ASSERT_KEY_ALT_NAME_FAILS (TEST_BSON ("{'keyAltNames': 'abc'}"),
338
- "keyAltName must have field 'keyAltName'");
281
+ /* Test extra key */
282
+ REFRESH;
283
+ ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'keyAltName': 'abc', 'extra': 1}"), "unrecognized field");
339
284
 
340
- /* Test extra key */
341
- REFRESH;
342
- ASSERT_KEY_ALT_NAME_FAILS (TEST_BSON ("{'keyAltName': 'abc', 'extra': 1}"),
343
- "unrecognized field");
344
-
345
- mongocrypt_ctx_destroy (ctx);
346
- mongocrypt_destroy (crypt);
285
+ mongocrypt_ctx_destroy(ctx);
286
+ mongocrypt_destroy(crypt);
347
287
  }
348
288
 
349
-
350
- static void
351
- _test_setopt_key_material (_mongocrypt_tester_t *tester)
352
- {
353
- /* "0123456789abcef", repeated 6 times. */
354
- const char *const material =
355
- "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyMzQ1"
356
- "Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVm";
357
- const char *const pattern =
358
- "{'keyMaterial': {'$binary': {'base64': '%s', 'subType': '00'}}%s}";
359
- mongocrypt_binary_t *const valid = TEST_BSON (pattern, material, "");
360
-
361
- mongocrypt_t *crypt =
362
- _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
363
- mongocrypt_ctx_t *ctx = NULL;
364
-
365
- /* Test double setting. */
366
- REFRESH;
367
- ASSERT_KEY_MATERIAL_OK (valid);
368
- ASSERT_KEY_MATERIAL_FAILS (valid, "keyMaterial already set");
369
-
370
- /* Test NULL input. */
371
- REFRESH;
372
- ASSERT_KEY_MATERIAL_FAILS (NULL, "option must be non-NULL");
373
-
374
- /* Test empty input. */
375
- REFRESH;
376
- ASSERT_KEY_MATERIAL_FAILS (TEST_BIN (0), "option must be non-NULL");
377
-
378
- /* Test empty key material. */
379
- REFRESH;
380
- ASSERT_KEY_MATERIAL_FAILS (
381
- TEST_BSON (pattern, "", ""),
382
- "keyMaterial should have length 96, but has length 0");
383
-
384
- /* Test too short key material. */
385
- REFRESH;
386
- ASSERT_KEY_MATERIAL_FAILS (
387
- TEST_BSON (pattern,
388
- "dG9vc2hvcnQ=", /* "tooshort" */
389
- ""),
390
- "keyMaterial should have length 96, but has length 8");
391
-
392
- /* Test too long key material. */
393
- REFRESH;
394
- ASSERT_KEY_MATERIAL_FAILS (
395
- TEST_BSON (
396
- pattern,
397
- /* "0123456789abcdef", repeated 6 times, followed by "toolong". */
398
- "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyM"
399
- "zQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmdG9vbG9uZw"
400
- "==",
401
- ""),
402
- "keyMaterial should have length 96, but has length 103");
403
-
404
- /* Test invalid keyMaterial options. */
405
- REFRESH;
406
- ASSERT_KEY_MATERIAL_FAILS (TEST_BSON ("{}"), "invalid bson");
407
-
408
- REFRESH;
409
- ASSERT_KEY_MATERIAL_FAILS (TEST_BSON ("{'a': 1}"),
410
- "keyMaterial must have field 'keyMaterial'");
411
-
412
- REFRESH;
413
- ASSERT_KEY_MATERIAL_FAILS (TEST_BSON ("{'keyMaterial': 1}"),
414
- "keyMaterial must be binary data");
415
-
416
- /* Test extra key. */
417
- REFRESH;
418
- ASSERT_KEY_MATERIAL_FAILS (TEST_BSON (pattern, material, ", 'a': 1"),
289
+ static void _test_setopt_key_material(_mongocrypt_tester_t *tester) {
290
+ /* "0123456789abcef", repeated 6 times. */
291
+ const char *const material = "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyMzQ1"
292
+ "Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVm";
293
+ const char *const pattern = "{'keyMaterial': {'$binary': {'base64': '%s', 'subType': '00'}}%s}";
294
+ mongocrypt_binary_t *const valid = TEST_BSON(pattern, material, "");
295
+
296
+ mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
297
+ mongocrypt_ctx_t *ctx = NULL;
298
+
299
+ /* Test double setting. */
300
+ REFRESH;
301
+ ASSERT_KEY_MATERIAL_OK(valid);
302
+ ASSERT_KEY_MATERIAL_FAILS(valid, "keyMaterial already set");
303
+
304
+ /* Test NULL input. */
305
+ REFRESH;
306
+ ASSERT_KEY_MATERIAL_FAILS(NULL, "option must be non-NULL");
307
+
308
+ /* Test empty input. */
309
+ REFRESH;
310
+ ASSERT_KEY_MATERIAL_FAILS(TEST_BIN(0), "option must be non-NULL");
311
+
312
+ /* Test empty key material. */
313
+ REFRESH;
314
+ ASSERT_KEY_MATERIAL_FAILS(TEST_BSON(pattern, "", ""), "keyMaterial should have length 96, but has length 0");
315
+
316
+ /* Test too short key material. */
317
+ REFRESH;
318
+ ASSERT_KEY_MATERIAL_FAILS(TEST_BSON(pattern,
319
+ "dG9vc2hvcnQ=", /* "tooshort" */
320
+ ""),
321
+ "keyMaterial should have length 96, but has length 8");
322
+
323
+ /* Test too long key material. */
324
+ REFRESH;
325
+ ASSERT_KEY_MATERIAL_FAILS(TEST_BSON(pattern,
326
+ /* "0123456789abcdef", repeated 6 times, followed by "toolong". */
327
+ "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyM"
328
+ "zQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmdG9vbG9uZw"
329
+ "==",
330
+ ""),
331
+ "keyMaterial should have length 96, but has length 103");
332
+
333
+ /* Test invalid keyMaterial options. */
334
+ REFRESH;
335
+ ASSERT_KEY_MATERIAL_FAILS(TEST_BSON("{}"), "invalid bson");
336
+
337
+ REFRESH;
338
+ ASSERT_KEY_MATERIAL_FAILS(TEST_BSON("{'a': 1}"), "keyMaterial must have field 'keyMaterial'");
339
+
340
+ REFRESH;
341
+ ASSERT_KEY_MATERIAL_FAILS(TEST_BSON("{'keyMaterial': 1}"), "keyMaterial must be binary data");
342
+
343
+ /* Test extra key. */
344
+ REFRESH;
345
+ ASSERT_KEY_MATERIAL_FAILS(TEST_BSON(pattern, material, ", 'a': 1"),
419
346
  "unrecognized field, only keyMaterial expected");
420
347
 
421
- /* Test error propagation. */
422
- REFRESH;
423
- ASSERT (!_mongocrypt_ctx_fail_w_msg (ctx, "test"));
424
- ASSERT_KEY_MATERIAL_FAILS (valid, "test");
348
+ /* Test error propagation. */
349
+ REFRESH;
350
+ ASSERT(!_mongocrypt_ctx_fail_w_msg(ctx, "test"));
351
+ ASSERT_KEY_MATERIAL_FAILS(valid, "test");
425
352
 
426
- mongocrypt_ctx_destroy (ctx);
427
- mongocrypt_destroy (crypt);
353
+ mongocrypt_ctx_destroy(ctx);
354
+ mongocrypt_destroy(crypt);
428
355
  }
429
356
 
357
+ static void _test_setopt_algorithm(_mongocrypt_tester_t *tester) {
358
+ mongocrypt_t *crypt;
359
+ mongocrypt_ctx_t *ctx = NULL;
430
360
 
431
- static void
432
- _test_setopt_algorithm (_mongocrypt_tester_t *tester)
433
- {
434
- mongocrypt_t *crypt;
435
- mongocrypt_ctx_t *ctx = NULL;
361
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
436
362
 
437
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
363
+ REFRESH;
364
+ ASSERT_ALGORITHM_FAILS(DET, -2, "invalid algorithm length");
438
365
 
439
- REFRESH;
440
- ASSERT_ALGORITHM_FAILS (DET, -2, "invalid algorithm length");
366
+ REFRESH;
367
+ ASSERT_ALGORITHM_OK(DET, 43);
441
368
 
442
- REFRESH;
443
- ASSERT_ALGORITHM_OK (DET, 43);
369
+ REFRESH;
370
+ ASSERT_ALGORITHM_FAILS(DET, 42, "unsupported algorithm");
444
371
 
445
- REFRESH;
446
- ASSERT_ALGORITHM_FAILS (DET, 42, "unsupported algorithm");
372
+ /* Check for prior bug. It's "Random", not "Randomized" */
373
+ REFRESH;
374
+ ASSERT_ALGORITHM_FAILS(RAND "ized", -1, "unsupported algorithm");
447
375
 
448
- /* Check for prior bug. It's "Random", not "Randomized" */
449
- REFRESH;
450
- ASSERT_ALGORITHM_FAILS (RAND "ized", -1, "unsupported algorithm");
376
+ /* Test double setting. */
377
+ REFRESH;
378
+ ASSERT_ALGORITHM_OK(DET, -1);
379
+ ASSERT_ALGORITHM_FAILS(DET, -1, "already set algorithm");
451
380
 
452
- /* Test double setting. */
453
- REFRESH;
454
- ASSERT_ALGORITHM_OK (DET, -1);
455
- ASSERT_ALGORITHM_FAILS (DET, -1, "already set algorithm");
381
+ /* Test NULL input */
382
+ REFRESH;
383
+ ASSERT_ALGORITHM_FAILS(NULL, 0, "passed null algorithm");
456
384
 
457
- /* Test NULL input */
458
- REFRESH;
459
- ASSERT_ALGORITHM_FAILS (NULL, 0, "passed null algorithm");
385
+ REFRESH;
386
+ _mongocrypt_ctx_fail_w_msg(ctx, "test");
387
+ ASSERT_ALGORITHM_FAILS(RAND, -1, "test")
460
388
 
461
- REFRESH;
462
- _mongocrypt_ctx_fail_w_msg (ctx, "test");
463
- ASSERT_ALGORITHM_FAILS (RAND, -1, "test")
389
+ /* Test case insensitive. */
390
+ REFRESH;
391
+ ASSERT_ALGORITHM_OK("aEAD_AES_256_CBC_HMAC_SHA_512-Deterministic", -1);
392
+ REFRESH;
393
+ ASSERT_ALGORITHM_OK("aEAD_AES_256_CBC_HMAC_SHA_512-Random", -1);
394
+ REFRESH;
395
+ ASSERT_ALGORITHM_OK("indexed", -1);
396
+ REFRESH;
397
+ ASSERT_ALGORITHM_OK("unindexed", -1);
464
398
 
465
- /* Test case insensitive. */
466
- REFRESH;
467
- ASSERT_ALGORITHM_OK ("aEAD_AES_256_CBC_HMAC_SHA_512-Deterministic", -1);
468
- REFRESH;
469
- ASSERT_ALGORITHM_OK ("aEAD_AES_256_CBC_HMAC_SHA_512-Random", -1);
470
- REFRESH;
471
- ASSERT_ALGORITHM_OK ("indexed", -1);
472
- REFRESH;
473
- ASSERT_ALGORITHM_OK ("unindexed", -1);
474
-
475
- mongocrypt_ctx_destroy (ctx);
476
- mongocrypt_destroy (crypt);
399
+ mongocrypt_ctx_destroy(ctx);
400
+ mongocrypt_destroy(crypt);
477
401
  }
478
402
 
479
- static void
480
- _test_setopt_query_type (_mongocrypt_tester_t *tester)
481
- {
482
- mongocrypt_t *crypt;
483
- mongocrypt_ctx_t *ctx = NULL;
403
+ static void _test_setopt_query_type(_mongocrypt_tester_t *tester) {
404
+ mongocrypt_t *crypt;
405
+ mongocrypt_ctx_t *ctx = NULL;
484
406
 
485
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
407
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
486
408
 
487
- /* Test valid input. */
488
- REFRESH;
489
- ASSERT_QUERY_TYPE_OK (MONGOCRYPT_QUERY_TYPE_EQUALITY_STR,
490
- (int) strlen (MONGOCRYPT_QUERY_TYPE_EQUALITY_STR));
409
+ /* Test valid input. */
410
+ REFRESH;
411
+ ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, (int)strlen(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR));
491
412
 
492
- /* Test invalid length. */
493
- REFRESH;
494
- ASSERT_QUERY_TYPE_FAILS ("foo", -2, "Invalid query_type string length");
413
+ /* Test invalid length. */
414
+ REFRESH;
415
+ ASSERT_QUERY_TYPE_FAILS("foo", -2, "Invalid query_type string length");
495
416
 
496
- /* Test double setting. */
497
- REFRESH;
498
- ASSERT_QUERY_TYPE_OK (MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1);
499
- ASSERT_QUERY_TYPE_OK (MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1);
417
+ /* Test double setting. */
418
+ REFRESH;
419
+ ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1);
420
+ ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1);
500
421
 
501
- /* Test NULL input */
502
- REFRESH;
503
- ASSERT_QUERY_TYPE_FAILS (NULL, 0, "Invalid null query_type string");
422
+ /* Test NULL input */
423
+ REFRESH;
424
+ ASSERT_QUERY_TYPE_FAILS(NULL, 0, "Invalid null query_type string");
504
425
 
505
- /* Test with failed context. */
506
- REFRESH;
507
- _mongocrypt_ctx_fail_w_msg (ctx, "test");
508
- ASSERT_QUERY_TYPE_FAILS (MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1, "test")
426
+ /* Test with failed context. */
427
+ REFRESH;
428
+ _mongocrypt_ctx_fail_w_msg(ctx, "test");
429
+ ASSERT_QUERY_TYPE_FAILS(MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1, "test")
509
430
 
510
- /* Test case insensitive. */
511
- REFRESH;
512
- ASSERT_QUERY_TYPE_OK ("Equality", -1);
431
+ /* Test case insensitive. */
432
+ REFRESH;
433
+ ASSERT_QUERY_TYPE_OK("Equality", -1);
513
434
 
514
- mongocrypt_ctx_destroy (ctx);
515
- mongocrypt_destroy (crypt);
435
+ mongocrypt_ctx_destroy(ctx);
436
+ mongocrypt_destroy(crypt);
516
437
  }
517
438
 
518
-
519
439
  /* Test required and prohibited options on a datakey context. */
520
- static void
521
- _test_setopt_for_datakey (_mongocrypt_tester_t *tester)
522
- {
523
- mongocrypt_t *crypt;
524
- mongocrypt_ctx_t *ctx = NULL;
525
- mongocrypt_binary_t *uuid;
526
-
527
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
528
- uuid = TEST_BIN (16);
529
-
530
- /* Test required and prohibited options. */
531
- REFRESH;
532
- ASSERT_DATAKEY_INIT_FAILS ("master key required");
533
-
534
- REFRESH;
535
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
536
- ASSERT_DATAKEY_INIT_OK;
537
-
538
- REFRESH;
539
- ASSERT_KEY_ENCRYPTION_KEY_OK (
540
- TEST_BSON ("{'provider': 'azure', 'keyName': '', "
541
- "'keyVaultEndpoint': 'example.com' }"));
542
- ASSERT_DATAKEY_INIT_OK;
543
-
544
- /* Test optional key alt names. */
545
- REFRESH;
546
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
547
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
548
- ASSERT_DATAKEY_INIT_OK;
549
-
550
- /* Multiple key alt names are okay. */
551
- REFRESH;
552
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
553
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
554
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'def'}"));
555
- ASSERT_DATAKEY_INIT_OK;
556
-
557
- /* But duplicates are not. */
558
- REFRESH;
559
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
560
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
561
- ASSERT_KEY_ALT_NAME_FAILS (TEST_BSON ("{'keyAltName': 'abc'}"),
562
- "duplicate keyAltNames found");
563
-
564
- /* Key Material is okay. */
565
- REFRESH;
566
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
567
- ASSERT_KEY_MATERIAL_OK (
568
- TEST_BSON ("{'keyMaterial': {'$binary': {'base64': "
569
- "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
570
- "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
571
- "WJjZGVm', 'subType': '00'}}}"));
572
- ASSERT_DATAKEY_INIT_OK;
573
-
574
- /* Test each prohibited option. */
575
- REFRESH;
576
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
577
- ASSERT_KEY_ID_OK (uuid);
578
- ASSERT_DATAKEY_INIT_FAILS ("key id and alt name prohibited");
579
-
580
- REFRESH;
581
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
582
- ASSERT_ALGORITHM_OK (MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
583
- ASSERT_DATAKEY_INIT_FAILS ("algorithm prohibited");
584
-
585
- /* Test setting options after init. */
586
- REFRESH;
587
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
588
- ASSERT_DATAKEY_INIT_OK;
589
- ASSERT_MASTERKEY_AWS_FAILS (
590
- "region", -1, "cmk", -1, "cannot set options after init");
591
-
592
- REFRESH;
593
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
594
- ASSERT_ENDPOINT_OK ("example.com:80", -1);
595
- ASSERT_DATAKEY_INIT_OK;
596
-
597
- REFRESH;
598
- ASSERT_MASTERKEY_LOCAL_OK;
599
- ASSERT_ENDPOINT_FAILS ("example.com:80", -1, "endpoint prohibited");
600
-
601
- mongocrypt_ctx_destroy (ctx);
602
- mongocrypt_destroy (crypt);
440
+ static void _test_setopt_for_datakey(_mongocrypt_tester_t *tester) {
441
+ mongocrypt_t *crypt;
442
+ mongocrypt_ctx_t *ctx = NULL;
443
+ mongocrypt_binary_t *uuid;
444
+
445
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
446
+ uuid = TEST_BIN(16);
447
+
448
+ /* Test required and prohibited options. */
449
+ REFRESH;
450
+ ASSERT_DATAKEY_INIT_FAILS("master key required");
451
+
452
+ REFRESH;
453
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
454
+ ASSERT_DATAKEY_INIT_OK;
455
+
456
+ REFRESH;
457
+ ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
458
+ "'keyVaultEndpoint': 'example.com' }"));
459
+ ASSERT_DATAKEY_INIT_OK;
460
+
461
+ /* Test optional key alt names. */
462
+ REFRESH;
463
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
464
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
465
+ ASSERT_DATAKEY_INIT_OK;
466
+
467
+ /* Multiple key alt names are okay. */
468
+ REFRESH;
469
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
470
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
471
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'def'}"));
472
+ ASSERT_DATAKEY_INIT_OK;
473
+
474
+ /* But duplicates are not. */
475
+ REFRESH;
476
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
477
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
478
+ ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'keyAltName': 'abc'}"), "duplicate keyAltNames found");
479
+
480
+ /* Key Material is okay. */
481
+ REFRESH;
482
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
483
+ ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
484
+ "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
485
+ "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
486
+ "WJjZGVm', 'subType': '00'}}}"));
487
+ ASSERT_DATAKEY_INIT_OK;
488
+
489
+ /* Test each prohibited option. */
490
+ REFRESH;
491
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
492
+ ASSERT_KEY_ID_OK(uuid);
493
+ ASSERT_DATAKEY_INIT_FAILS("key id and alt name prohibited");
494
+
495
+ REFRESH;
496
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
497
+ ASSERT_ALGORITHM_OK(MONGOCRYPT_ALGORITHM_DETERMINISTIC_STR, -1);
498
+ ASSERT_DATAKEY_INIT_FAILS("algorithm prohibited");
499
+
500
+ /* Test setting options after init. */
501
+ REFRESH;
502
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
503
+ ASSERT_DATAKEY_INIT_OK;
504
+ ASSERT_MASTERKEY_AWS_FAILS("region", -1, "cmk", -1, "cannot set options after init");
505
+
506
+ REFRESH;
507
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
508
+ ASSERT_ENDPOINT_OK("example.com:80", -1);
509
+ ASSERT_DATAKEY_INIT_OK;
510
+
511
+ REFRESH;
512
+ ASSERT_MASTERKEY_LOCAL_OK;
513
+ ASSERT_ENDPOINT_FAILS("example.com:80", -1, "endpoint prohibited");
514
+
515
+ mongocrypt_ctx_destroy(ctx);
516
+ mongocrypt_destroy(crypt);
603
517
  }
604
518
 
605
-
606
- static void
607
- _test_setopt_for_encrypt (_mongocrypt_tester_t *tester)
608
- {
609
- mongocrypt_t *crypt;
610
- mongocrypt_ctx_t *ctx = NULL;
611
- mongocrypt_binary_t *uuid, *cmd;
612
-
613
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
614
- cmd = TEST_FILE ("./test/example/cmd.json");
615
- uuid = TEST_BIN (16);
616
-
617
- /* Test required and prohibited options. */
618
- REFRESH;
619
- ASSERT_ENCRYPT_INIT_OK ("a", -1, cmd);
620
-
621
- REFRESH;
622
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
623
- ENCRYPT_INIT_FAILS ("a", -1, cmd, "master key prohibited");
624
-
625
- REFRESH;
626
- ASSERT_MASTERKEY_LOCAL_OK;
627
- ENCRYPT_INIT_FAILS ("a", -1, cmd, "master key prohibited");
628
-
629
- REFRESH;
630
- ASSERT_KEY_ENCRYPTION_KEY_OK (
631
- TEST_BSON ("{'provider': 'azure', 'keyName': '', "
632
- "'keyVaultEndpoint': 'example.com' }"));
633
- ENCRYPT_INIT_FAILS ("a", -1, cmd, "master key prohibited");
634
-
635
- REFRESH;
636
- ASSERT_KEY_ID_OK (uuid);
637
- ENCRYPT_INIT_FAILS ("a", -1, cmd, "key id and alt name prohibited");
638
-
639
- REFRESH;
640
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
641
- ENCRYPT_INIT_FAILS ("a", -1, cmd, "key id and alt name prohibited");
642
-
643
- REFRESH;
644
- ASSERT_KEY_MATERIAL_OK (
645
- TEST_BSON ("{'keyMaterial': {'$binary': {'base64': "
646
- "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
647
- "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
648
- "WJjZGVm', 'subType': '00'}}}"));
649
- ENCRYPT_INIT_FAILS ("a", -1, cmd, "key material prohibited");
650
-
651
- REFRESH;
652
- ASSERT_ALGORITHM_OK (DET, -1);
653
- ENCRYPT_INIT_FAILS ("a", -1, cmd, "algorithm prohibited");
654
-
655
- REFRESH;
656
- ENCRYPT_INIT_FAILS ("a", -1, NULL, "invalid command");
657
-
658
- /* Test setting options after init. */
659
- REFRESH;
660
- ASSERT_ENCRYPT_INIT_OK ("a", -1, cmd);
661
- ASSERT_MASTERKEY_LOCAL_FAILS ("cannot set options after init");
662
-
663
- mongocrypt_ctx_destroy (ctx);
664
- mongocrypt_destroy (crypt);
519
+ static void _test_setopt_for_encrypt(_mongocrypt_tester_t *tester) {
520
+ mongocrypt_t *crypt;
521
+ mongocrypt_ctx_t *ctx = NULL;
522
+ mongocrypt_binary_t *uuid, *cmd;
523
+
524
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
525
+ cmd = TEST_FILE("./test/example/cmd.json");
526
+ uuid = TEST_BIN(16);
527
+
528
+ /* Test required and prohibited options. */
529
+ REFRESH;
530
+ ASSERT_ENCRYPT_INIT_OK("a", -1, cmd);
531
+
532
+ REFRESH;
533
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
534
+ ENCRYPT_INIT_FAILS("a", -1, cmd, "master key prohibited");
535
+
536
+ REFRESH;
537
+ ASSERT_MASTERKEY_LOCAL_OK;
538
+ ENCRYPT_INIT_FAILS("a", -1, cmd, "master key prohibited");
539
+
540
+ REFRESH;
541
+ ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
542
+ "'keyVaultEndpoint': 'example.com' }"));
543
+ ENCRYPT_INIT_FAILS("a", -1, cmd, "master key prohibited");
544
+
545
+ REFRESH;
546
+ ASSERT_KEY_ID_OK(uuid);
547
+ ENCRYPT_INIT_FAILS("a", -1, cmd, "key id and alt name prohibited");
548
+
549
+ REFRESH;
550
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
551
+ ENCRYPT_INIT_FAILS("a", -1, cmd, "key id and alt name prohibited");
552
+
553
+ REFRESH;
554
+ ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
555
+ "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
556
+ "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
557
+ "WJjZGVm', 'subType': '00'}}}"));
558
+ ENCRYPT_INIT_FAILS("a", -1, cmd, "key material prohibited");
559
+
560
+ REFRESH;
561
+ ASSERT_ALGORITHM_OK(DET, -1);
562
+ ENCRYPT_INIT_FAILS("a", -1, cmd, "algorithm prohibited");
563
+
564
+ REFRESH;
565
+ ENCRYPT_INIT_FAILS("a", -1, NULL, "invalid command");
566
+
567
+ /* Test setting options after init. */
568
+ REFRESH;
569
+ ASSERT_ENCRYPT_INIT_OK("a", -1, cmd);
570
+ ASSERT_MASTERKEY_LOCAL_FAILS("cannot set options after init");
571
+
572
+ mongocrypt_ctx_destroy(ctx);
573
+ mongocrypt_destroy(crypt);
665
574
  }
666
575
 
667
-
668
- static void
669
- _test_setopt_for_explicit_encrypt (_mongocrypt_tester_t *tester)
670
- {
671
- mongocrypt_t *crypt;
672
- mongocrypt_ctx_t *ctx = NULL;
673
- mongocrypt_binary_t *bson, *uuid, *rangeopts;
674
-
675
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
676
- uuid = TEST_BIN (16);
677
- bson = TEST_BSON ("{'v': 'hello'}");
678
- rangeopts =
679
- TEST_BSON ("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}");
680
-
681
- /* Test required and prohibited options. */
682
- REFRESH;
683
- ASSERT_KEY_ID_OK (uuid);
684
- ASSERT_ALGORITHM_OK (RAND, -1);
685
- ASSERT_EX_ENCRYPT_INIT_OK (bson);
686
-
687
- /* Just keyAltName is ok */
688
- REFRESH;
689
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
690
- ASSERT_ALGORITHM_OK (RAND, -1);
691
- ASSERT_EX_ENCRYPT_INIT_OK (bson);
692
-
693
- /* Two keyAltNames is invalid */
694
- REFRESH;
695
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
696
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'def'}"));
697
- ASSERT_ALGORITHM_OK (RAND, -1);
698
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson,
699
- "must not specify multiple key alt names");
700
-
701
- /* Both keyAltName and keyId is invalid */
702
- REFRESH;
703
- ASSERT_KEY_ID_OK (uuid);
704
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
705
- ASSERT_ALGORITHM_OK (RAND, -1);
706
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson,
707
- "cannot have both key id and key alt name");
708
-
709
- REFRESH;
710
- ASSERT_KEY_ID_OK (uuid);
711
- ASSERT_ALGORITHM_OK (RAND, -1);
712
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
713
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "master key prohibited");
714
-
715
- REFRESH;
716
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
717
- ASSERT_ALGORITHM_OK (RAND, -1);
718
- ASSERT_KEY_MATERIAL_OK (
719
- TEST_BSON ("{'keyMaterial': {'$binary': {'base64': "
720
- "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
721
- "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
722
- "WJjZGVm', 'subType': '00'}}}"));
723
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "key material prohibited");
724
-
725
- REFRESH;
726
- ASSERT_KEY_ID_OK (uuid);
727
- ASSERT_ALGORITHM_OK (RAND, -1);
728
- ASSERT_MASTERKEY_LOCAL_OK;
729
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "master key prohibited");
730
-
731
- REFRESH;
732
- ASSERT_KEY_ID_OK (uuid);
733
- ASSERT_ALGORITHM_OK (RAND, -1);
734
- ASSERT_KEY_ENCRYPTION_KEY_OK (
735
- TEST_BSON ("{'provider': 'azure', 'keyName': '', "
736
- "'keyVaultEndpoint': 'example.com' }"));
737
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "master key prohibited");
738
-
739
- REFRESH;
740
- ASSERT_KEY_ID_OK (uuid);
741
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "algorithm or index type required");
742
-
743
- REFRESH;
744
- ASSERT_ALGORITHM_OK (RAND, -1);
745
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "key id or key alt name required")
746
-
747
- REFRESH;
748
- ASSERT_KEY_ID_OK (uuid);
749
- ASSERT_ALGORITHM_OK (DET, -1);
750
- ASSERT_EX_ENCRYPT_INIT_OK (bson);
751
-
752
- /* Just key alt name is ok */
753
- REFRESH;
754
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
755
- ASSERT_ALGORITHM_OK (RAND, -1);
756
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
757
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "master key prohibited");
758
-
759
- REFRESH;
760
- ASSERT_KEY_ID_OK (uuid);
761
- ASSERT_ALGORITHM_OK (DET, -1);
762
- ASSERT_EX_ENCRYPT_INIT_OK (bson);
763
-
764
- /* Test setting options after init. */
765
- REFRESH;
766
- ASSERT_KEY_ID_OK (uuid);
767
- ASSERT_ALGORITHM_OK (RAND, -1);
768
- ASSERT_EX_ENCRYPT_INIT_OK (bson);
769
- ASSERT_ALGORITHM_FAILS (RAND, -1, "cannot set options after init");
770
-
771
- /* Test that an option failure validated at the time of 'setopt' persists
772
- * upon init. */
773
- REFRESH;
774
- ASSERT_KEY_ID_OK (uuid);
775
- ASSERT_ALGORITHM_FAILS ("bad-algo", -1, "unsupported algorithm");
776
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "unsupported algorithm");
777
-
778
- /* It is an error to set the FLE 1 keyAltName option with any of the FLE 2
779
- * options (index_type, index_key_id, contention_factor, query_type, or
780
- * range opts). */
781
- {
782
- REFRESH;
783
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
784
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
785
- ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1),
786
- ctx);
787
- ASSERT_EX_ENCRYPT_INIT_FAILS (
788
- bson, "cannot set both key alt name and index type");
789
-
790
- REFRESH;
791
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
792
- ASSERT_OK (mongocrypt_ctx_setopt_index_key_id (ctx, uuid), ctx);
793
- ASSERT_EX_ENCRYPT_INIT_FAILS (
794
- bson, "cannot set both key alt name and index key id");
795
-
796
- REFRESH;
797
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
798
- ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 123), ctx);
799
- ASSERT_EX_ENCRYPT_INIT_FAILS (
800
- bson, "cannot set both key alt name and contention factor");
801
-
802
- REFRESH;
803
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
804
- ASSERT_OK (mongocrypt_ctx_setopt_query_type (
805
- ctx, MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1),
806
- ctx);
807
- ASSERT_EX_ENCRYPT_INIT_FAILS (
808
- bson, "cannot set both key alt name and query type");
809
-
810
- REFRESH;
811
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
812
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm_range (ctx, rangeopts), ctx);
813
- ASSERT_EX_ENCRYPT_INIT_FAILS (
814
- bson, "cannot set both key alt name and range opts");
815
- }
816
-
817
- /* It is an error to set the FLE 1 algorithm option with any of the FLE 2
818
- * options (index_type, index_key_id, contention_factor, query_type, or
819
- * range opts). */
820
- {
821
- REFRESH;
822
- /* Set key ID to get past the 'either key id or key alt name required'
823
- * error */
824
- ASSERT_KEY_ID_OK (uuid);
825
- ASSERT_ALGORITHM_OK (RAND, -1);
826
- ASSERT_OK (mongocrypt_ctx_setopt_index_key_id (ctx, uuid), ctx);
827
- ASSERT_EX_ENCRYPT_INIT_FAILS (
828
- bson, "cannot set both algorithm and index key id");
829
-
830
- REFRESH;
831
- /* Set key ID to get past the 'either key id or key alt name required'
832
- * error */
833
- ASSERT_KEY_ID_OK (uuid);
834
- ASSERT_ALGORITHM_OK (RAND, -1);
835
- ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 123), ctx);
836
- ASSERT_EX_ENCRYPT_INIT_FAILS (
837
- bson, "cannot set both algorithm and contention factor");
838
- REFRESH;
839
- /* Set key ID to get past the 'either key id or key alt name required'
840
- * error */
841
- ASSERT_KEY_ID_OK (uuid);
842
- ASSERT_ALGORITHM_OK (RAND, -1);
843
- ASSERT_OK (mongocrypt_ctx_setopt_query_type (
844
- ctx, MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1),
845
- ctx);
846
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson,
847
- "cannot set both algorithm and query type");
848
- REFRESH;
849
- /* Set key ID to get past the 'either key id or key alt name required'
850
- * error */
851
- ASSERT_KEY_ID_OK (uuid);
852
- ASSERT_ALGORITHM_OK (RAND, -1);
853
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm_range (ctx, rangeopts), ctx);
854
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson,
855
- "cannot set both algorithm and range opts");
856
- }
857
-
858
- /* Require either index_type or algorithm */
859
- {
860
- REFRESH;
861
- /* Set key ID to get past the 'either key id or key alt name required'
862
- * error */
863
- ASSERT_KEY_ID_OK (uuid);
864
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "algorithm or index type required");
865
- }
866
-
867
- /* It is an error to set contention_factor with index_type ==
868
- * MONGOCRYPT_INDEX_TYPE_NONE */
869
- {
870
- REFRESH;
871
- /* Set key ID to get past the 'either key id or key alt name required'
872
- * error */
873
- ASSERT_KEY_ID_OK (uuid);
874
- ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 0), ctx);
875
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
876
- ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1),
877
- ctx);
878
- ASSERT_EX_ENCRYPT_INIT_FAILS (
879
- bson, "cannot set contention factor with no index type");
880
- }
881
-
882
- /* It is an error to set range opts with index_type ==
883
- * MONGOCRYPT_INDEX_TYPE_NONE */
884
- {
885
- REFRESH;
886
- /* Set key ID to get past the 'either key id or key alt name required'
887
- * error */
888
- ASSERT_KEY_ID_OK (uuid);
889
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm_range (ctx, rangeopts), ctx);
890
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
891
- ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1),
892
- ctx);
893
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson,
894
- "cannot set range opts with no index type");
895
- }
896
-
897
- /* It is an error to set range opts with index_type ==
898
- * MONGOCRYPT_INDEX_TYPE_EQUALITY */
899
- {
900
- REFRESH;
901
- /* Set key ID to get past the 'either key id or key alt name required'
902
- * error */
903
- ASSERT_KEY_ID_OK (uuid);
904
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm_range (ctx, rangeopts), ctx);
905
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
906
- ctx, MONGOCRYPT_ALGORITHM_INDEXED_STR, -1),
907
- ctx);
908
- ASSERT_EX_ENCRYPT_INIT_FAILS (
909
- bson, "cannot set range opts with equality index type");
910
- }
911
-
912
- /* It is an error to set query_type with index_type ==
913
- * MONGOCRYPT_INDEX_TYPE_NONE */
914
- {
915
- REFRESH;
916
- /* Set key ID to get past the 'either key id or key alt name required'
917
- * error */
918
- ASSERT_KEY_ID_OK (uuid);
919
- ASSERT_OK (mongocrypt_ctx_setopt_query_type (
920
- ctx, MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1),
921
- ctx);
922
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
923
- ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1),
924
- ctx);
925
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson,
926
- "cannot set query type with no index type");
927
- }
928
-
929
- /* Contention factor is required for "Indexed" algorithm. */
930
- {
931
- REFRESH;
932
- /* Set key ID to get past the 'either key id or key alt name required'
933
- * error */
934
- ASSERT_KEY_ID_OK (uuid);
935
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
936
- ctx, MONGOCRYPT_ALGORITHM_INDEXED_STR, -1),
937
- ctx);
938
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "contention factor is required");
939
- }
940
-
941
- /* Contention factor is required for "rangePreview" algorithm. */
942
- {
943
- REFRESH;
944
- /* Set key ID to get past the 'either key id or key alt name required'
945
- * error */
946
- ASSERT_KEY_ID_OK (uuid);
947
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm_range (ctx, rangeopts), ctx);
948
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
949
- ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1),
950
- ctx);
951
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "contention factor is required");
952
- }
953
-
954
- /* Range opts is required for "rangePreview" algorithm. */
955
- {
956
- REFRESH;
957
- /* Set key ID to get past the 'either key id or key alt name required'
958
- * error */
959
- ASSERT_KEY_ID_OK (uuid);
960
- ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 0), ctx);
961
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
962
- ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1),
963
- ctx);
964
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "range opts are required");
965
- }
966
-
967
- /* Negative sparsity is prohibited. */
968
- {
969
- REFRESH;
970
- /* Set key ID to get past the 'either key id or key alt name required'
971
- * error */
972
- ASSERT_KEY_ID_OK (uuid);
973
- ASSERT_OK (
974
- mongocrypt_ctx_setopt_algorithm_range (
975
- ctx,
976
- TEST_BSON (
977
- "{'min': 0, 'max': 1, 'sparsity': { '$numberLong': '-1'}}")),
978
- ctx);
979
- ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 0), ctx);
980
- ASSERT_OK (mongocrypt_ctx_setopt_algorithm (
981
- ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1),
982
- ctx);
983
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "sparsity must be non-negative");
984
- }
985
-
986
- /* Error if query_type == "rangePreview" and algorithm != "rangePreview". */
987
- {
988
- REFRESH;
989
- ASSERT_KEY_ID_OK (uuid);
990
- ASSERT_ALGORITHM_OK (MONGOCRYPT_ALGORITHM_INDEXED_STR, -1);
991
- ASSERT_QUERY_TYPE_OK (MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_STR, -1);
992
- ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 0), ctx);
993
- ASSERT_EX_ENCRYPT_INIT_FAILS (bson, "must match index_type");
994
- }
995
-
996
- /* Error if query_type == "rangePreview" for
997
- * mongocrypt_ctx_explicit_encrypt_init. */
998
- {
999
- REFRESH;
1000
- ASSERT_KEY_ID_OK (uuid);
1001
- ASSERT_ALGORITHM_OK (MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1);
1002
- ASSERT_QUERY_TYPE_OK (MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_STR, -1);
1003
- ASSERT_OK (
1004
- mongocrypt_ctx_setopt_algorithm_range (
1005
- ctx,
1006
- TEST_BSON (
1007
- "{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
1008
- ctx);
1009
- ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 0), ctx);
1010
- ASSERT_EX_ENCRYPT_INIT_FAILS (
1011
- bson,
1012
- "Encrypt may not be used for range queries. Use EncryptExpression.");
1013
- }
1014
-
1015
- /* Error if query_type is unset for
1016
- * mongocrypt_ctx_explicit_encrypt_expression_init. */
1017
- {
1018
- REFRESH;
1019
- ASSERT_KEY_ID_OK (uuid);
1020
- ASSERT_ALGORITHM_OK (MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1);
1021
- ASSERT_OK (
1022
- mongocrypt_ctx_setopt_algorithm_range (
1023
- ctx,
1024
- TEST_BSON (
1025
- "{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
1026
- ctx);
1027
- ASSERT_OK (mongocrypt_ctx_setopt_contention_factor (ctx, 0), ctx);
1028
- ASSERT_EX_ENCRYPT_EXPRESSION_INIT_FAILS (
1029
- bson, "EncryptExpression may only be used for range queries.");
1030
- }
1031
-
1032
- mongocrypt_ctx_destroy (ctx);
1033
- mongocrypt_destroy (crypt);
576
+ static void _test_setopt_for_explicit_encrypt(_mongocrypt_tester_t *tester) {
577
+ mongocrypt_t *crypt;
578
+ mongocrypt_ctx_t *ctx = NULL;
579
+ mongocrypt_binary_t *bson, *uuid, *rangeopts;
580
+
581
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
582
+ uuid = TEST_BIN(16);
583
+ bson = TEST_BSON("{'v': 'hello'}");
584
+ rangeopts = TEST_BSON("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}");
585
+
586
+ /* Test required and prohibited options. */
587
+ REFRESH;
588
+ ASSERT_KEY_ID_OK(uuid);
589
+ ASSERT_ALGORITHM_OK(RAND, -1);
590
+ ASSERT_EX_ENCRYPT_INIT_OK(bson);
591
+
592
+ /* Just keyAltName is ok */
593
+ REFRESH;
594
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
595
+ ASSERT_ALGORITHM_OK(RAND, -1);
596
+ ASSERT_EX_ENCRYPT_INIT_OK(bson);
597
+
598
+ /* Two keyAltNames is invalid */
599
+ REFRESH;
600
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
601
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'def'}"));
602
+ ASSERT_ALGORITHM_OK(RAND, -1);
603
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "must not specify multiple key alt names");
604
+
605
+ /* Both keyAltName and keyId is invalid */
606
+ REFRESH;
607
+ ASSERT_KEY_ID_OK(uuid);
608
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
609
+ ASSERT_ALGORITHM_OK(RAND, -1);
610
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot have both key id and key alt name");
611
+
612
+ REFRESH;
613
+ ASSERT_KEY_ID_OK(uuid);
614
+ ASSERT_ALGORITHM_OK(RAND, -1);
615
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
616
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "master key prohibited");
617
+
618
+ REFRESH;
619
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
620
+ ASSERT_ALGORITHM_OK(RAND, -1);
621
+ ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
622
+ "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
623
+ "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
624
+ "WJjZGVm', 'subType': '00'}}}"));
625
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "key material prohibited");
626
+
627
+ REFRESH;
628
+ ASSERT_KEY_ID_OK(uuid);
629
+ ASSERT_ALGORITHM_OK(RAND, -1);
630
+ ASSERT_MASTERKEY_LOCAL_OK;
631
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "master key prohibited");
632
+
633
+ REFRESH;
634
+ ASSERT_KEY_ID_OK(uuid);
635
+ ASSERT_ALGORITHM_OK(RAND, -1);
636
+ ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
637
+ "'keyVaultEndpoint': 'example.com' }"));
638
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "master key prohibited");
639
+
640
+ REFRESH;
641
+ ASSERT_KEY_ID_OK(uuid);
642
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "algorithm or index type required");
643
+
644
+ REFRESH;
645
+ ASSERT_ALGORITHM_OK(RAND, -1);
646
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "key id or key alt name required")
647
+
648
+ REFRESH;
649
+ ASSERT_KEY_ID_OK(uuid);
650
+ ASSERT_ALGORITHM_OK(DET, -1);
651
+ ASSERT_EX_ENCRYPT_INIT_OK(bson);
652
+
653
+ /* Just key alt name is ok */
654
+ REFRESH;
655
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
656
+ ASSERT_ALGORITHM_OK(RAND, -1);
657
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
658
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "master key prohibited");
659
+
660
+ REFRESH;
661
+ ASSERT_KEY_ID_OK(uuid);
662
+ ASSERT_ALGORITHM_OK(DET, -1);
663
+ ASSERT_EX_ENCRYPT_INIT_OK(bson);
664
+
665
+ /* Test setting options after init. */
666
+ REFRESH;
667
+ ASSERT_KEY_ID_OK(uuid);
668
+ ASSERT_ALGORITHM_OK(RAND, -1);
669
+ ASSERT_EX_ENCRYPT_INIT_OK(bson);
670
+ ASSERT_ALGORITHM_FAILS(RAND, -1, "cannot set options after init");
671
+
672
+ /* Test that an option failure validated at the time of 'setopt' persists
673
+ * upon init. */
674
+ REFRESH;
675
+ ASSERT_KEY_ID_OK(uuid);
676
+ ASSERT_ALGORITHM_FAILS("bad-algo", -1, "unsupported algorithm");
677
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "unsupported algorithm");
678
+
679
+ /* It is an error to set the FLE 1 keyAltName option with any of the FLE 2
680
+ * options (index_type, index_key_id, contention_factor, query_type, or
681
+ * range opts). */
682
+ {
683
+ REFRESH;
684
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
685
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1), ctx);
686
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and index type");
687
+
688
+ REFRESH;
689
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
690
+ ASSERT_OK(mongocrypt_ctx_setopt_index_key_id(ctx, uuid), ctx);
691
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and index key id");
692
+
693
+ REFRESH;
694
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
695
+ ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 123), ctx);
696
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and contention factor");
697
+
698
+ REFRESH;
699
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
700
+ ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1), ctx);
701
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and query type");
702
+
703
+ REFRESH;
704
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
705
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
706
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both key alt name and range opts");
707
+ }
708
+
709
+ /* It is an error to set the FLE 1 algorithm option with any of the FLE 2
710
+ * options (index_type, index_key_id, contention_factor, query_type, or
711
+ * range opts). */
712
+ {
713
+ REFRESH;
714
+ /* Set key ID to get past the 'either key id or key alt name required'
715
+ * error */
716
+ ASSERT_KEY_ID_OK(uuid);
717
+ ASSERT_ALGORITHM_OK(RAND, -1);
718
+ ASSERT_OK(mongocrypt_ctx_setopt_index_key_id(ctx, uuid), ctx);
719
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both algorithm and index key id");
720
+
721
+ REFRESH;
722
+ /* Set key ID to get past the 'either key id or key alt name required'
723
+ * error */
724
+ ASSERT_KEY_ID_OK(uuid);
725
+ ASSERT_ALGORITHM_OK(RAND, -1);
726
+ ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 123), ctx);
727
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both algorithm and contention factor");
728
+ REFRESH;
729
+ /* Set key ID to get past the 'either key id or key alt name required'
730
+ * error */
731
+ ASSERT_KEY_ID_OK(uuid);
732
+ ASSERT_ALGORITHM_OK(RAND, -1);
733
+ ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1), ctx);
734
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both algorithm and query type");
735
+ REFRESH;
736
+ /* Set key ID to get past the 'either key id or key alt name required'
737
+ * error */
738
+ ASSERT_KEY_ID_OK(uuid);
739
+ ASSERT_ALGORITHM_OK(RAND, -1);
740
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
741
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set both algorithm and range opts");
742
+ }
743
+
744
+ /* Require either index_type or algorithm */
745
+ {
746
+ REFRESH;
747
+ /* Set key ID to get past the 'either key id or key alt name required'
748
+ * error */
749
+ ASSERT_KEY_ID_OK(uuid);
750
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "algorithm or index type required");
751
+ }
752
+
753
+ /* It is an error to set contention_factor with index_type ==
754
+ * MONGOCRYPT_INDEX_TYPE_NONE */
755
+ {
756
+ REFRESH;
757
+ /* Set key ID to get past the 'either key id or key alt name required'
758
+ * error */
759
+ ASSERT_KEY_ID_OK(uuid);
760
+ ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
761
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1), ctx);
762
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set contention factor with no index type");
763
+ }
764
+
765
+ /* It is an error to set range opts with index_type ==
766
+ * MONGOCRYPT_INDEX_TYPE_NONE */
767
+ {
768
+ REFRESH;
769
+ /* Set key ID to get past the 'either key id or key alt name required'
770
+ * error */
771
+ ASSERT_KEY_ID_OK(uuid);
772
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
773
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1), ctx);
774
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set range opts with no index type");
775
+ }
776
+
777
+ /* It is an error to set range opts with index_type ==
778
+ * MONGOCRYPT_INDEX_TYPE_EQUALITY */
779
+ {
780
+ REFRESH;
781
+ /* Set key ID to get past the 'either key id or key alt name required'
782
+ * error */
783
+ ASSERT_KEY_ID_OK(uuid);
784
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
785
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_INDEXED_STR, -1), ctx);
786
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set range opts with equality index type");
787
+ }
788
+
789
+ /* It is an error to set query_type with index_type ==
790
+ * MONGOCRYPT_INDEX_TYPE_NONE */
791
+ {
792
+ REFRESH;
793
+ /* Set key ID to get past the 'either key id or key alt name required'
794
+ * error */
795
+ ASSERT_KEY_ID_OK(uuid);
796
+ ASSERT_OK(mongocrypt_ctx_setopt_query_type(ctx, MONGOCRYPT_QUERY_TYPE_EQUALITY_STR, -1), ctx);
797
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_UNINDEXED_STR, -1), ctx);
798
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "cannot set query type with no index type");
799
+ }
800
+
801
+ /* Contention factor is required for "Indexed" algorithm. */
802
+ {
803
+ REFRESH;
804
+ /* Set key ID to get past the 'either key id or key alt name required'
805
+ * error */
806
+ ASSERT_KEY_ID_OK(uuid);
807
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_INDEXED_STR, -1), ctx);
808
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "contention factor is required");
809
+ }
810
+
811
+ /* Contention factor is required for "rangePreview" algorithm. */
812
+ {
813
+ REFRESH;
814
+ /* Set key ID to get past the 'either key id or key alt name required'
815
+ * error */
816
+ ASSERT_KEY_ID_OK(uuid);
817
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(ctx, rangeopts), ctx);
818
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1), ctx);
819
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "contention factor is required");
820
+ }
821
+
822
+ /* Range opts is required for "rangePreview" algorithm. */
823
+ {
824
+ REFRESH;
825
+ /* Set key ID to get past the 'either key id or key alt name required'
826
+ * error */
827
+ ASSERT_KEY_ID_OK(uuid);
828
+ ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
829
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1), ctx);
830
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "range opts are required");
831
+ }
832
+
833
+ /* Negative sparsity is prohibited. */
834
+ {
835
+ REFRESH;
836
+ /* Set key ID to get past the 'either key id or key alt name required'
837
+ * error */
838
+ ASSERT_KEY_ID_OK(uuid);
839
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm_range(
840
+ ctx,
841
+ TEST_BSON("{'min': 0, 'max': 1, 'sparsity': { '$numberLong': '-1'}}")),
842
+ ctx);
843
+ ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
844
+ ASSERT_OK(mongocrypt_ctx_setopt_algorithm(ctx, MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1), ctx);
845
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "sparsity must be non-negative");
846
+ }
847
+
848
+ /* Error if query_type == "rangePreview" and algorithm != "rangePreview". */
849
+ {
850
+ REFRESH;
851
+ ASSERT_KEY_ID_OK(uuid);
852
+ ASSERT_ALGORITHM_OK(MONGOCRYPT_ALGORITHM_INDEXED_STR, -1);
853
+ ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_STR, -1);
854
+ ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
855
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "must match index_type");
856
+ }
857
+
858
+ /* Error if query_type == "rangePreview" for
859
+ * mongocrypt_ctx_explicit_encrypt_init. */
860
+ {
861
+ REFRESH;
862
+ ASSERT_KEY_ID_OK(uuid);
863
+ ASSERT_ALGORITHM_OK(MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1);
864
+ ASSERT_QUERY_TYPE_OK(MONGOCRYPT_QUERY_TYPE_RANGEPREVIEW_STR, -1);
865
+ ASSERT_OK(
866
+ mongocrypt_ctx_setopt_algorithm_range(ctx,
867
+ TEST_BSON("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
868
+ ctx);
869
+ ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
870
+ ASSERT_EX_ENCRYPT_INIT_FAILS(bson, "Encrypt may not be used for range queries. Use EncryptExpression.");
871
+ }
872
+
873
+ /* Error if query_type is unset for
874
+ * mongocrypt_ctx_explicit_encrypt_expression_init. */
875
+ {
876
+ REFRESH;
877
+ ASSERT_KEY_ID_OK(uuid);
878
+ ASSERT_ALGORITHM_OK(MONGOCRYPT_ALGORITHM_RANGEPREVIEW_STR, -1);
879
+ ASSERT_OK(
880
+ mongocrypt_ctx_setopt_algorithm_range(ctx,
881
+ TEST_BSON("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
882
+ ctx);
883
+ ASSERT_OK(mongocrypt_ctx_setopt_contention_factor(ctx, 0), ctx);
884
+ ASSERT_EX_ENCRYPT_EXPRESSION_INIT_FAILS(bson, "EncryptExpression may only be used for range queries.");
885
+ }
886
+
887
+ mongocrypt_ctx_destroy(ctx);
888
+ mongocrypt_destroy(crypt);
1034
889
  }
1035
890
 
891
+ static void _test_setopt_for_decrypt(_mongocrypt_tester_t *tester) {
892
+ mongocrypt_t *crypt;
893
+ mongocrypt_ctx_t *ctx = NULL;
894
+ mongocrypt_binary_t *bson, *uuid;
895
+
896
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
897
+ uuid = TEST_BIN(16);
898
+ bson = TEST_BSON("{'a': 1}");
899
+
900
+ /* Test required and prohibited options. */
901
+ REFRESH;
902
+ ASSERT_DECRYPT_INIT_OK(bson);
903
+
904
+ REFRESH;
905
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
906
+ ASSERT_DECRYPT_INIT_FAILS(bson, "master key prohibited");
907
+
908
+ REFRESH;
909
+ ASSERT_MASTERKEY_LOCAL_OK;
910
+ ASSERT_DECRYPT_INIT_FAILS(bson, "master key prohibited");
911
+
912
+ REFRESH;
913
+ ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
914
+ "'keyVaultEndpoint': 'example.com' }"));
915
+ ASSERT_DECRYPT_INIT_FAILS(bson, "master key prohibited");
916
+
917
+ REFRESH;
918
+ ASSERT_KEY_ID_OK(uuid);
919
+ ASSERT_DECRYPT_INIT_FAILS(bson, "key id and alt name prohibited");
920
+
921
+ REFRESH;
922
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
923
+ ASSERT_DECRYPT_INIT_FAILS(bson, "key id and alt name prohibited");
924
+
925
+ REFRESH;
926
+ ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
927
+ "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
928
+ "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
929
+ "WJjZGVm', 'subType': '00'}}}"));
930
+ ASSERT_DECRYPT_INIT_FAILS(bson, "key material prohibited");
931
+
932
+ REFRESH;
933
+ ASSERT_ALGORITHM_OK(DET, -1);
934
+ ASSERT_DECRYPT_INIT_FAILS(bson, "algorithm prohibited");
935
+
936
+ /* Test setting options after init. */
937
+ REFRESH;
938
+ ASSERT_DECRYPT_INIT_OK(bson);
939
+ ASSERT_MASTERKEY_LOCAL_FAILS("cannot set options after init");
940
+
941
+ mongocrypt_ctx_destroy(ctx);
942
+ mongocrypt_destroy(crypt);
943
+ }
1036
944
 
1037
- static void
1038
- _test_setopt_for_decrypt (_mongocrypt_tester_t *tester)
1039
- {
1040
- mongocrypt_t *crypt;
1041
- mongocrypt_ctx_t *ctx = NULL;
1042
- mongocrypt_binary_t *bson, *uuid;
1043
-
1044
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
1045
- uuid = TEST_BIN (16);
1046
- bson = TEST_BSON ("{'a': 1}");
1047
-
1048
- /* Test required and prohibited options. */
1049
- REFRESH;
1050
- ASSERT_DECRYPT_INIT_OK (bson);
1051
-
1052
- REFRESH;
1053
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
1054
- ASSERT_DECRYPT_INIT_FAILS (bson, "master key prohibited");
1055
-
1056
- REFRESH;
1057
- ASSERT_MASTERKEY_LOCAL_OK;
1058
- ASSERT_DECRYPT_INIT_FAILS (bson, "master key prohibited");
1059
-
1060
- REFRESH;
1061
- ASSERT_KEY_ENCRYPTION_KEY_OK (
1062
- TEST_BSON ("{'provider': 'azure', 'keyName': '', "
1063
- "'keyVaultEndpoint': 'example.com' }"));
1064
- ASSERT_DECRYPT_INIT_FAILS (bson, "master key prohibited");
1065
-
1066
- REFRESH;
1067
- ASSERT_KEY_ID_OK (uuid);
1068
- ASSERT_DECRYPT_INIT_FAILS (bson, "key id and alt name prohibited");
1069
-
1070
- REFRESH;
1071
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
1072
- ASSERT_DECRYPT_INIT_FAILS (bson, "key id and alt name prohibited");
1073
-
1074
- REFRESH;
1075
- ASSERT_KEY_MATERIAL_OK (
1076
- TEST_BSON ("{'keyMaterial': {'$binary': {'base64': "
1077
- "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
1078
- "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
1079
- "WJjZGVm', 'subType': '00'}}}"));
1080
- ASSERT_DECRYPT_INIT_FAILS (bson, "key material prohibited");
1081
-
1082
- REFRESH;
1083
- ASSERT_ALGORITHM_OK (DET, -1);
1084
- ASSERT_DECRYPT_INIT_FAILS (bson, "algorithm prohibited");
1085
-
1086
- /* Test setting options after init. */
1087
- REFRESH;
1088
- ASSERT_DECRYPT_INIT_OK (bson);
1089
- ASSERT_MASTERKEY_LOCAL_FAILS ("cannot set options after init");
1090
-
1091
- mongocrypt_ctx_destroy (ctx);
1092
- mongocrypt_destroy (crypt);
945
+ static void _test_setopt_for_explicit_decrypt(_mongocrypt_tester_t *tester) {
946
+ mongocrypt_t *crypt;
947
+ mongocrypt_ctx_t *ctx = NULL;
948
+ mongocrypt_binary_t *bson, *uuid;
949
+
950
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
951
+ uuid = TEST_BIN(16);
952
+ bson = TEST_FILE("./test/data/explicit-decryption-input.json");
953
+
954
+ /* Test required and prohibited options. */
955
+ REFRESH;
956
+ ASSERT_EX_DECRYPT_INIT_OK(bson);
957
+
958
+ REFRESH;
959
+ ASSERT_MASTERKEY_AWS_OK("region", -1, "cmk", -1);
960
+ ASSERT_EX_DECRYPT_INIT_FAILS(bson, "master key prohibited");
961
+
962
+ REFRESH;
963
+ ASSERT_MASTERKEY_LOCAL_OK;
964
+ ASSERT_EX_DECRYPT_INIT_FAILS(bson, "master key prohibited");
965
+
966
+ REFRESH;
967
+ ASSERT_KEY_ENCRYPTION_KEY_OK(TEST_BSON("{'provider': 'azure', 'keyName': '', "
968
+ "'keyVaultEndpoint': 'example.com' }"));
969
+ ASSERT_EX_DECRYPT_INIT_FAILS(bson, "master key prohibited");
970
+
971
+ REFRESH;
972
+ ASSERT_KEY_ID_OK(uuid);
973
+ ASSERT_EX_DECRYPT_INIT_FAILS(bson, "key id and alt name prohibited");
974
+
975
+ REFRESH;
976
+ ASSERT_KEY_ALT_NAME_OK(TEST_BSON("{'keyAltName': 'abc'}"));
977
+ ASSERT_DECRYPT_INIT_FAILS(bson, "key id and alt name prohibited");
978
+
979
+ REFRESH;
980
+ ASSERT_KEY_MATERIAL_OK(TEST_BSON("{'keyMaterial': {'$binary': {'base64': "
981
+ "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
982
+ "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
983
+ "WJjZGVm', 'subType': '00'}}}"));
984
+ ASSERT_DECRYPT_INIT_FAILS(bson, "key material prohibited");
985
+
986
+ REFRESH;
987
+ ASSERT_ALGORITHM_OK(DET, -1);
988
+ ASSERT_EX_DECRYPT_INIT_FAILS(bson, "algorithm prohibited");
989
+
990
+ // Range opts are prohibited.
991
+ REFRESH;
992
+ ASSERT_OK(
993
+ mongocrypt_ctx_setopt_algorithm_range(ctx, TEST_BSON("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
994
+ ctx);
995
+ ASSERT_EX_DECRYPT_INIT_FAILS(bson, "range opts are prohibited");
996
+
997
+ mongocrypt_ctx_destroy(ctx);
998
+ mongocrypt_destroy(crypt);
1093
999
  }
1094
1000
 
1001
+ static void _test_setopt_failure_uninitialized(_mongocrypt_tester_t *tester) {
1002
+ mongocrypt_t *crypt;
1003
+ mongocrypt_ctx_t *ctx = NULL;
1004
+ mongocrypt_status_t *status;
1095
1005
 
1096
- static void
1097
- _test_setopt_for_explicit_decrypt (_mongocrypt_tester_t *tester)
1098
- {
1099
- mongocrypt_t *crypt;
1100
- mongocrypt_ctx_t *ctx = NULL;
1101
- mongocrypt_binary_t *bson, *uuid;
1102
-
1103
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
1104
- uuid = TEST_BIN (16);
1105
- bson = TEST_FILE ("./test/data/explicit-decryption-input.json");
1106
-
1107
- /* Test required and prohibited options. */
1108
- REFRESH;
1109
- ASSERT_EX_DECRYPT_INIT_OK (bson);
1110
-
1111
- REFRESH;
1112
- ASSERT_MASTERKEY_AWS_OK ("region", -1, "cmk", -1);
1113
- ASSERT_EX_DECRYPT_INIT_FAILS (bson, "master key prohibited");
1114
-
1115
- REFRESH;
1116
- ASSERT_MASTERKEY_LOCAL_OK;
1117
- ASSERT_EX_DECRYPT_INIT_FAILS (bson, "master key prohibited");
1118
-
1119
- REFRESH;
1120
- ASSERT_KEY_ENCRYPTION_KEY_OK (
1121
- TEST_BSON ("{'provider': 'azure', 'keyName': '', "
1122
- "'keyVaultEndpoint': 'example.com' }"));
1123
- ASSERT_EX_DECRYPT_INIT_FAILS (bson, "master key prohibited");
1124
-
1125
- REFRESH;
1126
- ASSERT_KEY_ID_OK (uuid);
1127
- ASSERT_EX_DECRYPT_INIT_FAILS (bson, "key id and alt name prohibited");
1128
-
1129
- REFRESH;
1130
- ASSERT_KEY_ALT_NAME_OK (TEST_BSON ("{'keyAltName': 'abc'}"));
1131
- ASSERT_DECRYPT_INIT_FAILS (bson, "key id and alt name prohibited");
1132
-
1133
- REFRESH;
1134
- ASSERT_KEY_MATERIAL_OK (
1135
- TEST_BSON ("{'keyMaterial': {'$binary': {'base64': "
1136
- "'MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJj"
1137
- "ZGVmMDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5Y"
1138
- "WJjZGVm', 'subType': '00'}}}"));
1139
- ASSERT_DECRYPT_INIT_FAILS (bson, "key material prohibited");
1140
-
1141
- REFRESH;
1142
- ASSERT_ALGORITHM_OK (DET, -1);
1143
- ASSERT_EX_DECRYPT_INIT_FAILS (bson, "algorithm prohibited");
1144
-
1145
- // Range opts are prohibited.
1146
- REFRESH;
1147
- ASSERT_OK (
1148
- mongocrypt_ctx_setopt_algorithm_range (
1149
- ctx,
1150
- TEST_BSON ("{'min': 0, 'max': 1, 'sparsity': {'$numberLong': '1'}}")),
1151
- ctx);
1152
- ASSERT_EX_DECRYPT_INIT_FAILS (bson, "range opts are prohibited");
1153
-
1154
- mongocrypt_ctx_destroy (ctx);
1155
- mongocrypt_destroy (crypt);
1156
- }
1006
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
1007
+ status = mongocrypt_status_new();
1157
1008
 
1009
+ REFRESH;
1010
+ ASSERT_KEY_ALT_NAME_FAILS(TEST_BSON("{'fake': 'abc'}"), "keyAltName must have field 'keyAltName'");
1011
+ /* Though mongocrypt_ctx_t is uninitialized, we should still get failure
1012
+ * status. */
1013
+ ASSERT_FAILS_STATUS(mongocrypt_ctx_status(ctx, status), status, "keyAltName must have field 'keyAltName'");
1158
1014
 
1159
- static void
1160
- _test_setopt_failure_uninitialized (_mongocrypt_tester_t *tester)
1161
- {
1162
- mongocrypt_t *crypt;
1163
- mongocrypt_ctx_t *ctx = NULL;
1164
- mongocrypt_status_t *status;
1165
-
1166
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
1167
- status = mongocrypt_status_new ();
1168
-
1169
- REFRESH;
1170
- ASSERT_KEY_ALT_NAME_FAILS (TEST_BSON ("{'fake': 'abc'}"),
1171
- "keyAltName must have field 'keyAltName'");
1172
- /* Though mongocrypt_ctx_t is uninitialized, we should still get failure
1173
- * status. */
1174
- ASSERT_FAILS_STATUS (mongocrypt_ctx_status (ctx, status),
1175
- status,
1176
- "keyAltName must have field 'keyAltName'");
1177
-
1178
- mongocrypt_ctx_destroy (ctx);
1179
- mongocrypt_destroy (crypt);
1180
- mongocrypt_status_destroy (status);
1015
+ mongocrypt_ctx_destroy(ctx);
1016
+ mongocrypt_destroy(crypt);
1017
+ mongocrypt_status_destroy(status);
1181
1018
  }
1182
1019
 
1020
+ static void _test_setopt_endpoint(_mongocrypt_tester_t *tester) {
1021
+ mongocrypt_t *crypt;
1022
+ mongocrypt_ctx_t *ctx = NULL;
1183
1023
 
1184
- static void
1185
- _test_setopt_endpoint (_mongocrypt_tester_t *tester)
1186
- {
1187
- mongocrypt_t *crypt;
1188
- mongocrypt_ctx_t *ctx = NULL;
1024
+ crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
1189
1025
 
1190
- crypt = _mongocrypt_tester_mongocrypt (TESTER_MONGOCRYPT_DEFAULT);
1026
+ REFRESH;
1027
+ ASSERT_ENDPOINT_FAILS("example.com", -2, "Invalid endpoint");
1191
1028
 
1192
- REFRESH;
1193
- ASSERT_ENDPOINT_FAILS ("example.com", -2, "Invalid endpoint");
1029
+ REFRESH;
1030
+ ASSERT_ENDPOINT_OK("example.com", -1);
1031
+ BSON_ASSERT(0 == strcmp(ctx->opts.kek.provider.aws.endpoint->host_and_port, "example.com"));
1194
1032
 
1195
- REFRESH;
1196
- ASSERT_ENDPOINT_OK ("example.com", -1);
1197
- BSON_ASSERT (0 == strcmp (ctx->opts.kek.provider.aws.endpoint->host_and_port,
1198
- "example.com"));
1033
+ /* Including a port is ok. */
1034
+ REFRESH;
1035
+ ASSERT_ENDPOINT_OK("example.com:80", -1);
1036
+ BSON_ASSERT(0 == strcmp(ctx->opts.kek.provider.aws.endpoint->host_and_port, "example.com:80"));
1199
1037
 
1200
- /* Including a port is ok. */
1201
- REFRESH;
1202
- ASSERT_ENDPOINT_OK ("example.com:80", -1);
1203
- BSON_ASSERT (0 == strcmp (ctx->opts.kek.provider.aws.endpoint->host_and_port,
1204
- "example.com:80"));
1038
+ /* Test double setting. */
1039
+ REFRESH;
1040
+ ASSERT_ENDPOINT_OK("example.com", -1);
1041
+ ASSERT_ENDPOINT_FAILS("example.com", -1, "already set masterkey endpoint");
1205
1042
 
1206
- /* Test double setting. */
1207
- REFRESH;
1208
- ASSERT_ENDPOINT_OK ("example.com", -1);
1209
- ASSERT_ENDPOINT_FAILS ("example.com", -1, "already set masterkey endpoint");
1043
+ /* Test NULL input */
1044
+ REFRESH;
1045
+ ASSERT_ENDPOINT_FAILS(NULL, 0, "Invalid endpoint");
1210
1046
 
1211
- /* Test NULL input */
1212
- REFRESH;
1213
- ASSERT_ENDPOINT_FAILS (NULL, 0, "Invalid endpoint");
1047
+ REFRESH;
1048
+ _mongocrypt_ctx_fail_w_msg(ctx, "test");
1049
+ ASSERT_ENDPOINT_FAILS(RAND, -1, "test")
1214
1050
 
1215
- REFRESH;
1216
- _mongocrypt_ctx_fail_w_msg (ctx, "test");
1217
- ASSERT_ENDPOINT_FAILS (RAND, -1, "test")
1218
-
1219
- mongocrypt_ctx_destroy (ctx);
1220
- mongocrypt_destroy (crypt);
1051
+ mongocrypt_ctx_destroy(ctx);
1052
+ mongocrypt_destroy(crypt);
1221
1053
  }
1222
1054
 
1223
- static void
1224
- _test_createdatakey_with_wrong_kms_provider_helper (
1225
- _mongocrypt_tester_t *tester, mongocrypt_binary_t *kms_provider)
1226
- {
1227
- mongocrypt_t *crypt;
1228
- mongocrypt_ctx_t *ctx;
1229
- const char *const kek = "{"
1230
- "'provider': 'azure',"
1231
- "'keyName': 'foo',"
1232
- "'keyVaultEndpoint': 'example.com'"
1233
- "}";
1234
-
1235
- crypt = mongocrypt_new ();
1236
- ASSERT_OK (mongocrypt_setopt_kms_providers (crypt, kms_provider), crypt);
1237
- mongocrypt_setopt_use_need_kms_credentials_state (crypt);
1238
- ASSERT_OK (mongocrypt_init (crypt), crypt);
1239
- ctx = mongocrypt_ctx_new (crypt);
1240
- ASSERT_OK (mongocrypt_ctx_setopt_key_encryption_key (ctx, TEST_BSON (kek)),
1241
- ctx);
1242
- ASSERT_FAILS (mongocrypt_ctx_datakey_init (ctx),
1243
- ctx,
1244
- "kms provider required by datakey is not configured");
1245
-
1246
- mongocrypt_ctx_destroy (ctx);
1247
- mongocrypt_destroy (crypt);
1055
+ static void _test_createdatakey_with_wrong_kms_provider_helper(_mongocrypt_tester_t *tester,
1056
+ mongocrypt_binary_t *kms_provider) {
1057
+ mongocrypt_t *crypt;
1058
+ mongocrypt_ctx_t *ctx;
1059
+ const char *const kek = "{"
1060
+ "'provider': 'azure',"
1061
+ "'keyName': 'foo',"
1062
+ "'keyVaultEndpoint': 'example.com'"
1063
+ "}";
1064
+
1065
+ crypt = mongocrypt_new();
1066
+ ASSERT_OK(mongocrypt_setopt_kms_providers(crypt, kms_provider), crypt);
1067
+ mongocrypt_setopt_use_need_kms_credentials_state(crypt);
1068
+ ASSERT_OK(mongocrypt_init(crypt), crypt);
1069
+ ctx = mongocrypt_ctx_new(crypt);
1070
+ ASSERT_OK(mongocrypt_ctx_setopt_key_encryption_key(ctx, TEST_BSON(kek)), ctx);
1071
+ ASSERT_FAILS(mongocrypt_ctx_datakey_init(ctx), ctx, "kms provider required by datakey is not configured");
1072
+
1073
+ mongocrypt_ctx_destroy(ctx);
1074
+ mongocrypt_destroy(crypt);
1248
1075
  }
1249
1076
 
1250
- static void
1251
- _test_setopt_createdatakey_wrong_kms_provider_configured (
1252
- _mongocrypt_tester_t *tester)
1253
- {
1254
- _test_createdatakey_with_wrong_kms_provider_helper (
1255
- tester, TEST_BSON ("{'gcp': { 'accessToken': '1234' } }"));
1077
+ static void _test_setopt_createdatakey_wrong_kms_provider_configured(_mongocrypt_tester_t *tester) {
1078
+ _test_createdatakey_with_wrong_kms_provider_helper(tester, TEST_BSON("{'gcp': { 'accessToken': '1234' } }"));
1256
1079
  }
1257
1080
 
1258
- static void
1259
- _test_setopt_createdatakey_wrong_kms_provider_empty (
1260
- _mongocrypt_tester_t *tester)
1261
- {
1262
- _test_createdatakey_with_wrong_kms_provider_helper (
1263
- tester, TEST_BSON ("{'gcp': {}}"));
1081
+ static void _test_setopt_createdatakey_wrong_kms_provider_empty(_mongocrypt_tester_t *tester) {
1082
+ _test_createdatakey_with_wrong_kms_provider_helper(tester, TEST_BSON("{'gcp': {}}"));
1264
1083
  }
1265
1084
 
1266
-
1267
- static void
1268
- _test_options (_mongocrypt_tester_t *tester)
1269
- {
1270
- /* Test individual options */
1271
- _test_setopt_masterkey_aws (tester);
1272
- _test_setopt_masterkey_local (tester);
1273
- _test_setopt_key_id (tester);
1274
- _test_setopt_algorithm (tester);
1275
- _test_setopt_key_alt_name (tester);
1276
- _test_setopt_key_material (tester);
1277
- _test_setopt_endpoint (tester);
1278
- _test_setopt_key_encryption_key_azure (tester);
1279
- _test_setopt_key_encryption_key_gcp (tester);
1280
- _test_setopt_query_type (tester);
1281
- _test_setopt_createdatakey_wrong_kms_provider_empty (tester);
1282
- _test_setopt_createdatakey_wrong_kms_provider_configured (tester);
1283
-
1284
- /* Test options on different contexts */
1285
- _test_setopt_for_datakey (tester);
1286
- _test_setopt_for_encrypt (tester);
1287
- _test_setopt_for_explicit_encrypt (tester);
1288
- _test_setopt_for_decrypt (tester);
1289
- _test_setopt_for_explicit_decrypt (tester);
1290
-
1291
- /* Test that failure to set an option on an uninitialized context is returned
1292
- * through mongocrypt_ctx_status */
1293
- _test_setopt_failure_uninitialized (tester);
1085
+ static void _test_options(_mongocrypt_tester_t *tester) {
1086
+ /* Test individual options */
1087
+ _test_setopt_masterkey_aws(tester);
1088
+ _test_setopt_masterkey_local(tester);
1089
+ _test_setopt_key_id(tester);
1090
+ _test_setopt_algorithm(tester);
1091
+ _test_setopt_key_alt_name(tester);
1092
+ _test_setopt_key_material(tester);
1093
+ _test_setopt_endpoint(tester);
1094
+ _test_setopt_key_encryption_key_azure(tester);
1095
+ _test_setopt_key_encryption_key_gcp(tester);
1096
+ _test_setopt_query_type(tester);
1097
+ _test_setopt_createdatakey_wrong_kms_provider_empty(tester);
1098
+ _test_setopt_createdatakey_wrong_kms_provider_configured(tester);
1099
+
1100
+ /* Test options on different contexts */
1101
+ _test_setopt_for_datakey(tester);
1102
+ _test_setopt_for_encrypt(tester);
1103
+ _test_setopt_for_explicit_encrypt(tester);
1104
+ _test_setopt_for_decrypt(tester);
1105
+ _test_setopt_for_explicit_decrypt(tester);
1106
+
1107
+ /* Test that failure to set an option on an uninitialized context is returned
1108
+ * through mongocrypt_ctx_status */
1109
+ _test_setopt_failure_uninitialized(tester);
1294
1110
  }
1295
1111
 
1296
-
1297
- void
1298
- _mongocrypt_tester_install_ctx_setopt (_mongocrypt_tester_t *tester)
1299
- {
1300
- INSTALL_TEST (_test_options);
1112
+ void _mongocrypt_tester_install_ctx_setopt(_mongocrypt_tester_t *tester) {
1113
+ INSTALL_TEST(_test_options);
1301
1114
  }