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,956 +0,0 @@
1
- #include "mongocrypt.h"
2
- #include <cassert>
3
-
4
- #ifdef _MSC_VER
5
- #define strncasecmp _strnicmp
6
- #define strcasecmp _stricmp
7
- #endif
8
-
9
- namespace node_mongocrypt {
10
-
11
- using namespace Napi;
12
-
13
- // anonymous namepace for helpers
14
- namespace {
15
- struct InstanceData {
16
- Reference<Function> MongoCryptContextCtor;
17
- Reference<Function> MongoCryptKMSRequestCtor;
18
- };
19
-
20
- struct MongoCryptStatusDeleter {
21
- void operator()(mongocrypt_status_t* status) {
22
- mongocrypt_status_destroy(status);
23
- }
24
- };
25
-
26
- Object ExtractStatus(Env env, mongocrypt_status_t* status) {
27
- Object result = Object::New(env);
28
- result["type"] = Number::New(env, mongocrypt_status_type(status));
29
- result["code"] = Number::New(env, mongocrypt_status_code(status));
30
- const char* message = mongocrypt_status_message(status, nullptr);
31
- if (message != nullptr) {
32
- result["message"] = String::New(env, message);
33
- }
34
-
35
- return result;
36
- }
37
-
38
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter>
39
- BufferToBinary(Uint8Array node_buffer) {
40
- uint8_t* buffer = node_buffer.Data();
41
- size_t buffer_len = node_buffer.ByteLength();
42
- return std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter>(
43
- mongocrypt_binary_new_from_data(buffer, buffer_len));
44
- }
45
-
46
- Uint8Array BufferFromBinary(Env env, mongocrypt_binary_t* binary) {
47
- const uint8_t* data = mongocrypt_binary_data(binary);
48
- size_t len = mongocrypt_binary_len(binary);
49
- return Buffer<uint8_t>::Copy(env, data, len);
50
- }
51
-
52
- Uint8Array BufferWithLengthOf(Env env, mongocrypt_binary_t* binary) {
53
- size_t len = mongocrypt_binary_len(binary);
54
- return Buffer<uint8_t>::New(env, len);
55
- }
56
-
57
- void CopyBufferData(mongocrypt_binary_t* out, Uint8Array buffer, size_t count) {
58
- assert(count <= mongocrypt_binary_len(out));
59
- assert(count <= buffer.ByteLength());
60
- memcpy(mongocrypt_binary_data(out), buffer.Data(), count);
61
- }
62
-
63
- void CopyBufferData(mongocrypt_binary_t* out, Uint8Array buffer) {
64
- CopyBufferData(out, buffer, mongocrypt_binary_len(out));
65
- }
66
-
67
- std::string errorStringFromStatus(mongocrypt_t* crypt) {
68
- std::unique_ptr<mongocrypt_status_t, MongoCryptStatusDeleter> status(mongocrypt_status_new());
69
- mongocrypt_status(crypt, status.get());
70
- const char* errorMessage = mongocrypt_status_message(status.get(), nullptr);
71
- if (!errorMessage) {
72
- return "Operation failed";
73
- }
74
-
75
- return errorMessage;
76
- }
77
-
78
- std::string errorStringFromStatus(mongocrypt_ctx_t* context) {
79
- std::unique_ptr<mongocrypt_status_t, MongoCryptStatusDeleter> status(mongocrypt_status_new());
80
- mongocrypt_ctx_status(context, status.get());
81
- const char* errorMessage = mongocrypt_status_message(status.get(), nullptr);
82
- if (!errorMessage) {
83
- return "Operation failed";
84
- }
85
-
86
- return errorMessage;
87
- }
88
-
89
- template<typename E>
90
- E strToEnumValue(
91
- Env env,
92
- const std::string& str,
93
- const char* option_name,
94
- const std::initializer_list<std::pair<const char*, E>>& values) {
95
- for (const auto& candidate : values) {
96
- if (candidate.first == str) {
97
- return candidate.second;
98
- }
99
- }
100
- throw Error::New(env,
101
- std::string("invalid enum value: '") + str + "' for " + option_name);
102
- }
103
-
104
- } // anonymous namespace
105
-
106
- Function MongoCrypt::Init(Napi::Env env) {
107
- return
108
- DefineClass(env,
109
- "MongoCrypt",
110
- {
111
- InstanceMethod("makeEncryptionContext", &MongoCrypt::MakeEncryptionContext),
112
- InstanceMethod("makeExplicitEncryptionContext", &MongoCrypt::MakeExplicitEncryptionContext),
113
- InstanceMethod("makeDecryptionContext", &MongoCrypt::MakeDecryptionContext),
114
- InstanceMethod("makeExplicitDecryptionContext", &MongoCrypt::MakeExplicitDecryptionContext),
115
- InstanceMethod("makeDataKeyContext", &MongoCrypt::MakeDataKeyContext),
116
- InstanceMethod("makeRewrapManyDataKeyContext", &MongoCrypt::MakeRewrapManyDataKeyContext),
117
- InstanceAccessor("status", &MongoCrypt::Status, nullptr),
118
- InstanceAccessor("cryptSharedLibVersionInfo", &MongoCrypt::CryptSharedLibVersionInfo, nullptr),
119
- StaticValue("libmongocryptVersion", String::New(env, mongocrypt_version(nullptr)))
120
- });
121
- }
122
-
123
- void MongoCrypt::logHandler(mongocrypt_log_level_t level,
124
- const char* message,
125
- uint32_t message_len,
126
- void* ctx) {
127
- MongoCrypt* mongoCrypt = static_cast<MongoCrypt*>(ctx);
128
- if (!mongoCrypt) {
129
- fprintf(stderr, "Log handler called without `MongoCrypt` instance\n");
130
- return;
131
- }
132
-
133
- Napi::Env env = mongoCrypt->Env();
134
- HandleScope scope(env);
135
- Function logger = mongoCrypt->GetCallback("logger");
136
-
137
- if (logger.IsEmpty()) {
138
- fprintf(stderr, "No logger set, but log handler registered\n");
139
- return;
140
- }
141
-
142
- try {
143
- logger.Call(std::initializer_list<napi_value>
144
- { Number::New(env, level), String::New(env, message, message_len) });
145
- } catch (const std::exception& ex) {
146
- fprintf(stderr, "Uncaught exception in logger callback: %s\n", ex.what());
147
- } catch (...) {
148
- fprintf(stderr, "Uncaught exception in logger callback\n");
149
- }
150
- }
151
-
152
-
153
- static void MaybeSetCryptoHookErrorStatus(Value result, mongocrypt_status_t *status) {
154
- if (!result.IsObject()) {
155
- return;
156
- }
157
- Object hookError = result.As<Object>();
158
- if (!hookError.Has("message")) {
159
- return;
160
- }
161
- std::string errorMessage = hookError.Get("message").ToString();
162
- mongocrypt_status_set(
163
- status,
164
- MONGOCRYPT_STATUS_ERROR_CLIENT,
165
- 1,
166
- errorMessage.c_str(),
167
- errorMessage.length() + 1
168
- );
169
- }
170
-
171
- static bool aes_256_generic_hook (MongoCrypt* mongoCrypt, mongocrypt_binary_t *key, mongocrypt_binary_t *iv, mongocrypt_binary_t *in, mongocrypt_binary_t *out, uint32_t *bytes_written, mongocrypt_status_t *status, Function hook) {
172
- Env env = mongoCrypt->Env();
173
- HandleScope scope(env);
174
-
175
- Uint8Array keyBuffer = BufferFromBinary(env, key);
176
- Uint8Array ivBuffer = BufferFromBinary(env, iv);
177
- Uint8Array inBuffer = BufferFromBinary(env, in);
178
- Uint8Array outBuffer = BufferWithLengthOf(env, out);
179
-
180
- Value result;
181
- try {
182
- result = hook.Call(std::initializer_list<napi_value>
183
- { keyBuffer, ivBuffer, inBuffer, outBuffer });
184
- } catch (...) {
185
- return false;
186
- }
187
-
188
- if (!result.IsNumber()) {
189
- MaybeSetCryptoHookErrorStatus(result, status);
190
- return false;
191
- }
192
-
193
- *bytes_written = result.ToNumber().Uint32Value();
194
- CopyBufferData(out, outBuffer, *bytes_written);
195
- return true;
196
- }
197
-
198
- bool MongoCrypt::setupCryptoHooks() {
199
- auto aes_256_cbc_encrypt =
200
- [](void *ctx, mongocrypt_binary_t *key, mongocrypt_binary_t *iv, mongocrypt_binary_t *in, mongocrypt_binary_t *out, uint32_t *bytes_written, mongocrypt_status_t *status) -> bool {
201
- MongoCrypt* mc = static_cast<MongoCrypt*>(ctx);
202
- return aes_256_generic_hook(mc, key, iv, in, out, bytes_written, status, mc->GetCallback("aes256CbcEncryptHook"));
203
- };
204
-
205
- auto aes_256_cbc_decrypt =
206
- [](void *ctx, mongocrypt_binary_t *key, mongocrypt_binary_t *iv, mongocrypt_binary_t *in, mongocrypt_binary_t *out, uint32_t *bytes_written, mongocrypt_status_t *status) -> bool {
207
- MongoCrypt* mc = static_cast<MongoCrypt*>(ctx);
208
- return aes_256_generic_hook(mc, key, iv, in, out, bytes_written, status, mc->GetCallback("aes256CbcDecryptHook"));
209
- };
210
-
211
- auto aes_256_ctr_encrypt =
212
- [](void *ctx, mongocrypt_binary_t *key, mongocrypt_binary_t *iv, mongocrypt_binary_t *in, mongocrypt_binary_t *out, uint32_t *bytes_written, mongocrypt_status_t *status) -> bool {
213
- MongoCrypt* mc = static_cast<MongoCrypt*>(ctx);
214
- return aes_256_generic_hook(mc, key, iv, in, out, bytes_written, status, mc->GetCallback("aes256CtrEncryptHook"));
215
- };
216
-
217
- auto aes_256_ctr_decrypt =
218
- [](void *ctx, mongocrypt_binary_t *key, mongocrypt_binary_t *iv, mongocrypt_binary_t *in, mongocrypt_binary_t *out, uint32_t *bytes_written, mongocrypt_status_t *status) -> bool {
219
- MongoCrypt* mc = static_cast<MongoCrypt*>(ctx);
220
- return aes_256_generic_hook(mc, key, iv, in, out, bytes_written, status, mc->GetCallback("aes256CtrDecryptHook"));
221
- };
222
-
223
- auto random =
224
- [](void *ctx, mongocrypt_binary_t *out, uint32_t count, mongocrypt_status_t *status) -> bool {
225
- MongoCrypt* mongoCrypt = static_cast<MongoCrypt*>(ctx);
226
- Napi::Env env = mongoCrypt->Env();
227
- HandleScope scope(env);
228
- Function hook = mongoCrypt->GetCallback("randomHook");
229
-
230
- Uint8Array outBuffer = BufferWithLengthOf(env, out);
231
- Napi::Value result;
232
- try {
233
- result = hook.Call(std::initializer_list<napi_value>
234
- { outBuffer, Number::New(env, count) });
235
- } catch (...) {
236
- return false;
237
- }
238
-
239
- if (!result.IsNumber()) {
240
- MaybeSetCryptoHookErrorStatus(result, status);
241
- return false;
242
- }
243
-
244
- CopyBufferData(out, outBuffer);
245
- return true;
246
- };
247
-
248
- auto hmac_sha_512 =
249
- [](void *ctx, mongocrypt_binary_t *key, mongocrypt_binary_t *in, mongocrypt_binary_t *out, mongocrypt_status_t *status) -> bool {
250
- MongoCrypt* mongoCrypt = static_cast<MongoCrypt*>(ctx);
251
- Napi::Env env = mongoCrypt->Env();
252
- HandleScope scope(env);
253
- Function hook = mongoCrypt->GetCallback("hmacSha512Hook");
254
-
255
- Uint8Array keyBuffer = BufferFromBinary(env, key);
256
- Uint8Array inputBuffer = BufferFromBinary(env, in);
257
- Uint8Array outputBuffer = BufferWithLengthOf(env, out);
258
-
259
- Napi::Value result;
260
- try {
261
- result = hook.Call(std::initializer_list<napi_value>
262
- { keyBuffer, inputBuffer, outputBuffer });
263
- } catch (...) {
264
- return false;
265
- }
266
-
267
- if (!result.IsNumber()) {
268
- MaybeSetCryptoHookErrorStatus(result, status);
269
- return false;
270
- }
271
-
272
- CopyBufferData(out, outputBuffer);
273
- return true;
274
- };
275
-
276
- auto hmac_sha_256 =
277
- [](void *ctx, mongocrypt_binary_t *key, mongocrypt_binary_t *in, mongocrypt_binary_t *out, mongocrypt_status_t *status) -> bool {
278
- MongoCrypt* mongoCrypt = static_cast<MongoCrypt*>(ctx);
279
- Napi::Env env = mongoCrypt->Env();
280
- HandleScope scope(env);
281
- Function hook = mongoCrypt->GetCallback("hmacSha256Hook");
282
-
283
- Uint8Array keyBuffer = BufferFromBinary(env, key);
284
- Uint8Array inputBuffer = BufferFromBinary(env, in);
285
- Uint8Array outputBuffer = BufferWithLengthOf(env, out);
286
-
287
- Napi::Value result;
288
- try {
289
- result = hook.Call(std::initializer_list<napi_value>
290
- { keyBuffer, inputBuffer, outputBuffer });
291
- } catch (...) {
292
- return false;
293
- }
294
-
295
- if (!result.IsNumber()) {
296
- MaybeSetCryptoHookErrorStatus(result, status);
297
- return false;
298
- }
299
-
300
- CopyBufferData(out, outputBuffer);
301
- return true;
302
- };
303
-
304
- auto sha_256 =
305
- [](void *ctx, mongocrypt_binary_t *in, mongocrypt_binary_t *out, mongocrypt_status_t *status) -> bool {
306
- MongoCrypt* mongoCrypt = static_cast<MongoCrypt*>(ctx);
307
- Napi::Env env = mongoCrypt->Env();
308
- HandleScope scope(env);
309
- Function hook = mongoCrypt->GetCallback("sha256Hook");
310
-
311
- Uint8Array inputBuffer = BufferFromBinary(env, in);
312
- Uint8Array outputBuffer = BufferWithLengthOf(env, out);
313
-
314
- Napi::Value result;
315
- try {
316
- result = hook.Call(std::initializer_list<napi_value>
317
- { inputBuffer, outputBuffer });
318
- } catch (...) {
319
- return false;
320
- }
321
-
322
- if (!result.IsNumber()) {
323
- MaybeSetCryptoHookErrorStatus(result, status);
324
- return false;
325
- }
326
-
327
- CopyBufferData(out, outputBuffer);
328
- return true;
329
- };
330
-
331
- auto sign_rsa_sha256 =
332
- [](void *ctx, mongocrypt_binary_t *key, mongocrypt_binary_t *in, mongocrypt_binary_t *out, mongocrypt_status_t *status) -> bool {
333
- MongoCrypt* mongoCrypt = static_cast<MongoCrypt*>(ctx);
334
- Napi::Env env = mongoCrypt->Env();
335
- HandleScope scope(env);
336
- Function hook = mongoCrypt->GetCallback("signRsaSha256Hook");
337
-
338
- Uint8Array keyBuffer = BufferFromBinary(env, key);
339
- Uint8Array inputBuffer = BufferFromBinary(env, in);
340
- Uint8Array outputBuffer = BufferWithLengthOf(env, out);
341
-
342
- Napi::Value result;
343
- try {
344
- result = hook.Call(std::initializer_list<napi_value>
345
- { keyBuffer, inputBuffer, outputBuffer });
346
- } catch (...) {
347
- return false;
348
- }
349
-
350
- if (!result.IsNumber()) {
351
- MaybeSetCryptoHookErrorStatus(result, status);
352
- return false;
353
- }
354
-
355
- CopyBufferData(out, outputBuffer);
356
- return true;
357
- };
358
-
359
- if (!mongocrypt_setopt_crypto_hooks(_mongo_crypt.get(),
360
- aes_256_cbc_encrypt,
361
- aes_256_cbc_decrypt,
362
- random,
363
- hmac_sha_512,
364
- hmac_sha_256,
365
- sha_256,
366
- this)) {
367
- return false;
368
- }
369
-
370
- // Added after `mongocrypt_setopt_crypto_hooks`, they should be treated as the same during configuration
371
- if (!mongocrypt_setopt_crypto_hook_sign_rsaes_pkcs1_v1_5(_mongo_crypt.get(), sign_rsa_sha256, this)) {
372
- return false;
373
- }
374
-
375
- if (!mongocrypt_setopt_aes_256_ctr(_mongo_crypt.get(), aes_256_ctr_encrypt, aes_256_ctr_decrypt, this)) {
376
- return false;
377
- }
378
-
379
- return true;
380
- }
381
-
382
- MongoCrypt::MongoCrypt(const CallbackInfo& info)
383
- : ObjectWrap(info), _mongo_crypt(mongocrypt_new()) {
384
- if (info.Length() < 1 || !info[0].IsObject()) {
385
- throw TypeError::New(Env(), "First parameter must be an object");
386
- }
387
-
388
- Object options = info[0].ToObject();
389
-
390
- if (options.Has("kmsProviders")) {
391
- Napi::Value kmsProvidersOptions = options["kmsProviders"];
392
-
393
- if (!kmsProvidersOptions.IsBuffer()) {
394
- throw TypeError::New(Env(), "Option `kmsProviders` must be a Buffer");
395
- }
396
-
397
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> kmsProvidersBinary(
398
- BufferToBinary(kmsProvidersOptions.As<Uint8Array>()));
399
- if (!mongocrypt_setopt_kms_providers(_mongo_crypt.get(), kmsProvidersBinary.get())) {
400
- throw TypeError::New(Env(), errorStringFromStatus(_mongo_crypt.get()));
401
- }
402
- }
403
-
404
- if (options.Has("schemaMap")) {
405
- Napi::Value schemaMapBuffer = options["schemaMap"];
406
-
407
- if (!schemaMapBuffer.IsBuffer()) {
408
- throw TypeError::New(Env(), "Option `schemaMap` must be a Buffer");
409
- }
410
-
411
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> schemaMapBinary(
412
- BufferToBinary(schemaMapBuffer.As<Uint8Array>()));
413
- if (!mongocrypt_setopt_schema_map(_mongo_crypt.get(), schemaMapBinary.get())) {
414
- throw TypeError::New(Env(), errorStringFromStatus(_mongo_crypt.get()));
415
- }
416
- }
417
-
418
- if (options.Has("encryptedFieldsMap")) {
419
- Napi::Value encryptedFieldsMapBuffer = options["encryptedFieldsMap"];
420
-
421
- if (!encryptedFieldsMapBuffer.IsBuffer()) {
422
- throw TypeError::New(Env(), "Option `encryptedFieldsMap` must be a Buffer");
423
- }
424
-
425
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> encryptedFieldsMapBinary(
426
- BufferToBinary(encryptedFieldsMapBuffer.As<Uint8Array>()));
427
- if (!mongocrypt_setopt_encrypted_field_config_map(_mongo_crypt.get(), encryptedFieldsMapBinary.get())) {
428
- throw TypeError::New(Env(), errorStringFromStatus(_mongo_crypt.get()));
429
- }
430
- }
431
-
432
- if (options.Has("logger")) {
433
- SetCallback("logger", options["logger"]);
434
- if (!mongocrypt_setopt_log_handler(
435
- _mongo_crypt.get(), MongoCrypt::logHandler, this)) {
436
- throw TypeError::New(Env(), errorStringFromStatus(_mongo_crypt.get()));
437
- }
438
- }
439
-
440
- if (options.Has("cryptoCallbacks")) {
441
- Object cryptoCallbacks = options.Get("cryptoCallbacks").ToObject();
442
-
443
- SetCallback("aes256CbcEncryptHook", cryptoCallbacks["aes256CbcEncryptHook"]);
444
- SetCallback("aes256CbcDecryptHook", cryptoCallbacks["aes256CbcDecryptHook"]);
445
- SetCallback("aes256CtrEncryptHook", cryptoCallbacks["aes256CtrEncryptHook"]);
446
- SetCallback("aes256CtrDecryptHook", cryptoCallbacks["aes256CtrDecryptHook"]);
447
- SetCallback("randomHook", cryptoCallbacks["randomHook"]);
448
- SetCallback("hmacSha512Hook", cryptoCallbacks["hmacSha512Hook"]);
449
- SetCallback("hmacSha256Hook", cryptoCallbacks["hmacSha256Hook"]);
450
- SetCallback("sha256Hook", cryptoCallbacks["sha256Hook"]);
451
- SetCallback("signRsaSha256Hook", cryptoCallbacks["signRsaSha256Hook"]);
452
-
453
- if (!setupCryptoHooks()) {
454
- throw Error::New(Env(), "unable to configure crypto hooks");
455
- }
456
- }
457
-
458
- if (options.Has("cryptSharedLibSearchPaths")) {
459
- Napi::Value search_paths_v = options["cryptSharedLibSearchPaths"];
460
- if (!search_paths_v.IsArray()) {
461
- throw TypeError::New(Env(), "Option `cryptSharedLibSearchPaths` must be an array");
462
- }
463
- Array search_paths = search_paths_v.As<Array>();
464
- for (uint32_t i = 0; i < search_paths.Length(); i++) {
465
- mongocrypt_setopt_append_crypt_shared_lib_search_path(
466
- _mongo_crypt.get(),
467
- search_paths.Get(i).ToString().Utf8Value().c_str());
468
- }
469
- }
470
-
471
- if (options.Has("cryptSharedLibPath")) {
472
- mongocrypt_setopt_set_crypt_shared_lib_path_override(
473
- _mongo_crypt.get(),
474
- options.Get("cryptSharedLibPath").ToString().Utf8Value().c_str());
475
- }
476
-
477
- if (options.Get("bypassQueryAnalysis").ToBoolean()) {
478
- mongocrypt_setopt_bypass_query_analysis(_mongo_crypt.get());
479
- }
480
-
481
- mongocrypt_setopt_use_need_kms_credentials_state(_mongo_crypt.get());
482
-
483
- // Initialize after all options are set.
484
- if (!mongocrypt_init(_mongo_crypt.get())) {
485
- throw TypeError::New(Env(), errorStringFromStatus(_mongo_crypt.get()));
486
- }
487
- }
488
-
489
- Value MongoCrypt::CryptSharedLibVersionInfo(const CallbackInfo& info) {
490
- uint64_t version_numeric = mongocrypt_crypt_shared_lib_version(_mongo_crypt.get());
491
- const char* version_string = mongocrypt_crypt_shared_lib_version_string(_mongo_crypt.get(), nullptr);
492
- if (version_string == nullptr) {
493
- return Env().Null();
494
- }
495
-
496
- Object ret = Object::New(Env());
497
- ret["version"] = BigInt::New(Env(), version_numeric);
498
- ret["versionStr"] = String::New(Env(), version_string);
499
- return ret;
500
- }
501
-
502
- Value MongoCrypt::Status(const CallbackInfo& info) {
503
- std::unique_ptr<mongocrypt_status_t, MongoCryptStatusDeleter> status(mongocrypt_status_new());
504
- mongocrypt_status(_mongo_crypt.get(), status.get());
505
- return ExtractStatus(Env(), status.get());
506
- }
507
-
508
- Value MongoCrypt::MakeEncryptionContext(const CallbackInfo& info) {
509
- std::string ns = info[0].ToString();
510
- std::unique_ptr<mongocrypt_ctx_t, MongoCryptContextDeleter> context(
511
- mongocrypt_ctx_new(_mongo_crypt.get()));
512
-
513
- Napi::Value commandBuffer = info[1];
514
- if (!commandBuffer.IsBuffer()) {
515
- throw TypeError::New(Env(), "Parameter `command` must be a Buffer");
516
- }
517
-
518
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binaryCommand(BufferToBinary(commandBuffer.As<Uint8Array>()));
519
- if (!mongocrypt_ctx_encrypt_init(
520
- context.get(), ns.c_str(), ns.size(), binaryCommand.get())) {
521
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
522
- }
523
-
524
- return MongoCryptContext::NewInstance(Env(), std::move(context));
525
- }
526
-
527
- Value MongoCrypt::MakeExplicitEncryptionContext(const CallbackInfo& info) {
528
- std::unique_ptr<mongocrypt_ctx_t, MongoCryptContextDeleter> context(
529
- mongocrypt_ctx_new(_mongo_crypt.get()));
530
-
531
- Napi::Value valueBuffer = info[0];
532
- if (!valueBuffer.IsBuffer()) {
533
- throw TypeError::New(Env(), "Parameter `value` must be a Buffer");
534
- }
535
-
536
- Object options = info.Length() > 1 ? info[1].ToObject() : Object::New(info.Env());
537
-
538
- if (options.Has("keyId")) {
539
- Napi::Value keyId = options["keyId"];
540
-
541
- if (!keyId.IsBuffer()) {
542
- throw TypeError::New(Env(), "`keyId` must be a Buffer");
543
- }
544
-
545
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binary(BufferToBinary(keyId.As<Uint8Array>()));
546
- if (!mongocrypt_ctx_setopt_key_id(context.get(), binary.get())) {
547
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
548
- }
549
- }
550
-
551
- if (options.Has("keyAltName")) {
552
- Napi::Value keyAltName = options["keyAltName"];
553
-
554
- if (!keyAltName.IsBuffer()) {
555
- throw TypeError::New(Env(), "`keyAltName` must be a Buffer");
556
- }
557
-
558
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binary(
559
- BufferToBinary(keyAltName.As<Uint8Array>()));
560
- if (!mongocrypt_ctx_setopt_key_alt_name(context.get(), binary.get())) {
561
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
562
- }
563
- }
564
-
565
- if (options.Has("algorithm")) {
566
- std::string algorithm = options.Get("algorithm").ToString();
567
- if (!mongocrypt_ctx_setopt_algorithm(
568
- context.get(), algorithm.c_str(), algorithm.size())) {
569
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
570
- }
571
-
572
- if (strcasecmp(algorithm.c_str(), "rangepreview") == 0) {
573
- if (!options.Has("rangeOptions")) {
574
- throw TypeError::New(Env(), "`rangeOptions` must be provided if `algorithm` is set to RangePreview");
575
- }
576
-
577
- Napi::Value rangeOptions = options["rangeOptions"];
578
-
579
- if (!rangeOptions.IsBuffer()) {
580
- throw TypeError::New(Env(), "`rangeOptions` must be a Buffer");
581
- }
582
-
583
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binary(BufferToBinary(rangeOptions.As<Uint8Array>()));
584
- if (!mongocrypt_ctx_setopt_algorithm_range(context.get(), binary.get())) {
585
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
586
- }
587
- }
588
- }
589
-
590
- if (options.Has("contentionFactor")) {
591
- Napi::Value contention_factor_value = options["contentionFactor"];
592
- int64_t contention_factor = contention_factor_value.IsBigInt() ?
593
- contention_factor_value.As<BigInt>().Int64Value(nullptr) :
594
- contention_factor_value.ToNumber().Int64Value();
595
- if (!mongocrypt_ctx_setopt_contention_factor(context.get(), contention_factor)) {
596
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
597
- }
598
- }
599
-
600
- if (options.Has("queryType")) {
601
- std::string query_type_str = options.Get("queryType").ToString();
602
- if (!mongocrypt_ctx_setopt_query_type(context.get(), query_type_str.data(), -1)) {
603
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
604
- }
605
- }
606
-
607
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binaryValue(BufferToBinary(valueBuffer.As<Uint8Array>()));
608
-
609
- const bool isExpressionMode = options.Get("expressionMode").ToBoolean();
610
-
611
- const bool status = isExpressionMode
612
- ? mongocrypt_ctx_explicit_encrypt_expression_init(context.get(), binaryValue.get())
613
- : mongocrypt_ctx_explicit_encrypt_init(context.get(), binaryValue.get());
614
-
615
- if (!status) {
616
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
617
- }
618
-
619
- return MongoCryptContext::NewInstance(Env(), std::move(context));
620
- }
621
-
622
- Value MongoCrypt::MakeDecryptionContext(const CallbackInfo& info) {
623
- if (!info[0].IsBuffer()) {
624
- throw TypeError::New(Env(), "First parameter must be a Buffer");
625
- }
626
-
627
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binary(
628
- BufferToBinary(info[0].As<Uint8Array>()));
629
- std::unique_ptr<mongocrypt_ctx_t, MongoCryptContextDeleter> context(
630
- mongocrypt_ctx_new(_mongo_crypt.get()));
631
-
632
- if (!mongocrypt_ctx_decrypt_init(context.get(), binary.get())) {
633
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
634
- }
635
-
636
- return MongoCryptContext::NewInstance(Env(), std::move(context));
637
- }
638
-
639
- Value MongoCrypt::MakeExplicitDecryptionContext(const CallbackInfo& info) {
640
- if (!info[0].IsBuffer()) {
641
- throw TypeError::New(Env(), "First parameter must be a Buffer");
642
- }
643
-
644
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binary(
645
- BufferToBinary(info[0].As<Uint8Array>()));
646
- std::unique_ptr<mongocrypt_ctx_t, MongoCryptContextDeleter> context(
647
- mongocrypt_ctx_new(_mongo_crypt.get()));
648
-
649
- if (!mongocrypt_ctx_explicit_decrypt_init(context.get(), binary.get())) {
650
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
651
- }
652
-
653
- return MongoCryptContext::NewInstance(Env(), std::move(context));
654
- }
655
-
656
- Value MongoCrypt::MakeDataKeyContext(const CallbackInfo& info) {
657
- Napi::Value optionsBuffer = info[0];
658
- if (!optionsBuffer.IsBuffer()) {
659
- throw TypeError::New(Env(), "Parameter `options` must be a Buffer");
660
- }
661
-
662
- std::unique_ptr<mongocrypt_ctx_t, MongoCryptContextDeleter> context(
663
- mongocrypt_ctx_new(_mongo_crypt.get()));
664
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binary(
665
- BufferToBinary(optionsBuffer.As<Uint8Array>()));
666
-
667
- if (!mongocrypt_ctx_setopt_key_encryption_key(context.get(), binary.get())) {
668
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
669
- }
670
-
671
- Object options = info[1].ToObject();
672
- if (options.Has("keyAltNames")) {
673
- Napi::Value keyAltNames = options["keyAltNames"];
674
-
675
- if (keyAltNames.IsArray()) {
676
- Array keyAltNamesArray = keyAltNames.As<Array>();
677
- uint32_t keyAltNamesLength = keyAltNamesArray.Length();
678
- for (uint32_t i = 0; i < keyAltNamesLength; i += 1) {
679
- if (keyAltNamesArray.Has(i)) {
680
- Napi::Value keyAltName = keyAltNamesArray[i];
681
- if (!keyAltName.IsBuffer()) {
682
- // We should never get here
683
- throw TypeError::New(Env(), "Serialized keyAltName must be a Buffer");
684
- }
685
-
686
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binary(
687
- BufferToBinary(keyAltName.As<Uint8Array>()));
688
- if (!mongocrypt_ctx_setopt_key_alt_name(context.get(), binary.get())) {
689
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
690
- }
691
- }
692
- }
693
- }
694
- }
695
-
696
- if (options.Has("keyMaterial")) {
697
- Napi::Value keyMaterial = options["keyMaterial"];
698
-
699
- if (!keyMaterial.IsUndefined()) {
700
- if (!keyMaterial.IsBuffer()) {
701
- // We should never get here
702
- throw TypeError::New(Env(), "Serialized keyMaterial must be a Buffer");
703
- }
704
-
705
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> binary(
706
- BufferToBinary(keyMaterial.As<Uint8Array>()));
707
- if (!mongocrypt_ctx_setopt_key_material(context.get(), binary.get())) {
708
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
709
- }
710
- }
711
- }
712
-
713
- if (!mongocrypt_ctx_datakey_init(context.get())) {
714
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
715
- }
716
-
717
- return MongoCryptContext::NewInstance(Env(), std::move(context));
718
- }
719
-
720
- Value MongoCrypt::MakeRewrapManyDataKeyContext(const CallbackInfo& info) {
721
- Napi::Value filter_buffer = info[0];
722
- if (!filter_buffer.IsBuffer()) {
723
- throw TypeError::New(Env(), "Parameter `options` must be a Buffer");
724
- }
725
-
726
- std::unique_ptr<mongocrypt_ctx_t, MongoCryptContextDeleter> context(
727
- mongocrypt_ctx_new(_mongo_crypt.get()));
728
-
729
- Napi::Value key_encryption_key = info[1];
730
- if (key_encryption_key.IsBuffer()) {
731
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> key_binary(
732
- BufferToBinary(key_encryption_key.As<Uint8Array>()));
733
- if (!mongocrypt_ctx_setopt_key_encryption_key(context.get(), key_binary.get())) {
734
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
735
- }
736
- }
737
-
738
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> filter_binary(
739
- BufferToBinary(filter_buffer.As<Uint8Array>()));
740
- if (!mongocrypt_ctx_rewrap_many_datakey_init(context.get(), filter_binary.get())) {
741
- throw TypeError::New(Env(), errorStringFromStatus(context.get()));
742
- }
743
-
744
- return MongoCryptContext::NewInstance(Env(), std::move(context));
745
- }
746
-
747
- // Store callbacks as nested properties on the MongoCrypt binding object
748
- // itself, and use these helpers to do so. Storing them as JS engine
749
- // References is a big memory leak footgun.
750
- Function MongoCrypt::GetCallback(const char* name) {
751
- Napi::Value storage = Value().Get("__callbackStorage");
752
- if (!storage.IsObject()) {
753
- throw Error::New(Env(), "Cannot get callbacks becauses none were registered");
754
- }
755
- Napi::Value entry = storage.As<Object>().Get(name);
756
- if (!entry.IsFunction()) {
757
- throw Error::New(Env(), std::string("Trying to look up unknown callback ") + name);
758
- }
759
- return entry.As<Function>();
760
- }
761
-
762
- void MongoCrypt::SetCallback(const char* name, Napi::Value fn) {
763
- if (!fn.IsFunction()) {
764
- throw Error::New(Env(), std::string("Storing non-function as callback ") + name);
765
- }
766
-
767
- Napi::Value storage = Value().Get("__callbackStorage");
768
- if (!storage.IsObject()) {
769
- storage = Object::New(Env());
770
- Value().Set("__callbackStorage", storage);
771
- }
772
- storage.As<Object>().Set(name, fn);
773
- }
774
-
775
- Function MongoCryptContext::Init(Napi::Env env) {
776
- return
777
- DefineClass(env,
778
- "MongoCryptContext",
779
- {
780
- InstanceMethod("nextMongoOperation", &MongoCryptContext::NextMongoOperation),
781
- InstanceMethod("addMongoOperationResponse", &MongoCryptContext::AddMongoOperationResponse),
782
- InstanceMethod("finishMongoOperation", &MongoCryptContext::FinishMongoOperation),
783
- InstanceMethod("nextKMSRequest", &MongoCryptContext::NextKMSRequest),
784
- InstanceMethod("provideKMSProviders", &MongoCryptContext::ProvideKMSProviders),
785
- InstanceMethod("finishKMSRequests", &MongoCryptContext::FinishKMSRequests),
786
- InstanceMethod("finalize", &MongoCryptContext::FinalizeContext),
787
- InstanceAccessor("status", &MongoCryptContext::Status, nullptr),
788
- InstanceAccessor("state", &MongoCryptContext::State, nullptr)
789
- });
790
- }
791
-
792
- Object MongoCryptContext::NewInstance(Napi::Env env, std::unique_ptr<mongocrypt_ctx_t, MongoCryptContextDeleter> context) {
793
- InstanceData* instance_data = env.GetInstanceData<InstanceData>();
794
- Object obj = instance_data->MongoCryptContextCtor.Value().New({});
795
- MongoCryptContext* instance = MongoCryptContext::Unwrap(obj);
796
- instance->_context = std::move(context);
797
- return obj;
798
- }
799
-
800
- MongoCryptContext::MongoCryptContext(const CallbackInfo& info)
801
- : ObjectWrap(info) {}
802
-
803
- Value MongoCryptContext::Status(const CallbackInfo& info) {
804
- std::unique_ptr<mongocrypt_status_t, MongoCryptStatusDeleter> status(mongocrypt_status_new());
805
- mongocrypt_ctx_status(_context.get(), status.get());
806
- return ExtractStatus(Env(), status.get());
807
- }
808
-
809
- Value MongoCryptContext::State(const CallbackInfo& info) {
810
- return Number::New(Env(), mongocrypt_ctx_state(_context.get()));
811
- }
812
-
813
- Value MongoCryptContext::NextMongoOperation(const CallbackInfo& info) {
814
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> op_bson(mongocrypt_binary_new());
815
- mongocrypt_ctx_mongo_op(_context.get(), op_bson.get());
816
- return BufferFromBinary(Env(), op_bson.get());
817
- }
818
-
819
- void MongoCryptContext::AddMongoOperationResponse(const CallbackInfo& info) {
820
- if (info.Length() != 1 || !info[0].IsObject()) {
821
- throw TypeError::New(Env(), "Missing required parameter `buffer`");
822
- }
823
-
824
- if (!info[0].IsBuffer()) {
825
- throw TypeError::New(Env(), "First parameter must be a Buffer");
826
- }
827
-
828
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> reply_bson(
829
- BufferToBinary(info[0].As<Uint8Array>()));
830
- mongocrypt_ctx_mongo_feed(_context.get(), reply_bson.get());
831
- // return value
832
- }
833
-
834
- void MongoCryptContext::FinishMongoOperation(const CallbackInfo& info) {
835
- mongocrypt_ctx_mongo_done(_context.get());
836
- }
837
-
838
- void MongoCryptContext::ProvideKMSProviders(const CallbackInfo& info) {
839
- if (info.Length() != 1 || !info[0].IsObject()) {
840
- throw TypeError::New(Env(), "Missing required parameter `buffer`");
841
- }
842
-
843
- if (!info[0].IsBuffer()) {
844
- throw TypeError::New(Env(), "First parameter must be a Buffer");
845
- }
846
-
847
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> kms_bson(
848
- BufferToBinary(info[0].As<Uint8Array>()));
849
- mongocrypt_ctx_provide_kms_providers(_context.get(), kms_bson.get());
850
- }
851
-
852
- Value MongoCryptContext::NextKMSRequest(const CallbackInfo& info) {
853
- mongocrypt_kms_ctx_t* kms_context = mongocrypt_ctx_next_kms_ctx(_context.get());
854
- if (kms_context == nullptr) {
855
- return Env().Null();
856
- } else {
857
- Object result = MongoCryptKMSRequest::NewInstance(Env(), kms_context);
858
- // The lifetime of the `kms_context` pointer is not specified
859
- // anywhere, so it seems reasonable to assume that it is at
860
- // least the lifetime of this context object.
861
- // Use a symbol to enforce that lifetime dependency.
862
- result.Set("__kmsRequestContext", Value());
863
- return result;
864
- }
865
- }
866
-
867
- void MongoCryptContext::FinishKMSRequests(const CallbackInfo& info) {
868
- mongocrypt_ctx_kms_done(_context.get());
869
- }
870
-
871
- Value MongoCryptContext::FinalizeContext(const CallbackInfo& info) {
872
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> output(mongocrypt_binary_new());
873
- mongocrypt_ctx_finalize(_context.get(), output.get());
874
- return BufferFromBinary(Env(), output.get());
875
- }
876
-
877
- Function MongoCryptKMSRequest::Init(Napi::Env env) {
878
- return
879
- DefineClass(env,
880
- "MongoCryptKMSRequest",
881
- {
882
- InstanceMethod("addResponse", &MongoCryptKMSRequest::AddResponse),
883
- InstanceAccessor("status", &MongoCryptKMSRequest::Status, nullptr),
884
- InstanceAccessor("bytesNeeded", &MongoCryptKMSRequest::BytesNeeded, nullptr),
885
- InstanceAccessor("kmsProvider", &MongoCryptKMSRequest::KMSProvider, nullptr),
886
- InstanceAccessor("endpoint", &MongoCryptKMSRequest::Endpoint, nullptr),
887
- InstanceAccessor("message", &MongoCryptKMSRequest::Message, nullptr)
888
- });
889
- }
890
-
891
- Object MongoCryptKMSRequest::NewInstance(Napi::Env env, mongocrypt_kms_ctx_t* kms_context) {
892
- InstanceData* instance_data = env.GetInstanceData<InstanceData>();
893
- Object obj = instance_data->MongoCryptKMSRequestCtor.Value().New({});
894
- MongoCryptKMSRequest* instance = MongoCryptKMSRequest::Unwrap(obj);
895
- instance->_kms_context = kms_context;
896
- return obj;
897
- }
898
-
899
- MongoCryptKMSRequest::MongoCryptKMSRequest(const CallbackInfo& info)
900
- : ObjectWrap(info), _kms_context(nullptr) {}
901
-
902
- Value MongoCryptKMSRequest::Status(const CallbackInfo& info) {
903
- std::unique_ptr<mongocrypt_status_t, MongoCryptStatusDeleter> status(mongocrypt_status_new());
904
- mongocrypt_kms_ctx_status(_kms_context, status.get());
905
- return ExtractStatus(Env(), status.get());
906
- }
907
-
908
- Value MongoCryptKMSRequest::BytesNeeded(const CallbackInfo& info) {
909
- return Number::New(Env(), mongocrypt_kms_ctx_bytes_needed(_kms_context));
910
- }
911
-
912
- Value MongoCryptKMSRequest::KMSProvider(const CallbackInfo& info) {
913
- return String::New(Env(), mongocrypt_kms_ctx_get_kms_provider(_kms_context, nullptr));
914
- }
915
-
916
- Value MongoCryptKMSRequest::Message(const CallbackInfo& info) {
917
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> message(mongocrypt_binary_new());
918
- mongocrypt_kms_ctx_message(_kms_context, message.get());
919
- return BufferFromBinary(Env(), message.get());
920
- }
921
-
922
- Value MongoCryptKMSRequest::Endpoint(const CallbackInfo& info) {
923
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> message(mongocrypt_binary_new());
924
-
925
- const char* endpoint;
926
- mongocrypt_kms_ctx_endpoint(_kms_context, &endpoint);
927
- return String::New(Env(), endpoint);
928
- }
929
-
930
- void MongoCryptKMSRequest::AddResponse(const CallbackInfo& info) {
931
- if (!info[0].IsBuffer()) {
932
- throw TypeError::New(Env(), "First parameter must be of type Buffer");
933
- }
934
-
935
- std::unique_ptr<mongocrypt_binary_t, MongoCryptBinaryDeleter> reply_bytes(
936
- BufferToBinary(info[0].As<Uint8Array>()));
937
- mongocrypt_kms_ctx_feed(_kms_context, reply_bytes.get());
938
- }
939
-
940
- static Object Init(Env env, Object exports) {
941
- Function MongoCryptCtor = MongoCrypt::Init(env);
942
- Function MongoCryptContextCtor = MongoCryptContext::Init(env);
943
- Function MongoCryptKMSRequestCtor = MongoCryptKMSRequest::Init(env);
944
- exports["MongoCrypt"] = MongoCryptCtor;
945
- exports["MongoCryptContextCtor"] = MongoCryptContextCtor;
946
- exports["MongoCryptKMSRequestCtor"] = MongoCryptKMSRequestCtor;
947
- env.SetInstanceData(new InstanceData {
948
- Reference<Function>::New(MongoCryptContextCtor, 1),
949
- Reference<Function>::New(MongoCryptKMSRequestCtor, 1)
950
- });
951
- return exports;
952
- }
953
-
954
- NODE_API_MODULE(mongocrypt, Init)
955
-
956
- } // namespace node_mongocrypt