libmongocrypt-helper 1.8.0.0.1001 → 1.11.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (385) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +33 -0
  3. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +12 -1
  4. data/ext/libmongocrypt/libmongocrypt/CODEOWNERS +1 -4
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +151 -3
  6. data/ext/libmongocrypt/libmongocrypt/README.md +36 -40
  7. data/ext/libmongocrypt/libmongocrypt/bindings/cs/CMakeLists.txt +1 -0
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Driver.snk +0 -0
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/AssemblyInfo.cs +2 -2
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Binary.cs +16 -2
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClientFactory.cs +8 -4
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +10 -0
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/LibraryLoader.cs +81 -44
  14. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/MongoDB.Libmongocrypt.csproj +2 -1
  15. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/MongoDB.Libmongocrypt.Test.csproj +2 -0
  16. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test32/MongoDB.Libmongocrypt.Test32.csproj +2 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/cs/README.md +3 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +21 -26
  19. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.config +3 -0
  20. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.sh +0 -0
  21. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/build.gradle.kts +28 -0
  22. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/java/com/mongodb/crypt/benchmark/BenchmarkRunner.java +217 -0
  23. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/resources/keyDocument.json +24 -0
  24. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +21 -6
  25. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.jar +0 -0
  26. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.properties +1 -1
  27. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew +154 -108
  28. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew.bat +7 -18
  29. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/settings.gradle.kts +1 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPI.java +41 -6
  31. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPIHelper.java +5 -5
  32. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CipherCallback.java +27 -1
  33. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoCryptImpl.java +34 -19
  34. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoExplicitEncryptOptions.java +6 -4
  35. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/jni-config.json +180 -0
  36. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/reflect-config.json +134 -0
  37. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +44 -2
  38. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +1 -1
  39. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/rangeopts.json +3 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +4 -900
  41. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +60 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +41 -20
  43. data/ext/libmongocrypt/libmongocrypt/bindings/python/RELEASE.rst +6 -24
  44. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +4 -13
  45. data/ext/libmongocrypt/libmongocrypt/bindings/python/hatch_build.py +36 -0
  46. data/ext/libmongocrypt/libmongocrypt/bindings/python/libmongocrypt-version.txt +1 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/__init__.py +2 -2
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/auto_encrypter.py +61 -0
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/credentials.py +156 -0
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/explicit_encrypter.py +156 -0
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/state_machine.py +149 -0
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/auto_encrypter.py +2 -46
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binary.py +14 -17
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +107 -61
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +6 -4
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/credentials.py +2 -121
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/crypto.py +31 -20
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/errors.py +2 -2
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +2 -233
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +168 -238
  61. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/options.py +265 -0
  62. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/state_machine.py +2 -141
  63. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/auto_encrypter.py +61 -0
  64. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/credentials.py +156 -0
  65. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/explicit_encrypter.py +156 -0
  66. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/state_machine.py +149 -0
  67. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  68. data/ext/libmongocrypt/libmongocrypt/bindings/python/pyproject.toml +118 -0
  69. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +97 -61
  70. data/ext/libmongocrypt/libmongocrypt/bindings/python/{test-requirements.txt → requirements-test.txt} +4 -1
  71. data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements.txt +4 -0
  72. data/ext/libmongocrypt/libmongocrypt/bindings/python/sbom.json +76 -0
  73. data/ext/libmongocrypt/libmongocrypt/bindings/python/strip_header.py +6 -7
  74. data/ext/libmongocrypt/libmongocrypt/bindings/python/synchro.py +64 -0
  75. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -0
  76. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/collection-info.json +1 -1
  77. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/command.json +1 -1
  78. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/compact/success/encrypted-payload.json +21 -21
  79. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-command-reply.json +1 -1
  80. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-field-config-map.json +1 -1
  81. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +1 -1
  82. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/rangeopts.json +3 -0
  83. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-rangePreview-explicit/int32/rangeopts.json +11 -0
  84. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-rangePreview-explicit/int32/value-to-encrypt.json +20 -0
  85. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-azure.json +1 -1
  86. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-gcp.json +1 -1
  87. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document.json +1 -1
  88. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-filter.json +1 -1
  89. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/list-collections-filter.json +1 -1
  90. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-command.json +1 -1
  91. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-reply.json +1 -1
  92. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/schema-map.json +1 -1
  93. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/keyDocument.json +24 -0
  94. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/perf_test.py +165 -0
  95. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_binding.py +8 -12
  96. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_crypto.py +9 -11
  97. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +988 -340
  98. data/ext/libmongocrypt/libmongocrypt/bindings/python/update-sbom.sh +14 -0
  99. data/ext/libmongocrypt/libmongocrypt/cmake/FetchMongoC.cmake +19 -1
  100. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +23 -0
  101. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +19 -227
  102. data/ext/libmongocrypt/libmongocrypt/cmake/Patch.cmake +54 -0
  103. data/ext/libmongocrypt/libmongocrypt/doc/img/cli-icon.png +0 -0
  104. data/ext/libmongocrypt/libmongocrypt/doc/img/reference-targets.png +0 -0
  105. data/ext/libmongocrypt/libmongocrypt/doc/releasing.md +153 -0
  106. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version.py +61 -28
  107. data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version_selftest.sh +73 -0
  108. data/ext/libmongocrypt/libmongocrypt/etc/cyclonedx.sbom.json +108 -0
  109. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +1 -1
  110. data/ext/libmongocrypt/libmongocrypt/etc/libbson-remove-GCC-diagnostic-pragma.patch +27 -0
  111. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-alpine-arm-fix.patch +17 -0
  112. data/ext/libmongocrypt/libmongocrypt/etc/packager.py +120 -91
  113. data/ext/libmongocrypt/libmongocrypt/etc/purls.txt +14 -0
  114. data/ext/libmongocrypt/libmongocrypt/etc/repo_config.yaml +56 -0
  115. data/ext/libmongocrypt/libmongocrypt/etc/silk-create-asset-group.sh +70 -0
  116. data/ext/libmongocrypt/libmongocrypt/etc/ssdlc_compliance_report.md +37 -0
  117. data/ext/libmongocrypt/libmongocrypt/etc/third_party_vulnerabilities.md +42 -0
  118. data/ext/libmongocrypt/libmongocrypt/integrating.md +18 -1
  119. data/ext/libmongocrypt/libmongocrypt/kms-message/CMakeLists.txt +11 -3
  120. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_gcp_request.c +1 -1
  121. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer.c +17 -0
  122. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer_private.h +6 -0
  123. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_request.c +211 -1
  124. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_response.c +163 -0
  125. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_tag_type_private.h +2 -1
  126. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_request.h +17 -0
  127. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_response.h +6 -0
  128. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_port.c +3 -2
  129. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request.c +4 -2
  130. data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.c +2 -2
  131. data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kmip_reader_writer.c +23 -2
  132. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +13 -10
  133. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +1 -1
  134. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +16 -2
  135. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +94 -6
  136. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +15 -5
  137. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +114 -53
  138. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +1 -1
  139. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +1 -1
  140. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +2 -2
  141. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +2 -2
  142. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +21 -6
  143. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +5 -5
  144. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +38 -2
  145. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +1 -1
  146. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +20 -7
  147. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +8 -8
  148. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +89 -1
  149. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +3 -3
  150. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +1 -23
  151. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +4 -3
  152. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +15 -12
  153. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +11 -0
  154. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +16 -6
  155. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +64 -22
  156. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +23 -4
  157. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +359 -65
  158. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +26 -14
  159. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +17 -6
  160. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +31 -13
  161. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +16 -3
  162. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +259 -63
  163. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +40 -24
  164. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +57 -13
  165. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +17 -0
  166. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +5 -0
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +0 -5
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +5 -7
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +1 -0
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +16 -18
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +105 -76
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +9 -3
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +170 -89
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +5 -5
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +505 -124
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +31 -6
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +81 -13
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +7 -0
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +5 -1
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +161 -103
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +2 -7
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +191 -69
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +1 -1
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +50 -15
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +365 -69
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +2 -1
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +200 -107
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +50 -5
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +591 -15
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +6 -13
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +3 -2
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +47 -234
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +75 -24
  194. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +18 -2
  195. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +4 -0
  196. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/bypassQueryAnalysis/payload.json +53 -0
  197. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd-to-mongocryptd.json +23 -0
  198. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd.json +20 -0
  199. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd-to-mongocryptd.json +50 -0
  200. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd.json +20 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/collinfo.json +44 -0
  202. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-field-map.json +24 -0
  203. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-payload-pattern.json +53 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/mongocryptd-reply.json +62 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd-to-mongocryptd.json +30 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd.json +17 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/mongocryptd-reply.json +39 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/payload.json +21 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/missing-key-id/collinfo.json +20 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/collinfo.json +9 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/encrypted-payload.json +4 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/cmd.json +1 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/collinfo.json +63 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-field-config-map.json +61 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload-range-v2.json +37 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload.json +29 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/cmd.json +1 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/collinfo.json +64 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload-range-v2.json +105 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload.json +30 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/cmd.json +1 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/collinfo.json +49 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-field-config-map.json +47 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-payload.json +23 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/collinfo.json +15 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-field-config-map.json +10 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload-range-v2.json +104 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload.json +6 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/collinfo.json +4 -4
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +3 -3
  231. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/decrypt-response.txt +16 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/encrypt-response.txt +16 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/oauth-response.txt +19 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/cmd.json +9 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-field-map.json +19 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-payload.json +62 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/mongocryptd-reply.json +69 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/cmd.json +11 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-field-map.json +19 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-payload.json +40 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/mongocryptd-reply.json +47 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_decimal128.cstruct +1 -1
  243. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_double.cstruct +8637 -7958
  244. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int32.cstruct +5522 -1382
  245. data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int64.cstruct +5042 -1262
  246. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128.cstruct +1 -1
  247. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128_precision.cstruct +1 -1
  248. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double.cstruct +1 -1
  249. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double_precision.cstruct +2 -2
  250. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int32.cstruct +1 -1
  251. data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int64.cstruct +1 -1
  252. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/cmd.json +8 -0
  253. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-field-map.json +19 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-payload.json +53 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/mongocryptd-reply.json +58 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/cmd.json +11 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-field-map.json +19 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-payload.json +40 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/mongocryptd-reply.json +45 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/expected.json +26 -0
  261. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/to-encrypt.json +20 -0
  262. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/expected.json +26 -0
  263. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/to-encrypt.json +20 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-double/expected.json +8 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32/expected.json +8 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32-defaults/expected.json +8 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +7 -4
  268. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +9 -5
  269. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +9 -5
  270. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +1 -0
  271. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +8 -8
  272. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +6 -4
  273. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +43 -3
  274. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +76 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +5 -5
  276. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +89 -14
  277. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +342 -76
  278. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +94 -12
  279. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +205 -7
  280. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +49 -23
  281. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +16 -19
  282. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +22 -1
  283. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +94 -11
  284. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cleanup.c +374 -0
  285. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +121 -42
  286. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +134 -4
  287. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +40 -0
  288. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +16 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +11 -11
  290. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +8 -5
  291. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +922 -92
  292. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +2 -2
  293. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +114 -12
  294. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +14 -9
  295. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +424 -3
  296. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +1 -1
  297. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +447 -28
  298. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-opts.c +42 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +30 -26
  300. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +7 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +3 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +66 -14
  303. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +11 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/test-named-kms-providers.c +2381 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/util/HELP.autogen +3 -1
  306. data/ext/libmongocrypt/libmongocrypt/test/util/README.md +1 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +4 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/util/make_includes.py +1 -1
  309. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +38 -3
  310. data/lib/libmongocrypt_helper/version.rb +2 -2
  311. metadata +112 -106
  312. checksums.yaml.gz.sig +0 -0
  313. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +0 -1
  314. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +0 -79
  315. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +0 -105
  316. data/ext/libmongocrypt/libmongocrypt/bindings/node/LICENSE +0 -201
  317. data/ext/libmongocrypt/libmongocrypt/bindings/node/binding.gyp +0 -79
  318. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/README.hbs +0 -44
  319. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +0 -36
  320. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +0 -641
  321. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +0 -420
  322. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/buffer_pool.js +0 -123
  323. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +0 -821
  324. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +0 -98
  325. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/cryptoCallbacks.js +0 -87
  326. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +0 -75
  327. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +0 -73
  328. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js +0 -66
  329. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +0 -26
  330. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +0 -178
  331. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +0 -24
  332. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +0 -54
  333. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +0 -39
  334. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +0 -492
  335. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +0 -15302
  336. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +0 -100
  337. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +0 -956
  338. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.h +0 -114
  339. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +0 -950
  340. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/buffer_pool.test.js +0 -91
  341. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +0 -1093
  342. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +0 -94
  343. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +0 -240
  344. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/README.md +0 -5
  345. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/cmd.json +0 -6
  346. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/collection-info.json +0 -37
  347. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document-nested.json +0 -8
  348. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document.json +0 -11
  349. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encryptedFields.json +0 -30
  350. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key-document.json +0 -32
  351. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key1-document.json +0 -30
  352. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/mongocryptd-reply.json +0 -18
  353. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +0 -45
  354. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +0 -48
  355. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +0 -551
  356. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +0 -66
  357. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +0 -51
  358. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +0 -331
  359. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +0 -8
  360. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/mongodb_reporter.js +0 -325
  361. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +0 -63
  362. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +0 -89
  363. data/ext/libmongocrypt/libmongocrypt/debian/build_snapshot.sh +0 -79
  364. data/ext/libmongocrypt/libmongocrypt/debian/changelog +0 -105
  365. data/ext/libmongocrypt/libmongocrypt/debian/compat +0 -1
  366. data/ext/libmongocrypt/libmongocrypt/debian/control +0 -41
  367. data/ext/libmongocrypt/libmongocrypt/debian/copyright +0 -129
  368. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +0 -23
  369. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.dirs +0 -2
  370. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.install +0 -5
  371. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.dirs +0 -1
  372. data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.install +0 -1
  373. data/ext/libmongocrypt/libmongocrypt/debian/rules +0 -46
  374. data/ext/libmongocrypt/libmongocrypt/debian/source/format +0 -1
  375. data/ext/libmongocrypt/libmongocrypt/debian/source/lintian-overrides +0 -3
  376. data/ext/libmongocrypt/libmongocrypt/debian/source/options +0 -1
  377. data/ext/libmongocrypt/libmongocrypt/debian/watch +0 -3
  378. data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/mongocryptd-reply.json +0 -72
  379. data.tar.gz.sig +0 -1
  380. metadata.gz.sig +0 -0
  381. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-decrypt-reply.txt → test/data/kms-aws/decrypt-response.txt} +0 -0
  382. /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-encrypt-reply.txt → test/data/kms-aws/encrypt-response.txt} +0 -0
  383. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/decrypt-response.txt +0 -0
  384. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/encrypt-response.txt +0 -0
  385. /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/oauth-response.txt +0 -0
@@ -1,821 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = function (modules) {
4
- const mc = require('bindings')('mongocrypt');
5
- const common = require('./common');
6
- const databaseNamespace = common.databaseNamespace;
7
- const collectionNamespace = common.collectionNamespace;
8
- const promiseOrCallback = common.promiseOrCallback;
9
- const maybeCallback = common.maybeCallback;
10
- const StateMachine = modules.stateMachine.StateMachine;
11
- const BSON = modules.mongodb.BSON;
12
- const {
13
- MongoCryptCreateEncryptedCollectionError,
14
- MongoCryptCreateDataKeyError
15
- } = require('./errors');
16
- const { loadCredentials } = require('./providers/index');
17
- const cryptoCallbacks = require('./cryptoCallbacks');
18
- const { promisify } = require('util');
19
-
20
- /** @typedef {*} BSONValue - any serializable BSON value */
21
- /** @typedef {BSON.Long} Long A 64 bit integer, represented by the js-bson Long type.*/
22
-
23
- /**
24
- * @typedef {object} KMSProviders Configuration options that are used by specific KMS providers during key generation, encryption, and decryption.
25
- * @property {object} [aws] Configuration options for using 'aws' as your KMS provider
26
- * @property {string} [aws.accessKeyId] The access key used for the AWS KMS provider
27
- * @property {string} [aws.secretAccessKey] The secret access key used for the AWS KMS provider
28
- * @property {object} [local] Configuration options for using 'local' as your KMS provider
29
- * @property {Buffer} [local.key] The master key used to encrypt/decrypt data keys. A 96-byte long Buffer.
30
- * @property {object} [azure] Configuration options for using 'azure' as your KMS provider
31
- * @property {string} [azure.tenantId] The tenant ID identifies the organization for the account
32
- * @property {string} [azure.clientId] The client ID to authenticate a registered application
33
- * @property {string} [azure.clientSecret] The client secret to authenticate a registered application
34
- * @property {string} [azure.identityPlatformEndpoint] If present, a host with optional port. E.g. "example.com" or "example.com:443". This is optional, and only needed if customer is using a non-commercial Azure instance (e.g. a government or China account, which use different URLs). Defaults to "login.microsoftonline.com"
35
- * @property {object} [gcp] Configuration options for using 'gcp' as your KMS provider
36
- * @property {string} [gcp.email] The service account email to authenticate
37
- * @property {string|Binary} [gcp.privateKey] A PKCS#8 encrypted key. This can either be a base64 string or a binary representation
38
- * @property {string} [gcp.endpoint] If present, a host with optional port. E.g. "example.com" or "example.com:443". Defaults to "oauth2.googleapis.com"
39
- */
40
-
41
- /**
42
- * @typedef {object} DataKey A data key as stored in the database.
43
- * @property {UUID} _id A unique identifier for the key.
44
- * @property {number} version A numeric identifier for the schema version of this document. Implicitly 0 if unset.
45
- * @property {string[]} [keyAltNames] Alternate names to search for keys by. Used for a per-document key scenario in support of GDPR scenarios.
46
- * @property {Binary} keyMaterial Encrypted data key material, BinData type General.
47
- * @property {Date} creationDate The datetime the wrapped data key material was imported into the Key Database.
48
- * @property {Date} updateDate The datetime the wrapped data key material was last modified. On initial import, this value will be set to creationDate.
49
- * @property {number} status 0 = enabled, 1 = disabled
50
- * @property {object} masterKey the encrypted master key
51
- */
52
-
53
- /**
54
- * @typedef {string} KmsProvider A string containing the name of a kms provider. Valid options are 'aws', 'azure', 'gcp', 'kmip', or 'local'
55
- */
56
-
57
- /**
58
- * @typedef {object} ClientSession The ClientSession class from the MongoDB Node driver (see https://mongodb.github.io/node-mongodb-native/4.8/classes/ClientSession.html)
59
- */
60
-
61
- /**
62
- * @typedef {object} DeleteResult The result of a delete operation from the MongoDB Node driver (see https://mongodb.github.io/node-mongodb-native/4.8/interfaces/DeleteResult.html)
63
- * @property {boolean} acknowledged Indicates whether this write result was acknowledged. If not, then all other members of this result will be undefined.
64
- * @property {number} deletedCount The number of documents that were deleted
65
- */
66
-
67
- /**
68
- * @typedef {object} BulkWriteResult The BulkWriteResult class from the MongoDB Node driver (https://mongodb.github.io/node-mongodb-native/4.8/classes/BulkWriteResult.html)
69
- */
70
-
71
- /**
72
- * @typedef {object} FindCursor The FindCursor class from the MongoDB Node driver (see https://mongodb.github.io/node-mongodb-native/4.8/classes/FindCursor.html)
73
- */
74
-
75
- /**
76
- * The public interface for explicit in-use encryption
77
- */
78
- class ClientEncryption {
79
- /**
80
- * Create a new encryption instance
81
- *
82
- * @param {MongoClient} client The client used for encryption
83
- * @param {object} options Additional settings
84
- * @param {string} options.keyVaultNamespace The namespace of the key vault, used to store encryption keys
85
- * @param {object} options.tlsOptions An object that maps KMS provider names to TLS options.
86
- * @param {MongoClient} [options.keyVaultClient] A `MongoClient` used to fetch keys from a key vault. Defaults to `client`
87
- * @param {KMSProviders} [options.kmsProviders] options for specific KMS providers to use
88
- *
89
- * @example
90
- * new ClientEncryption(mongoClient, {
91
- * keyVaultNamespace: 'client.encryption',
92
- * kmsProviders: {
93
- * local: {
94
- * key: masterKey // The master key used for encryption/decryption. A 96-byte long Buffer
95
- * }
96
- * }
97
- * });
98
- *
99
- * @example
100
- * new ClientEncryption(mongoClient, {
101
- * keyVaultNamespace: 'client.encryption',
102
- * kmsProviders: {
103
- * aws: {
104
- * accessKeyId: AWS_ACCESS_KEY,
105
- * secretAccessKey: AWS_SECRET_KEY
106
- * }
107
- * }
108
- * });
109
- */
110
- constructor(client, options) {
111
- this._client = client;
112
- this._bson = options.bson || BSON || client.topology.bson;
113
- this._proxyOptions = options.proxyOptions;
114
- this._tlsOptions = options.tlsOptions;
115
- this._kmsProviders = options.kmsProviders || {};
116
-
117
- if (options.keyVaultNamespace == null) {
118
- throw new TypeError('Missing required option `keyVaultNamespace`');
119
- }
120
-
121
- const mongoCryptOptions = { ...options, cryptoCallbacks };
122
-
123
- mongoCryptOptions.kmsProviders = !Buffer.isBuffer(this._kmsProviders)
124
- ? this._bson.serialize(this._kmsProviders)
125
- : this._kmsProviders;
126
-
127
- this._onKmsProviderRefresh = options.onKmsProviderRefresh;
128
- this._keyVaultNamespace = options.keyVaultNamespace;
129
- this._keyVaultClient = options.keyVaultClient || client;
130
- this._mongoCrypt = new mc.MongoCrypt(mongoCryptOptions);
131
- }
132
-
133
- /**
134
- * @typedef {Binary} ClientEncryptionDataKeyId
135
- * The id of an existing dataKey. Is a bson Binary value.
136
- * Can be used for {@link ClientEncryption.encrypt}, and can be used to directly
137
- * query for the data key itself against the key vault namespace.
138
- */
139
-
140
- /**
141
- * @callback ClientEncryptionCreateDataKeyCallback
142
- * @param {Error} [error] If present, indicates an error that occurred in the creation of the data key
143
- * @param {ClientEncryption~dataKeyId} [dataKeyId] If present, returns the id of the created data key
144
- */
145
-
146
- /**
147
- * @typedef {object} AWSEncryptionKeyOptions Configuration options for making an AWS encryption key
148
- * @property {string} region The AWS region of the KMS
149
- * @property {string} key The Amazon Resource Name (ARN) to the AWS customer master key (CMK)
150
- * @property {string} [endpoint] An alternate host to send KMS requests to. May include port number
151
- */
152
-
153
- /**
154
- * @typedef {object} GCPEncryptionKeyOptions Configuration options for making a GCP encryption key
155
- * @property {string} projectId GCP project id
156
- * @property {string} location Location name (e.g. "global")
157
- * @property {string} keyRing Key ring name
158
- * @property {string} keyName Key name
159
- * @property {string} [keyVersion] Key version
160
- * @property {string} [endpoint] KMS URL, defaults to `https://www.googleapis.com/auth/cloudkms`
161
- */
162
-
163
- /**
164
- * @typedef {object} AzureEncryptionKeyOptions Configuration options for making an Azure encryption key
165
- * @property {string} keyName Key name
166
- * @property {string} keyVaultEndpoint Key vault URL, typically `<name>.vault.azure.net`
167
- * @property {string} [keyVersion] Key version
168
- */
169
-
170
- /**
171
- * Creates a data key used for explicit encryption and inserts it into the key vault namespace
172
- *
173
- * @param {string} provider The KMS provider used for this data key. Must be `'aws'`, `'azure'`, `'gcp'`, or `'local'`
174
- * @param {object} [options] Options for creating the data key
175
- * @param {AWSEncryptionKeyOptions|AzureEncryptionKeyOptions|GCPEncryptionKeyOptions} [options.masterKey] Idenfities a new KMS-specific key used to encrypt the new data key
176
- * @param {string[]} [options.keyAltNames] An optional list of string alternate names used to reference a key. If a key is created with alternate names, then encryption may refer to the key by the unique alternate name instead of by _id.
177
- * @param {ClientEncryptionCreateDataKeyCallback} [callback] Optional callback to invoke when key is created
178
- * @returns {Promise|void} If no callback is provided, returns a Promise that either resolves with {@link ClientEncryption~dataKeyId the id of the created data key}, or rejects with an error. If a callback is provided, returns nothing.
179
- * @example
180
- * // Using callbacks to create a local key
181
- * clientEncryption.createDataKey('local', (err, dataKey) => {
182
- * if (err) {
183
- * // This means creating the key failed.
184
- * } else {
185
- * // key creation succeeded
186
- * }
187
- * });
188
- *
189
- * @example
190
- * // Using async/await to create a local key
191
- * const dataKeyId = await clientEncryption.createDataKey('local');
192
- *
193
- * @example
194
- * // Using async/await to create an aws key
195
- * const dataKeyId = await clientEncryption.createDataKey('aws', {
196
- * masterKey: {
197
- * region: 'us-east-1',
198
- * key: 'xxxxxxxxxxxxxx' // CMK ARN here
199
- * }
200
- * });
201
- *
202
- * @example
203
- * // Using async/await to create an aws key with a keyAltName
204
- * const dataKeyId = await clientEncryption.createDataKey('aws', {
205
- * masterKey: {
206
- * region: 'us-east-1',
207
- * key: 'xxxxxxxxxxxxxx' // CMK ARN here
208
- * },
209
- * keyAltNames: [ 'mySpecialKey' ]
210
- * });
211
- */
212
- createDataKey(provider, options, callback) {
213
- if (typeof options === 'function') {
214
- callback = options;
215
- options = {};
216
- }
217
- if (options == null) {
218
- options = {};
219
- }
220
-
221
- const bson = this._bson;
222
-
223
- const dataKey = Object.assign({ provider }, options.masterKey);
224
-
225
- if (options.keyAltNames && !Array.isArray(options.keyAltNames)) {
226
- throw new TypeError(
227
- `Option "keyAltNames" must be an array of strings, but was of type ${typeof options.keyAltNames}.`
228
- );
229
- }
230
-
231
- let keyAltNames = undefined;
232
- if (options.keyAltNames && options.keyAltNames.length > 0) {
233
- keyAltNames = options.keyAltNames.map((keyAltName, i) => {
234
- if (typeof keyAltName !== 'string') {
235
- throw new TypeError(
236
- `Option "keyAltNames" must be an array of strings, but item at index ${i} was of type ${typeof keyAltName}`
237
- );
238
- }
239
-
240
- return bson.serialize({ keyAltName });
241
- });
242
- }
243
-
244
- let keyMaterial = undefined;
245
- if (options.keyMaterial) {
246
- keyMaterial = bson.serialize({ keyMaterial: options.keyMaterial });
247
- }
248
-
249
- const dataKeyBson = bson.serialize(dataKey);
250
- const context = this._mongoCrypt.makeDataKeyContext(dataKeyBson, {
251
- keyAltNames,
252
- keyMaterial
253
- });
254
- const stateMachine = new StateMachine({
255
- bson,
256
- proxyOptions: this._proxyOptions,
257
- tlsOptions: this._tlsOptions
258
- });
259
-
260
- return promiseOrCallback(callback, cb => {
261
- stateMachine.execute(this, context, (err, dataKey) => {
262
- if (err) {
263
- cb(err, null);
264
- return;
265
- }
266
-
267
- const dbName = databaseNamespace(this._keyVaultNamespace);
268
- const collectionName = collectionNamespace(this._keyVaultNamespace);
269
-
270
- this._keyVaultClient
271
- .db(dbName)
272
- .collection(collectionName)
273
- .insertOne(dataKey, { writeConcern: { w: 'majority' } })
274
- .then(
275
- result => {
276
- return cb(null, result.insertedId);
277
- },
278
- err => {
279
- cb(err, null);
280
- }
281
- );
282
- });
283
- });
284
- }
285
-
286
- /**
287
- * @typedef {object} RewrapManyDataKeyResult
288
- * @property {BulkWriteResult} [bulkWriteResult] An optional BulkWriteResult, if any keys were matched and attempted to be re-wrapped.
289
- */
290
-
291
- /**
292
- * Searches the keyvault for any data keys matching the provided filter. If there are matches, rewrapManyDataKey then attempts to re-wrap the data keys using the provided options.
293
- *
294
- * If no matches are found, then no bulk write is performed.
295
- *
296
- * @param {object} filter A valid MongoDB filter. Any documents matching this filter will be re-wrapped.
297
- * @param {object} [options]
298
- * @param {KmsProvider} options.provider The KMS provider to use when re-wrapping the data keys.
299
- * @param {AWSEncryptionKeyOptions | AzureEncryptionKeyOptions | GCPEncryptionKeyOptions} [options.masterKey]
300
- * @returns {Promise<RewrapManyDataKeyResult>}
301
- *
302
- * @example
303
- * // rewrapping all data data keys (using a filter that matches all documents)
304
- * const filter = {};
305
- *
306
- * const result = await clientEncryption.rewrapManyDataKey(filter);
307
- * if (result.bulkWriteResult != null) {
308
- * // keys were re-wrapped, results will be available in the bulkWrite object.
309
- * }
310
- *
311
- * @example
312
- * // attempting to rewrap all data keys with no matches
313
- * const filter = { _id: new Binary() } // assume _id matches no documents in the database
314
- * const result = await clientEncryption.rewrapManyDataKey(filter);
315
- *
316
- * if (result.bulkWriteResult == null) {
317
- * // no keys matched, `bulkWriteResult` does not exist on the result object
318
- * }
319
- */
320
- async rewrapManyDataKey(filter, options) {
321
- const bson = this._bson;
322
-
323
- let keyEncryptionKeyBson = undefined;
324
- if (options) {
325
- const keyEncryptionKey = Object.assign({ provider: options.provider }, options.masterKey);
326
- keyEncryptionKeyBson = bson.serialize(keyEncryptionKey);
327
- } else {
328
- // Always make sure `options` is an object below.
329
- options = {};
330
- }
331
- const filterBson = bson.serialize(filter);
332
- const context = this._mongoCrypt.makeRewrapManyDataKeyContext(
333
- filterBson,
334
- keyEncryptionKeyBson
335
- );
336
- const stateMachine = new StateMachine({
337
- bson,
338
- proxyOptions: this._proxyOptions,
339
- tlsOptions: this._tlsOptions
340
- });
341
-
342
- const execute = promisify(stateMachine.execute.bind(stateMachine));
343
-
344
- const dataKey = await execute(this, context);
345
- if (!dataKey || dataKey.v.length === 0) {
346
- return {};
347
- }
348
-
349
- const dbName = databaseNamespace(this._keyVaultNamespace);
350
- const collectionName = collectionNamespace(this._keyVaultNamespace);
351
- const replacements = dataKey.v.map(key => ({
352
- updateOne: {
353
- filter: { _id: key._id },
354
- update: {
355
- $set: {
356
- masterKey: key.masterKey,
357
- keyMaterial: key.keyMaterial
358
- },
359
- $currentDate: {
360
- updateDate: true
361
- }
362
- }
363
- }
364
- }));
365
-
366
- const result = await this._keyVaultClient
367
- .db(dbName)
368
- .collection(collectionName)
369
- .bulkWrite(replacements, {
370
- writeConcern: { w: 'majority' }
371
- });
372
-
373
- return { bulkWriteResult: result };
374
- }
375
-
376
- /**
377
- * Deletes the key with the provided id from the keyvault, if it exists.
378
- *
379
- * @param {ClientEncryptionDataKeyId} _id - the id of the document to delete.
380
- * @returns {Promise<DeleteResult>} Returns a promise that either resolves to a {@link DeleteResult} or rejects with an error.
381
- *
382
- * @example
383
- * // delete a key by _id
384
- * const id = new Binary(); // id is a bson binary subtype 4 object
385
- * const { deletedCount } = await clientEncryption.deleteKey(id);
386
- *
387
- * if (deletedCount != null && deletedCount > 0) {
388
- * // successful deletion
389
- * }
390
- *
391
- */
392
- async deleteKey(_id) {
393
- const dbName = databaseNamespace(this._keyVaultNamespace);
394
- const collectionName = collectionNamespace(this._keyVaultNamespace);
395
- return await this._keyVaultClient
396
- .db(dbName)
397
- .collection(collectionName)
398
- .deleteOne({ _id }, { writeConcern: { w: 'majority' } });
399
- }
400
-
401
- /**
402
- * Finds all the keys currently stored in the keyvault.
403
- *
404
- * This method will not throw.
405
- *
406
- * @returns {FindCursor} a FindCursor over all keys in the keyvault.
407
- * @example
408
- * // fetching all keys
409
- * const keys = await clientEncryption.getKeys().toArray();
410
- */
411
- getKeys() {
412
- const dbName = databaseNamespace(this._keyVaultNamespace);
413
- const collectionName = collectionNamespace(this._keyVaultNamespace);
414
- return this._keyVaultClient
415
- .db(dbName)
416
- .collection(collectionName)
417
- .find({}, { readConcern: { level: 'majority' } });
418
- }
419
-
420
- /**
421
- * Finds a key in the keyvault with the specified _id.
422
- *
423
- * @param {ClientEncryptionDataKeyId} _id - the id of the document to delete.
424
- * @returns {Promise<DataKey>} Returns a promise that either resolves to a {@link DataKey} if a document matches the key or null if no documents
425
- * match the id. The promise rejects with an error if an error is thrown.
426
- * @example
427
- * // getting a key by id
428
- * const id = new Binary(); // id is a bson binary subtype 4 object
429
- * const key = await clientEncryption.getKey(id);
430
- * if (!key) {
431
- * // key is null if there was no matching key
432
- * }
433
- */
434
- async getKey(_id) {
435
- const dbName = databaseNamespace(this._keyVaultNamespace);
436
- const collectionName = collectionNamespace(this._keyVaultNamespace);
437
- return await this._keyVaultClient
438
- .db(dbName)
439
- .collection(collectionName)
440
- .findOne({ _id }, { readConcern: { level: 'majority' } });
441
- }
442
-
443
- /**
444
- * Finds a key in the keyvault which has the specified keyAltName.
445
- *
446
- * @param {string} keyAltName - a keyAltName to search for a key
447
- * @returns {Promise<DataKey | null>} Returns a promise that either resolves to a {@link DataKey} if a document matches the key or null if no documents
448
- * match the keyAltName. The promise rejects with an error if an error is thrown.
449
- * @example
450
- * // get a key by alt name
451
- * const keyAltName = 'keyAltName';
452
- * const key = await clientEncryption.getKeyByAltName(keyAltName);
453
- * if (!key) {
454
- * // key is null if there is no matching key
455
- * }
456
- */
457
- async getKeyByAltName(keyAltName) {
458
- const dbName = databaseNamespace(this._keyVaultNamespace);
459
- const collectionName = collectionNamespace(this._keyVaultNamespace);
460
- return await this._keyVaultClient
461
- .db(dbName)
462
- .collection(collectionName)
463
- .findOne({ keyAltNames: keyAltName }, { readConcern: { level: 'majority' } });
464
- }
465
-
466
- /**
467
- * Adds a keyAltName to a key identified by the provided _id.
468
- *
469
- * This method resolves to/returns the *old* key value (prior to adding the new altKeyName).
470
- *
471
- * @param {ClientEncryptionDataKeyId} _id The id of the document to update.
472
- * @param {string} keyAltName - a keyAltName to search for a key
473
- * @returns {Promise<DataKey>} Returns a promise that either resolves to a {@link DataKey} if a document matches the key or null if no documents
474
- * match the id. The promise rejects with an error if an error is thrown.
475
- * @example
476
- * // adding an keyAltName to a data key
477
- * const id = new Binary(); // id is a bson binary subtype 4 object
478
- * const keyAltName = 'keyAltName';
479
- * const oldKey = await clientEncryption.addKeyAltName(id, keyAltName);
480
- * if (!oldKey) {
481
- * // null is returned if there is no matching document with an id matching the supplied id
482
- * }
483
- */
484
- async addKeyAltName(_id, keyAltName) {
485
- const dbName = databaseNamespace(this._keyVaultNamespace);
486
- const collectionName = collectionNamespace(this._keyVaultNamespace);
487
- const { value } = await this._keyVaultClient
488
- .db(dbName)
489
- .collection(collectionName)
490
- .findOneAndUpdate(
491
- { _id },
492
- { $addToSet: { keyAltNames: keyAltName } },
493
- { writeConcern: { w: 'majority' }, returnDocument: 'before' }
494
- );
495
-
496
- return value;
497
- }
498
-
499
- /**
500
- * Adds a keyAltName to a key identified by the provided _id.
501
- *
502
- * This method resolves to/returns the *old* key value (prior to removing the new altKeyName).
503
- *
504
- * If the removed keyAltName is the last keyAltName for that key, the `altKeyNames` property is unset from the document.
505
- *
506
- * @param {ClientEncryptionDataKeyId} _id The id of the document to update.
507
- * @param {string} keyAltName - a keyAltName to search for a key
508
- * @returns {Promise<DataKey | null>} Returns a promise that either resolves to a {@link DataKey} if a document matches the key or null if no documents
509
- * match the id. The promise rejects with an error if an error is thrown.
510
- * @example
511
- * // removing a key alt name from a data key
512
- * const id = new Binary(); // id is a bson binary subtype 4 object
513
- * const keyAltName = 'keyAltName';
514
- * const oldKey = await clientEncryption.removeKeyAltName(id, keyAltName);
515
- *
516
- * if (!oldKey) {
517
- * // null is returned if there is no matching document with an id matching the supplied id
518
- * }
519
- */
520
- async removeKeyAltName(_id, keyAltName) {
521
- const dbName = databaseNamespace(this._keyVaultNamespace);
522
- const collectionName = collectionNamespace(this._keyVaultNamespace);
523
- const pipeline = [
524
- {
525
- $set: {
526
- keyAltNames: {
527
- $cond: [
528
- {
529
- $eq: ['$keyAltNames', [keyAltName]]
530
- },
531
- '$$REMOVE',
532
- {
533
- $filter: {
534
- input: '$keyAltNames',
535
- cond: {
536
- $ne: ['$$this', keyAltName]
537
- }
538
- }
539
- }
540
- ]
541
- }
542
- }
543
- }
544
- ];
545
- const { value } = await this._keyVaultClient
546
- .db(dbName)
547
- .collection(collectionName)
548
- .findOneAndUpdate({ _id }, pipeline, {
549
- writeConcern: { w: 'majority' },
550
- returnDocument: 'before'
551
- });
552
-
553
- return value;
554
- }
555
-
556
- /**
557
- * @experimental Public Technical Preview
558
- *
559
- * A convenience method for creating an encrypted collection.
560
- * This method will create data keys for any encryptedFields that do not have a `keyId` defined
561
- * and then create a new collection with the full set of encryptedFields.
562
- *
563
- * @template {TSchema} - Schema for the collection being created
564
- * @param {Db} db - A Node.js driver Db object with which to create the collection
565
- * @param {string} name - The name of the collection to be created
566
- * @param {object} options - Options for createDataKey and for createCollection
567
- * @param {string} options.provider - KMS provider name
568
- * @param {AWSEncryptionKeyOptions | AzureEncryptionKeyOptions | GCPEncryptionKeyOptions} [options.masterKey] - masterKey to pass to createDataKey
569
- * @param {CreateCollectionOptions} options.createCollectionOptions - options to pass to createCollection, must include `encryptedFields`
570
- * @returns {Promise<{ collection: Collection<TSchema>, encryptedFields: Document }>} - created collection and generated encryptedFields
571
- * @throws {MongoCryptCreateDataKeyError} - If part way through the process a createDataKey invocation fails, an error will be rejected that has the partial `encryptedFields` that were created.
572
- * @throws {MongoCryptCreateEncryptedCollectionError} - If creating the collection fails, an error will be rejected that has the entire `encryptedFields` that were created.
573
- */
574
- async createEncryptedCollection(db, name, options) {
575
- const {
576
- provider,
577
- masterKey,
578
- createCollectionOptions: {
579
- encryptedFields: { ...encryptedFields },
580
- ...createCollectionOptions
581
- }
582
- } = options;
583
-
584
- if (Array.isArray(encryptedFields.fields)) {
585
- const createDataKeyPromises = encryptedFields.fields.map(async field =>
586
- field == null || typeof field !== 'object' || field.keyId != null
587
- ? field
588
- : {
589
- ...field,
590
- keyId: await this.createDataKey(provider, { masterKey })
591
- }
592
- );
593
-
594
- const createDataKeyResolutions = await Promise.allSettled(createDataKeyPromises);
595
-
596
- encryptedFields.fields = createDataKeyResolutions.map((resolution, index) =>
597
- resolution.status === 'fulfilled' ? resolution.value : encryptedFields.fields[index]
598
- );
599
-
600
- const rejection = createDataKeyResolutions.find(({ status }) => status === 'rejected');
601
- if (rejection != null) {
602
- throw new MongoCryptCreateDataKeyError({ encryptedFields, cause: rejection.reason });
603
- }
604
- }
605
-
606
- try {
607
- const collection = await db.createCollection(name, {
608
- ...createCollectionOptions,
609
- encryptedFields
610
- });
611
- return { collection, encryptedFields };
612
- } catch (cause) {
613
- throw new MongoCryptCreateEncryptedCollectionError({ encryptedFields, cause });
614
- }
615
- }
616
-
617
- /**
618
- * @callback ClientEncryptionEncryptCallback
619
- * @param {Error} [err] If present, indicates an error that occurred in the process of encryption
620
- * @param {Buffer} [result] If present, is the encrypted result
621
- */
622
-
623
- /**
624
- * @typedef {object} RangeOptions
625
- * min, max, sparsity, and range must match the values set in the encryptedFields of the destination collection.
626
- * For double and decimal128, min/max/precision must all be set, or all be unset.
627
- * @property {BSONValue} min is required if precision is set.
628
- * @property {BSONValue} max is required if precision is set.
629
- * @property {BSON.Long} sparsity
630
- * @property {number | undefined} precision (may only be set for double or decimal128).
631
- */
632
-
633
- /**
634
- * @typedef {object} EncryptOptions Options to provide when encrypting data.
635
- * @property {ClientEncryptionDataKeyId} [keyId] The id of the Binary dataKey to use for encryption.
636
- * @property {string} [keyAltName] A unique string name corresponding to an already existing dataKey.
637
- * @property {string} [algorithm] The algorithm to use for encryption. Must be either `'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic'`, `'AEAD_AES_256_CBC_HMAC_SHA_512-Random'`, `'Indexed'` or `'Unindexed'`
638
- * @property {bigint | number} [contentionFactor] (experimental) - the contention factor.
639
- * @property {'equality' | 'rangePreview'} queryType (experimental) - the query type supported.
640
- * @property {RangeOptions} [rangeOptions] (experimental) The index options for a Queryable Encryption field supporting "rangePreview" queries.
641
- */
642
-
643
- /**
644
- * Explicitly encrypt a provided value. Note that either `options.keyId` or `options.keyAltName` must
645
- * be specified. Specifying both `options.keyId` and `options.keyAltName` is considered an error.
646
- *
647
- * @param {*} value The value that you wish to serialize. Must be of a type that can be serialized into BSON
648
- * @param {EncryptOptions} options
649
- * @param {ClientEncryptionEncryptCallback} [callback] Optional callback to invoke when value is encrypted
650
- * @returns {Promise|void} If no callback is provided, returns a Promise that either resolves with the encrypted value, or rejects with an error. If a callback is provided, returns nothing.
651
- *
652
- * @example
653
- * // Encryption with callback API
654
- * function encryptMyData(value, callback) {
655
- * clientEncryption.createDataKey('local', (err, keyId) => {
656
- * if (err) {
657
- * return callback(err);
658
- * }
659
- * clientEncryption.encrypt(value, { keyId, algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' }, callback);
660
- * });
661
- * }
662
- *
663
- * @example
664
- * // Encryption with async/await api
665
- * async function encryptMyData(value) {
666
- * const keyId = await clientEncryption.createDataKey('local');
667
- * return clientEncryption.encrypt(value, { keyId, algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' });
668
- * }
669
- *
670
- * @example
671
- * // Encryption using a keyAltName
672
- * async function encryptMyData(value) {
673
- * await clientEncryption.createDataKey('local', { keyAltNames: 'mySpecialKey' });
674
- * return clientEncryption.encrypt(value, { keyAltName: 'mySpecialKey', algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' });
675
- * }
676
- */
677
- encrypt(value, options, callback) {
678
- return maybeCallback(() => this._encrypt(value, false, options), callback);
679
- }
680
-
681
- /**
682
- * Encrypts a Match Expression or Aggregate Expression to query a range index.
683
- *
684
- * Only supported when queryType is "rangePreview" and algorithm is "RangePreview".
685
- *
686
- * @experimental The Range algorithm is experimental only. It is not intended for production use. It is subject to breaking changes.
687
- *
688
- * @param {object} expression a BSON document of one of the following forms:
689
- * 1. A Match Expression of this form:
690
- * `{$and: [{<field>: {$gt: <value1>}}, {<field>: {$lt: <value2> }}]}`
691
- * 2. An Aggregate Expression of this form:
692
- * `{$and: [{$gt: [<fieldpath>, <value1>]}, {$lt: [<fieldpath>, <value2>]}]}`
693
- *
694
- * `$gt` may also be `$gte`. `$lt` may also be `$lte`.
695
- *
696
- * @param {EncryptOptions} options
697
- * @returns {Promise<object>} Returns a Promise that either resolves with the encrypted value or rejects with an error.
698
- */
699
- async encryptExpression(expression, options) {
700
- return this._encrypt(expression, true, options);
701
- }
702
-
703
- /**
704
- * @callback ClientEncryption~decryptCallback
705
- * @param {Error} [err] If present, indicates an error that occurred in the process of decryption
706
- * @param {object} [result] If present, is the decrypted result
707
- */
708
-
709
- /**
710
- * Explicitly decrypt a provided encrypted value
711
- *
712
- * @param {Buffer | Binary} value An encrypted value
713
- * @param {ClientEncryption~decryptCallback} callback Optional callback to invoke when value is decrypted
714
- * @returns {Promise|void} If no callback is provided, returns a Promise that either resolves with the decrypted value, or rejects with an error. If a callback is provided, returns nothing.
715
- *
716
- * @example
717
- * // Decrypting value with callback API
718
- * function decryptMyValue(value, callback) {
719
- * clientEncryption.decrypt(value, callback);
720
- * }
721
- *
722
- * @example
723
- * // Decrypting value with async/await API
724
- * async function decryptMyValue(value) {
725
- * return clientEncryption.decrypt(value);
726
- * }
727
- */
728
- decrypt(value, callback) {
729
- const bson = this._bson;
730
- const valueBuffer = bson.serialize({ v: value });
731
- const context = this._mongoCrypt.makeExplicitDecryptionContext(valueBuffer);
732
-
733
- const stateMachine = new StateMachine({
734
- bson,
735
- proxyOptions: this._proxyOptions,
736
- tlsOptions: this._tlsOptions
737
- });
738
-
739
- return promiseOrCallback(callback, cb => {
740
- stateMachine.execute(this, context, (err, result) => {
741
- if (err) {
742
- cb(err, null);
743
- return;
744
- }
745
-
746
- cb(null, result.v);
747
- });
748
- });
749
- }
750
-
751
- /**
752
- * Ask the user for KMS credentials.
753
- *
754
- * This returns anything that looks like the kmsProviders original input
755
- * option. It can be empty, and any provider specified here will override
756
- * the original ones.
757
- */
758
- async askForKMSCredentials() {
759
- return this._onKmsProviderRefresh
760
- ? this._onKmsProviderRefresh()
761
- : loadCredentials(this._kmsProviders);
762
- }
763
-
764
- static get libmongocryptVersion() {
765
- return mc.MongoCrypt.libmongocryptVersion;
766
- }
767
-
768
- /**
769
- * A helper that perform explicit encryption of values and expressions.
770
- * Explicitly encrypt a provided value. Note that either `options.keyId` or `options.keyAltName` must
771
- * be specified. Specifying both `options.keyId` and `options.keyAltName` is considered an error.
772
- *
773
- * @param {*} value The value that you wish to encrypt. Must be of a type that can be serialized into BSON
774
- * @param {boolean} expressionMode - a boolean that indicates whether or not to encrypt the value as an expression
775
- * @param {EncryptOptions} options
776
- * @returns the raw result of the call to stateMachine.execute(). When expressionMode is set to true, the return
777
- * value will be a bson document. When false, the value will be a BSON Binary.
778
- *
779
- * @ignore
780
- *
781
- */
782
- async _encrypt(value, expressionMode, options) {
783
- const bson = this._bson;
784
- const valueBuffer = bson.serialize({ v: value });
785
- const contextOptions = Object.assign({}, options, { expressionMode });
786
- if (options.keyId) {
787
- contextOptions.keyId = options.keyId.buffer;
788
- }
789
- if (options.keyAltName) {
790
- const keyAltName = options.keyAltName;
791
- if (options.keyId) {
792
- throw new TypeError(`"options" cannot contain both "keyId" and "keyAltName"`);
793
- }
794
- const keyAltNameType = typeof keyAltName;
795
- if (keyAltNameType !== 'string') {
796
- throw new TypeError(
797
- `"options.keyAltName" must be of type string, but was of type ${keyAltNameType}`
798
- );
799
- }
800
-
801
- contextOptions.keyAltName = bson.serialize({ keyAltName });
802
- }
803
-
804
- if ('rangeOptions' in options) {
805
- contextOptions.rangeOptions = bson.serialize(options.rangeOptions);
806
- }
807
-
808
- const stateMachine = new StateMachine({
809
- bson,
810
- proxyOptions: this._proxyOptions,
811
- tlsOptions: this._tlsOptions
812
- });
813
- const context = this._mongoCrypt.makeExplicitEncryptionContext(valueBuffer, contextOptions);
814
-
815
- const result = await stateMachine.executeAsync(this, context);
816
- return result.v;
817
- }
818
- }
819
-
820
- return { ClientEncryption };
821
- };