libmongocrypt-helper 1.7.4.0.1002 → 1.8.0.0.1001
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
- data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
- data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
- data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
- data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
- data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
- data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
- data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
- data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
- data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
- data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
- data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
- data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
- data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
- data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
- data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
- data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
- data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
- data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
- data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
- data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
- data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
- data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
- data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
- data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
- data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
- data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
- data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
- data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
- data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
- data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
- data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
- data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
- data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
- data/lib/libmongocrypt_helper/version.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +154 -26
- metadata.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -14,678 +14,557 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
#include <bson/bson.h>
|
18
17
|
#include "mongocrypt-buffer-private.h"
|
19
18
|
#include "mongocrypt-endian-private.h"
|
20
19
|
#include "mongocrypt-util-private.h"
|
20
|
+
#include <bson/bson.h>
|
21
21
|
|
22
22
|
#define INT32_LEN 4
|
23
23
|
#define TYPE_LEN 1
|
24
24
|
#define NULL_BYTE_LEN 1
|
25
25
|
#define NULL_BYTE_VAL 0x00
|
26
26
|
|
27
|
-
|
28
27
|
/* if a buffer is not owned, copy the data and make it owned. */
|
29
|
-
static void
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
buf->owned = true;
|
28
|
+
static void _make_owned(_mongocrypt_buffer_t *buf) {
|
29
|
+
uint8_t *tmp;
|
30
|
+
|
31
|
+
BSON_ASSERT_PARAM(buf);
|
32
|
+
if (buf->owned) {
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
tmp = buf->data;
|
36
|
+
if (buf->len > 0) {
|
37
|
+
buf->data = bson_malloc(buf->len);
|
38
|
+
BSON_ASSERT(buf->data);
|
39
|
+
memcpy(buf->data, tmp, buf->len);
|
40
|
+
} else {
|
41
|
+
buf->data = NULL;
|
42
|
+
}
|
43
|
+
|
44
|
+
buf->owned = true;
|
48
45
|
}
|
49
46
|
|
50
47
|
/* TODO CDRIVER-2990 have buffer operations require initialized buffer to
|
51
48
|
* prevent leaky code. */
|
52
|
-
void
|
53
|
-
|
54
|
-
{
|
55
|
-
BSON_ASSERT_PARAM (buf);
|
49
|
+
void _mongocrypt_buffer_init(_mongocrypt_buffer_t *buf) {
|
50
|
+
BSON_ASSERT_PARAM(buf);
|
56
51
|
|
57
|
-
|
52
|
+
memset(buf, 0, sizeof(*buf));
|
58
53
|
}
|
59
54
|
|
55
|
+
void _mongocrypt_buffer_resize(_mongocrypt_buffer_t *buf, uint32_t len) {
|
56
|
+
BSON_ASSERT_PARAM(buf);
|
57
|
+
|
58
|
+
/* Currently this just wipes whatever was in data before,
|
59
|
+
but a fancier implementation could copy over up to 'len'
|
60
|
+
bytes from the old buffer to the new one. */
|
61
|
+
if (buf->owned) {
|
62
|
+
buf->data = bson_realloc(buf->data, len);
|
63
|
+
buf->len = len;
|
64
|
+
return;
|
65
|
+
}
|
60
66
|
|
61
|
-
|
62
|
-
|
63
|
-
{
|
64
|
-
BSON_ASSERT_PARAM (buf);
|
67
|
+
buf->data = bson_malloc(len);
|
68
|
+
BSON_ASSERT(buf->data);
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if (buf->owned) {
|
70
|
-
buf->data = bson_realloc (buf->data, len);
|
71
|
-
buf->len = len;
|
72
|
-
return;
|
73
|
-
}
|
70
|
+
buf->len = len;
|
71
|
+
buf->owned = true;
|
72
|
+
}
|
74
73
|
|
75
|
-
|
76
|
-
|
74
|
+
void _mongocrypt_buffer_init_size(_mongocrypt_buffer_t *buf, uint32_t len) {
|
75
|
+
BSON_ASSERT_PARAM(buf);
|
77
76
|
|
78
|
-
|
79
|
-
|
77
|
+
_mongocrypt_buffer_init(buf);
|
78
|
+
_mongocrypt_buffer_resize(buf, len);
|
80
79
|
}
|
81
80
|
|
81
|
+
void _mongocrypt_buffer_steal(_mongocrypt_buffer_t *buf, _mongocrypt_buffer_t *src) {
|
82
|
+
BSON_ASSERT_PARAM(buf);
|
83
|
+
BSON_ASSERT_PARAM(src);
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
if (!src->owned) {
|
86
|
+
_mongocrypt_buffer_copy_to(src, buf);
|
87
|
+
_mongocrypt_buffer_init(src);
|
88
|
+
return;
|
89
|
+
}
|
87
90
|
|
88
|
-
|
89
|
-
|
91
|
+
buf->data = src->data;
|
92
|
+
buf->len = src->len;
|
93
|
+
buf->owned = true;
|
94
|
+
_mongocrypt_buffer_init(src);
|
90
95
|
}
|
91
96
|
|
97
|
+
bool _mongocrypt_buffer_from_binary_iter(_mongocrypt_buffer_t *buf, bson_iter_t *iter) {
|
98
|
+
BSON_ASSERT_PARAM(buf);
|
99
|
+
BSON_ASSERT_PARAM(iter);
|
100
|
+
|
101
|
+
if (!BSON_ITER_HOLDS_BINARY(iter)) {
|
102
|
+
return false;
|
103
|
+
}
|
104
|
+
_mongocrypt_buffer_init(buf);
|
105
|
+
bson_iter_binary(iter, &buf->subtype, &buf->len, (const uint8_t **)&buf->data);
|
106
|
+
buf->owned = false;
|
107
|
+
return true;
|
108
|
+
}
|
92
109
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
BSON_ASSERT_PARAM (buf);
|
97
|
-
BSON_ASSERT_PARAM (src);
|
110
|
+
bool _mongocrypt_buffer_copy_from_binary_iter(_mongocrypt_buffer_t *buf, bson_iter_t *iter) {
|
111
|
+
BSON_ASSERT_PARAM(buf);
|
112
|
+
BSON_ASSERT_PARAM(iter);
|
98
113
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
return;
|
103
|
-
}
|
114
|
+
if (!_mongocrypt_buffer_from_binary_iter(buf, iter)) {
|
115
|
+
return false;
|
116
|
+
}
|
104
117
|
|
105
|
-
|
106
|
-
|
107
|
-
buf->owned = true;
|
108
|
-
_mongocrypt_buffer_init (src);
|
118
|
+
_make_owned(buf);
|
119
|
+
return true;
|
109
120
|
}
|
110
121
|
|
111
|
-
bool
|
112
|
-
|
113
|
-
|
114
|
-
{
|
115
|
-
BSON_ASSERT_PARAM (buf);
|
116
|
-
BSON_ASSERT_PARAM (iter);
|
122
|
+
bool _mongocrypt_buffer_from_document_iter(_mongocrypt_buffer_t *buf, bson_iter_t *iter) {
|
123
|
+
BSON_ASSERT_PARAM(buf);
|
124
|
+
BSON_ASSERT_PARAM(iter);
|
117
125
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
return true;
|
126
|
+
if (!BSON_ITER_HOLDS_DOCUMENT(iter)) {
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
_mongocrypt_buffer_init(buf);
|
130
|
+
bson_iter_document(iter, &buf->len, (const uint8_t **)&buf->data);
|
131
|
+
buf->owned = false;
|
132
|
+
return true;
|
126
133
|
}
|
127
134
|
|
135
|
+
bool _mongocrypt_buffer_copy_from_document_iter(_mongocrypt_buffer_t *buf, bson_iter_t *iter) {
|
136
|
+
BSON_ASSERT_PARAM(buf);
|
137
|
+
BSON_ASSERT_PARAM(iter);
|
128
138
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
139
|
+
if (!_mongocrypt_buffer_from_document_iter(buf, iter)) {
|
140
|
+
return false;
|
141
|
+
}
|
142
|
+
_make_owned(buf);
|
143
|
+
return true;
|
144
|
+
}
|
135
145
|
|
136
|
-
|
137
|
-
|
138
|
-
|
146
|
+
void _mongocrypt_buffer_steal_from_bson(_mongocrypt_buffer_t *buf, bson_t *bson) {
|
147
|
+
BSON_ASSERT_PARAM(buf);
|
148
|
+
BSON_ASSERT_PARAM(bson);
|
139
149
|
|
140
|
-
|
141
|
-
|
150
|
+
_mongocrypt_buffer_init(buf);
|
151
|
+
buf->data = bson_destroy_with_steal(bson, true, &buf->len);
|
152
|
+
buf->owned = true;
|
142
153
|
}
|
143
154
|
|
155
|
+
void _mongocrypt_buffer_from_bson(_mongocrypt_buffer_t *buf, const bson_t *bson) {
|
156
|
+
BSON_ASSERT_PARAM(buf);
|
157
|
+
BSON_ASSERT_PARAM(bson);
|
158
|
+
|
159
|
+
_mongocrypt_buffer_init(buf);
|
160
|
+
buf->data = (uint8_t *)bson_get_data(bson);
|
161
|
+
buf->len = bson->len;
|
162
|
+
buf->owned = false;
|
163
|
+
}
|
144
164
|
|
145
|
-
bool
|
146
|
-
|
147
|
-
|
148
|
-
{
|
149
|
-
BSON_ASSERT_PARAM (buf);
|
150
|
-
BSON_ASSERT_PARAM (iter);
|
165
|
+
bool _mongocrypt_buffer_to_bson(const _mongocrypt_buffer_t *buf, bson_t *bson) {
|
166
|
+
BSON_ASSERT_PARAM(buf);
|
167
|
+
BSON_ASSERT_PARAM(bson);
|
151
168
|
|
152
|
-
|
153
|
-
return false;
|
154
|
-
}
|
155
|
-
_mongocrypt_buffer_init (buf);
|
156
|
-
bson_iter_document (iter, &buf->len, (const uint8_t **) &buf->data);
|
157
|
-
buf->owned = false;
|
158
|
-
return true;
|
169
|
+
return bson_init_static(bson, buf->data, buf->len);
|
159
170
|
}
|
160
171
|
|
172
|
+
bool _mongocrypt_buffer_append(const _mongocrypt_buffer_t *buf, bson_t *bson, const char *key, int key_len) {
|
173
|
+
BSON_ASSERT_PARAM(buf);
|
174
|
+
BSON_ASSERT_PARAM(bson);
|
175
|
+
BSON_ASSERT_PARAM(key);
|
161
176
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
{
|
166
|
-
|
167
|
-
|
177
|
+
return bson_append_binary(bson, key, key_len, buf->subtype, buf->data, buf->len);
|
178
|
+
}
|
179
|
+
|
180
|
+
void _mongocrypt_buffer_from_binary(_mongocrypt_buffer_t *buf, const mongocrypt_binary_t *binary) {
|
181
|
+
BSON_ASSERT_PARAM(buf);
|
182
|
+
BSON_ASSERT_PARAM(binary);
|
168
183
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
return true;
|
184
|
+
_mongocrypt_buffer_init(buf);
|
185
|
+
buf->data = binary->data;
|
186
|
+
buf->len = binary->len;
|
187
|
+
buf->owned = false;
|
174
188
|
}
|
175
189
|
|
190
|
+
void _mongocrypt_buffer_copy_from_binary(_mongocrypt_buffer_t *buf, const struct _mongocrypt_binary_t *binary) {
|
191
|
+
BSON_ASSERT_PARAM(buf);
|
192
|
+
BSON_ASSERT_PARAM(binary);
|
193
|
+
|
194
|
+
_mongocrypt_buffer_from_binary(buf, binary);
|
195
|
+
_make_owned(buf);
|
196
|
+
}
|
176
197
|
|
177
|
-
void
|
178
|
-
|
179
|
-
|
180
|
-
BSON_ASSERT_PARAM (buf);
|
181
|
-
BSON_ASSERT_PARAM (bson);
|
198
|
+
void _mongocrypt_buffer_to_binary(const _mongocrypt_buffer_t *buf, mongocrypt_binary_t *binary) {
|
199
|
+
BSON_ASSERT_PARAM(buf);
|
200
|
+
BSON_ASSERT_PARAM(binary);
|
182
201
|
|
183
|
-
|
184
|
-
|
185
|
-
buf->owned = true;
|
202
|
+
binary->data = buf->data;
|
203
|
+
binary->len = buf->len;
|
186
204
|
}
|
187
205
|
|
206
|
+
void _mongocrypt_buffer_copy_to(const _mongocrypt_buffer_t *src, _mongocrypt_buffer_t *dst) {
|
207
|
+
if (src == dst) {
|
208
|
+
return;
|
209
|
+
}
|
210
|
+
|
211
|
+
BSON_ASSERT_PARAM(src);
|
212
|
+
BSON_ASSERT_PARAM(dst);
|
213
|
+
|
214
|
+
_mongocrypt_buffer_cleanup(dst);
|
215
|
+
if (src->len == 0) {
|
216
|
+
return;
|
217
|
+
}
|
188
218
|
|
189
|
-
|
190
|
-
|
191
|
-
{
|
192
|
-
BSON_ASSERT_PARAM (buf);
|
193
|
-
BSON_ASSERT_PARAM (bson);
|
219
|
+
dst->data = bson_malloc((size_t)src->len);
|
220
|
+
BSON_ASSERT(dst->data);
|
194
221
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
222
|
+
memcpy(dst->data, src->data, src->len);
|
223
|
+
dst->len = src->len;
|
224
|
+
dst->subtype = src->subtype;
|
225
|
+
dst->owned = true;
|
199
226
|
}
|
200
227
|
|
228
|
+
void _mongocrypt_buffer_set_to(const _mongocrypt_buffer_t *src, _mongocrypt_buffer_t *dst) {
|
229
|
+
if (src == dst) {
|
230
|
+
return;
|
231
|
+
}
|
201
232
|
|
202
|
-
|
203
|
-
|
204
|
-
{
|
205
|
-
BSON_ASSERT_PARAM (buf);
|
206
|
-
BSON_ASSERT_PARAM (bson);
|
233
|
+
BSON_ASSERT_PARAM(src);
|
234
|
+
BSON_ASSERT_PARAM(dst);
|
207
235
|
|
208
|
-
|
236
|
+
dst->data = src->data;
|
237
|
+
dst->len = src->len;
|
238
|
+
dst->subtype = src->subtype;
|
239
|
+
dst->owned = false;
|
209
240
|
}
|
210
241
|
|
242
|
+
int _mongocrypt_buffer_cmp(const _mongocrypt_buffer_t *a, const _mongocrypt_buffer_t *b) {
|
243
|
+
BSON_ASSERT_PARAM(a);
|
244
|
+
BSON_ASSERT_PARAM(b);
|
211
245
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
BSON_ASSERT_PARAM (bson);
|
220
|
-
BSON_ASSERT_PARAM (key);
|
221
|
-
|
222
|
-
return bson_append_binary (
|
223
|
-
bson, key, key_len, buf->subtype, buf->data, buf->len);
|
246
|
+
if (a->len != b->len) {
|
247
|
+
return a->len > b->len ? 1 : -1;
|
248
|
+
}
|
249
|
+
if (0 == a->len) {
|
250
|
+
return 0;
|
251
|
+
}
|
252
|
+
return memcmp(a->data, b->data, a->len);
|
224
253
|
}
|
225
254
|
|
255
|
+
void _mongocrypt_buffer_cleanup(_mongocrypt_buffer_t *buf) {
|
256
|
+
if (buf && buf->owned) {
|
257
|
+
bson_free(buf->data);
|
258
|
+
}
|
259
|
+
}
|
226
260
|
|
227
|
-
|
228
|
-
|
229
|
-
const mongocrypt_binary_t *binary)
|
230
|
-
{
|
231
|
-
BSON_ASSERT_PARAM (buf);
|
232
|
-
BSON_ASSERT_PARAM (binary);
|
261
|
+
bool _mongocrypt_buffer_empty(const _mongocrypt_buffer_t *buf) {
|
262
|
+
BSON_ASSERT_PARAM(buf);
|
233
263
|
|
234
|
-
|
235
|
-
buf->data = binary->data;
|
236
|
-
buf->len = binary->len;
|
237
|
-
buf->owned = false;
|
264
|
+
return buf->data == NULL;
|
238
265
|
}
|
239
266
|
|
267
|
+
bool _mongocrypt_buffer_to_bson_value(_mongocrypt_buffer_t *plaintext, uint8_t type, bson_value_t *out) {
|
268
|
+
bool ret = false;
|
269
|
+
bson_iter_t iter;
|
270
|
+
bson_t wrapper;
|
271
|
+
uint32_t data_len;
|
272
|
+
uint32_t le_data_len;
|
273
|
+
uint8_t *data;
|
274
|
+
uint8_t data_prefix;
|
275
|
+
|
276
|
+
BSON_ASSERT_PARAM(plaintext);
|
277
|
+
BSON_ASSERT_PARAM(out);
|
278
|
+
|
279
|
+
data_prefix = INT32_LEN /* adds document size */
|
280
|
+
+ TYPE_LEN /* element type */
|
281
|
+
+ NULL_BYTE_LEN; /* and doc's null byte terminator */
|
282
|
+
|
283
|
+
BSON_ASSERT(plaintext->len <= UINT32_MAX - data_prefix - NULL_BYTE_LEN);
|
240
284
|
|
241
|
-
|
242
|
-
|
243
|
-
const struct _mongocrypt_binary_t *binary)
|
244
|
-
{
|
245
|
-
BSON_ASSERT_PARAM (buf);
|
246
|
-
BSON_ASSERT_PARAM (binary);
|
285
|
+
data_len = (plaintext->len + data_prefix + NULL_BYTE_LEN);
|
286
|
+
le_data_len = BSON_UINT32_TO_LE(data_len);
|
247
287
|
|
248
|
-
|
249
|
-
|
288
|
+
data = bson_malloc0(data_len);
|
289
|
+
BSON_ASSERT(data);
|
290
|
+
|
291
|
+
memcpy(data + data_prefix, plaintext->data, plaintext->len);
|
292
|
+
memcpy(data, &le_data_len, INT32_LEN);
|
293
|
+
memcpy(data + INT32_LEN, &type, TYPE_LEN);
|
294
|
+
data[data_len - 1] = NULL_BYTE_VAL;
|
295
|
+
|
296
|
+
if (!bson_init_static(&wrapper, data, data_len)) {
|
297
|
+
goto fail;
|
298
|
+
}
|
299
|
+
|
300
|
+
if (!bson_validate(&wrapper, BSON_VALIDATE_NONE, NULL)) {
|
301
|
+
goto fail;
|
302
|
+
}
|
303
|
+
|
304
|
+
if (!bson_iter_init_find(&iter, &wrapper, "")) {
|
305
|
+
goto fail;
|
306
|
+
}
|
307
|
+
bson_value_copy(bson_iter_value(&iter), out);
|
308
|
+
|
309
|
+
/* Due to an open libbson bug (CDRIVER-3340), give an empty
|
310
|
+
* binary payload a real address. TODO: remove this after
|
311
|
+
* CDRIVER-3340 is fixed. */
|
312
|
+
if (out->value_type == BSON_TYPE_BINARY && 0 == out->value.v_binary.data_len) {
|
313
|
+
out->value.v_binary.data = bson_malloc(1); /* Freed in bson_value_destroy */
|
314
|
+
}
|
315
|
+
|
316
|
+
ret = true;
|
317
|
+
fail:
|
318
|
+
bson_free(data);
|
319
|
+
return ret;
|
250
320
|
}
|
251
321
|
|
322
|
+
void _mongocrypt_buffer_from_iter(_mongocrypt_buffer_t *plaintext, bson_iter_t *iter) {
|
323
|
+
bson_t wrapper = BSON_INITIALIZER;
|
324
|
+
int32_t offset = INT32_LEN /* skips document size */
|
325
|
+
+ TYPE_LEN /* element type */
|
326
|
+
+ NULL_BYTE_LEN; /* and the key's null byte terminator */
|
327
|
+
|
328
|
+
uint8_t *wrapper_data;
|
329
|
+
|
330
|
+
BSON_ASSERT_PARAM(plaintext);
|
331
|
+
BSON_ASSERT_PARAM(iter);
|
332
|
+
|
333
|
+
/* It is not straightforward to transform a bson_value_t to a string of
|
334
|
+
* bytes. As a workaround, we wrap the value in a bson document with an empty
|
335
|
+
* key, then use the raw buffer from inside the new bson_t, skipping the
|
336
|
+
* length and type header information and the key name. */
|
337
|
+
bson_append_iter(&wrapper, "", 0, iter);
|
338
|
+
wrapper_data = ((uint8_t *)bson_get_data(&wrapper));
|
339
|
+
BSON_ASSERT(wrapper.len >= (uint32_t)offset + NULL_BYTE_LEN);
|
340
|
+
plaintext->len = wrapper.len - (uint32_t)offset - NULL_BYTE_LEN; /* the final null byte */
|
341
|
+
plaintext->data = bson_malloc(plaintext->len);
|
342
|
+
BSON_ASSERT(plaintext->data);
|
252
343
|
|
253
|
-
|
254
|
-
|
255
|
-
mongocrypt_binary_t *binary)
|
256
|
-
{
|
257
|
-
BSON_ASSERT_PARAM (buf);
|
258
|
-
BSON_ASSERT_PARAM (binary);
|
344
|
+
plaintext->owned = true;
|
345
|
+
memcpy(plaintext->data, wrapper_data + offset, plaintext->len);
|
259
346
|
|
260
|
-
|
261
|
-
binary->len = buf->len;
|
347
|
+
bson_destroy(&wrapper);
|
262
348
|
}
|
263
349
|
|
350
|
+
bool _mongocrypt_buffer_from_uuid_iter(_mongocrypt_buffer_t *buf, bson_iter_t *iter) {
|
351
|
+
const uint8_t *data;
|
352
|
+
bson_subtype_t subtype;
|
353
|
+
uint32_t len;
|
264
354
|
|
265
|
-
|
266
|
-
|
267
|
-
_mongocrypt_buffer_t *dst)
|
268
|
-
{
|
269
|
-
if (src == dst) {
|
270
|
-
return;
|
271
|
-
}
|
355
|
+
BSON_ASSERT_PARAM(buf);
|
356
|
+
BSON_ASSERT_PARAM(iter);
|
272
357
|
|
273
|
-
|
274
|
-
|
358
|
+
if (!BSON_ITER_HOLDS_BINARY(iter)) {
|
359
|
+
return false;
|
360
|
+
}
|
361
|
+
bson_iter_binary(iter, &subtype, &len, &data);
|
362
|
+
if (subtype != BSON_SUBTYPE_UUID) {
|
363
|
+
return false;
|
364
|
+
}
|
365
|
+
if (len != UUID_LEN) {
|
366
|
+
return false;
|
367
|
+
}
|
368
|
+
_mongocrypt_buffer_init(buf);
|
369
|
+
buf->data = (uint8_t *)data;
|
370
|
+
buf->len = len;
|
371
|
+
buf->subtype = subtype;
|
372
|
+
buf->owned = false;
|
373
|
+
return true;
|
374
|
+
}
|
375
|
+
|
376
|
+
bool _mongocrypt_buffer_copy_from_uuid_iter(_mongocrypt_buffer_t *buf, bson_iter_t *iter) {
|
377
|
+
BSON_ASSERT_PARAM(buf);
|
378
|
+
BSON_ASSERT_PARAM(iter);
|
275
379
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
380
|
+
if (!_mongocrypt_buffer_from_uuid_iter(buf, iter)) {
|
381
|
+
return false;
|
382
|
+
}
|
383
|
+
_make_owned(buf);
|
384
|
+
return true;
|
385
|
+
}
|
280
386
|
|
281
|
-
|
282
|
-
|
387
|
+
bool _mongocrypt_buffer_is_uuid(_mongocrypt_buffer_t *buf) {
|
388
|
+
BSON_ASSERT_PARAM(buf);
|
283
389
|
|
284
|
-
|
285
|
-
dst->len = src->len;
|
286
|
-
dst->subtype = src->subtype;
|
287
|
-
dst->owned = true;
|
390
|
+
return buf->len == UUID_LEN && buf->subtype == BSON_SUBTYPE_UUID;
|
288
391
|
}
|
289
392
|
|
393
|
+
void _mongocrypt_buffer_copy_from_hex(_mongocrypt_buffer_t *buf, const char *hex) {
|
394
|
+
uint32_t i;
|
395
|
+
size_t hex_len;
|
396
|
+
|
397
|
+
BSON_ASSERT_PARAM(buf);
|
398
|
+
BSON_ASSERT_PARAM(hex);
|
290
399
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
return;
|
297
|
-
}
|
400
|
+
hex_len = strlen(hex);
|
401
|
+
if (hex_len == 0) {
|
402
|
+
_mongocrypt_buffer_init(buf);
|
403
|
+
return;
|
404
|
+
}
|
298
405
|
|
299
|
-
|
300
|
-
|
406
|
+
BSON_ASSERT(hex_len / 2u <= UINT32_MAX);
|
407
|
+
buf->len = (uint32_t)(hex_len / 2u);
|
408
|
+
buf->data = bson_malloc(buf->len);
|
409
|
+
BSON_ASSERT(buf->data);
|
301
410
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
411
|
+
buf->owned = true;
|
412
|
+
for (i = 0; i < buf->len; i++) {
|
413
|
+
uint32_t tmp;
|
414
|
+
BSON_ASSERT(i <= UINT32_MAX / 2);
|
415
|
+
BSON_ASSERT(sscanf(hex + (2 * i), "%02x", &tmp));
|
416
|
+
*(buf->data + i) = (uint8_t)tmp;
|
417
|
+
}
|
306
418
|
}
|
307
419
|
|
420
|
+
int _mongocrypt_buffer_cmp_hex(_mongocrypt_buffer_t *buf, const char *hex) {
|
421
|
+
_mongocrypt_buffer_t tmp;
|
422
|
+
int res;
|
308
423
|
|
309
|
-
|
310
|
-
|
311
|
-
const _mongocrypt_buffer_t *b)
|
312
|
-
{
|
313
|
-
BSON_ASSERT_PARAM (a);
|
314
|
-
BSON_ASSERT_PARAM (b);
|
424
|
+
BSON_ASSERT_PARAM(buf);
|
425
|
+
BSON_ASSERT_PARAM(hex);
|
315
426
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
return 0;
|
321
|
-
}
|
322
|
-
return memcmp (a->data, b->data, a->len);
|
427
|
+
_mongocrypt_buffer_copy_from_hex(&tmp, hex);
|
428
|
+
res = _mongocrypt_buffer_cmp(buf, &tmp);
|
429
|
+
_mongocrypt_buffer_cleanup(&tmp);
|
430
|
+
return res;
|
323
431
|
}
|
324
432
|
|
433
|
+
char *_mongocrypt_buffer_to_hex(_mongocrypt_buffer_t *buf) {
|
434
|
+
BSON_ASSERT_PARAM(buf);
|
435
|
+
/* since buf->len is a uint32_t, even doubling it won't bring it anywhere
|
436
|
+
* near to SIZE_MAX */
|
325
437
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
438
|
+
char *hex = bson_malloc0(buf->len * 2 + 1);
|
439
|
+
BSON_ASSERT(hex);
|
440
|
+
|
441
|
+
char *out = hex;
|
442
|
+
|
443
|
+
for (uint32_t i = 0; i < buf->len; i++, out += 2) {
|
444
|
+
sprintf(out, "%02X", buf->data[i]);
|
445
|
+
}
|
446
|
+
return hex;
|
332
447
|
}
|
333
448
|
|
449
|
+
bool _mongocrypt_buffer_concat(_mongocrypt_buffer_t *dst, const _mongocrypt_buffer_t *srcs, uint32_t num_srcs) {
|
450
|
+
uint32_t total = 0;
|
451
|
+
uint32_t offset;
|
452
|
+
uint32_t i;
|
453
|
+
|
454
|
+
BSON_ASSERT_PARAM(dst);
|
455
|
+
BSON_ASSERT_PARAM(srcs);
|
334
456
|
|
335
|
-
|
336
|
-
|
337
|
-
{
|
338
|
-
BSON_ASSERT_PARAM (buf);
|
457
|
+
for (i = 0; i < num_srcs; i++) {
|
458
|
+
uint32_t old_total = total;
|
339
459
|
|
340
|
-
|
460
|
+
total += srcs[i].len;
|
461
|
+
/* If the previous operation overflowed, then total will have a smaller
|
462
|
+
* value than previously. */
|
463
|
+
if (total < old_total) {
|
464
|
+
return false;
|
465
|
+
}
|
466
|
+
}
|
467
|
+
|
468
|
+
_mongocrypt_buffer_init(dst);
|
469
|
+
_mongocrypt_buffer_resize(dst, total);
|
470
|
+
offset = 0;
|
471
|
+
for (i = 0; i < num_srcs; i++) {
|
472
|
+
if (srcs[i].len) {
|
473
|
+
memcpy(dst->data + offset, srcs[i].data, srcs[i].len);
|
474
|
+
}
|
475
|
+
offset += srcs[i].len;
|
476
|
+
}
|
477
|
+
return true;
|
341
478
|
}
|
342
479
|
|
343
|
-
|
344
|
-
|
345
|
-
uint8_t type,
|
346
|
-
bson_value_t *out)
|
347
|
-
{
|
348
|
-
bool ret = false;
|
349
|
-
bson_iter_t iter;
|
350
|
-
bson_t wrapper;
|
351
|
-
uint32_t data_len;
|
352
|
-
uint32_t le_data_len;
|
353
|
-
uint8_t *data;
|
354
|
-
uint8_t data_prefix;
|
480
|
+
struct _mongocrypt_binary_t *_mongocrypt_buffer_as_binary(_mongocrypt_buffer_t *buf) {
|
481
|
+
BSON_ASSERT_PARAM(buf);
|
355
482
|
|
356
|
-
|
357
|
-
|
483
|
+
buf->bin.data = buf->data;
|
484
|
+
buf->bin.len = buf->len;
|
485
|
+
return &buf->bin;
|
486
|
+
}
|
358
487
|
|
359
|
-
|
360
|
-
|
361
|
-
|
488
|
+
bool _mongocrypt_buffer_copy_from_data_and_size(_mongocrypt_buffer_t *buf, const uint8_t *data, size_t len) {
|
489
|
+
BSON_ASSERT_PARAM(buf);
|
490
|
+
BSON_ASSERT_PARAM(data);
|
362
491
|
|
363
|
-
|
492
|
+
_mongocrypt_buffer_init(buf);
|
364
493
|
|
365
|
-
|
366
|
-
|
494
|
+
if (!size_to_uint32(len, &buf->len)) {
|
495
|
+
return false;
|
496
|
+
}
|
367
497
|
|
368
|
-
|
369
|
-
|
498
|
+
if ((buf->data = bson_malloc(len))) {
|
499
|
+
memcpy(buf->data, data, len);
|
500
|
+
buf->owned = true;
|
501
|
+
}
|
370
502
|
|
371
|
-
|
372
|
-
|
373
|
-
memcpy (data + INT32_LEN, &type, TYPE_LEN);
|
374
|
-
data[data_len - 1] = NULL_BYTE_VAL;
|
503
|
+
return true;
|
504
|
+
}
|
375
505
|
|
376
|
-
|
377
|
-
|
378
|
-
|
506
|
+
bool _mongocrypt_buffer_steal_from_data_and_size(_mongocrypt_buffer_t *buf, uint8_t *data, size_t len) {
|
507
|
+
BSON_ASSERT_PARAM(buf);
|
508
|
+
BSON_ASSERT_PARAM(data);
|
379
509
|
|
380
|
-
|
381
|
-
|
382
|
-
|
510
|
+
_mongocrypt_buffer_init(buf);
|
511
|
+
if (!size_to_uint32(len, &buf->len)) {
|
512
|
+
return false;
|
513
|
+
}
|
514
|
+
buf->data = data;
|
515
|
+
buf->owned = true;
|
516
|
+
return true;
|
517
|
+
}
|
383
518
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
bson_value_copy (bson_iter_value (&iter), out);
|
519
|
+
bool _mongocrypt_buffer_steal_from_string(_mongocrypt_buffer_t *buf, char *str) {
|
520
|
+
BSON_ASSERT_PARAM(buf);
|
521
|
+
BSON_ASSERT_PARAM(str);
|
388
522
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
523
|
+
_mongocrypt_buffer_init(buf);
|
524
|
+
if (!size_to_uint32(strlen(str), &buf->len)) {
|
525
|
+
return false;
|
526
|
+
}
|
527
|
+
buf->data = (uint8_t *)str;
|
528
|
+
buf->owned = true;
|
529
|
+
return true;
|
530
|
+
}
|
397
531
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
bool
|
438
|
-
_mongocrypt_buffer_from_uuid_iter (_mongocrypt_buffer_t *buf, bson_iter_t *iter)
|
439
|
-
{
|
440
|
-
const uint8_t *data;
|
441
|
-
bson_subtype_t subtype;
|
442
|
-
uint32_t len;
|
443
|
-
|
444
|
-
BSON_ASSERT_PARAM (buf);
|
445
|
-
BSON_ASSERT_PARAM (iter);
|
446
|
-
|
447
|
-
if (!BSON_ITER_HOLDS_BINARY (iter)) {
|
448
|
-
return false;
|
449
|
-
}
|
450
|
-
bson_iter_binary (iter, &subtype, &len, &data);
|
451
|
-
if (subtype != BSON_SUBTYPE_UUID) {
|
452
|
-
return false;
|
453
|
-
}
|
454
|
-
if (len != UUID_LEN) {
|
455
|
-
return false;
|
456
|
-
}
|
457
|
-
_mongocrypt_buffer_init (buf);
|
458
|
-
buf->data = (uint8_t *) data;
|
459
|
-
buf->len = len;
|
460
|
-
buf->subtype = subtype;
|
461
|
-
buf->owned = false;
|
462
|
-
return true;
|
463
|
-
}
|
464
|
-
|
465
|
-
|
466
|
-
bool
|
467
|
-
_mongocrypt_buffer_copy_from_uuid_iter (_mongocrypt_buffer_t *buf,
|
468
|
-
bson_iter_t *iter)
|
469
|
-
{
|
470
|
-
BSON_ASSERT_PARAM (buf);
|
471
|
-
BSON_ASSERT_PARAM (iter);
|
472
|
-
|
473
|
-
if (!_mongocrypt_buffer_from_uuid_iter (buf, iter)) {
|
474
|
-
return false;
|
475
|
-
}
|
476
|
-
_make_owned (buf);
|
477
|
-
return true;
|
478
|
-
}
|
479
|
-
|
480
|
-
bool
|
481
|
-
_mongocrypt_buffer_is_uuid (_mongocrypt_buffer_t *buf)
|
482
|
-
{
|
483
|
-
BSON_ASSERT_PARAM (buf);
|
484
|
-
|
485
|
-
return buf->len == UUID_LEN && buf->subtype == BSON_SUBTYPE_UUID;
|
486
|
-
}
|
487
|
-
|
488
|
-
void
|
489
|
-
_mongocrypt_buffer_copy_from_hex (_mongocrypt_buffer_t *buf, const char *hex)
|
490
|
-
{
|
491
|
-
uint32_t i;
|
492
|
-
size_t hex_len;
|
493
|
-
|
494
|
-
BSON_ASSERT_PARAM (buf);
|
495
|
-
BSON_ASSERT_PARAM (hex);
|
496
|
-
|
497
|
-
hex_len = strlen (hex);
|
498
|
-
if (hex_len == 0) {
|
499
|
-
_mongocrypt_buffer_init (buf);
|
500
|
-
return;
|
501
|
-
}
|
502
|
-
|
503
|
-
BSON_ASSERT (hex_len / 2u <= UINT32_MAX);
|
504
|
-
buf->len = (uint32_t) (hex_len / 2u);
|
505
|
-
buf->data = bson_malloc (buf->len);
|
506
|
-
BSON_ASSERT (buf->data);
|
507
|
-
|
508
|
-
buf->owned = true;
|
509
|
-
for (i = 0; i < buf->len; i++) {
|
510
|
-
uint32_t tmp;
|
511
|
-
BSON_ASSERT (i <= UINT32_MAX / 2);
|
512
|
-
BSON_ASSERT (sscanf (hex + (2 * i), "%02x", &tmp));
|
513
|
-
*(buf->data + i) = (uint8_t) tmp;
|
514
|
-
}
|
515
|
-
}
|
516
|
-
|
517
|
-
int
|
518
|
-
_mongocrypt_buffer_cmp_hex (_mongocrypt_buffer_t *buf, const char *hex)
|
519
|
-
{
|
520
|
-
_mongocrypt_buffer_t tmp;
|
521
|
-
int res;
|
522
|
-
|
523
|
-
BSON_ASSERT_PARAM (buf);
|
524
|
-
BSON_ASSERT_PARAM (hex);
|
525
|
-
|
526
|
-
_mongocrypt_buffer_copy_from_hex (&tmp, hex);
|
527
|
-
res = _mongocrypt_buffer_cmp (buf, &tmp);
|
528
|
-
_mongocrypt_buffer_cleanup (&tmp);
|
529
|
-
return res;
|
530
|
-
}
|
531
|
-
|
532
|
-
char *
|
533
|
-
_mongocrypt_buffer_to_hex (_mongocrypt_buffer_t *buf)
|
534
|
-
{
|
535
|
-
BSON_ASSERT_PARAM (buf);
|
536
|
-
/* since buf->len is a uint32_t, even doubling it won't bring it anywhere
|
537
|
-
* near to SIZE_MAX */
|
538
|
-
|
539
|
-
char *hex = bson_malloc0 (buf->len * 2 + 1);
|
540
|
-
BSON_ASSERT (hex);
|
541
|
-
|
542
|
-
char *out = hex;
|
543
|
-
|
544
|
-
for (uint32_t i = 0; i < buf->len; i++, out += 2) {
|
545
|
-
sprintf (out, "%02X", buf->data[i]);
|
546
|
-
}
|
547
|
-
return hex;
|
548
|
-
}
|
549
|
-
|
550
|
-
bool
|
551
|
-
_mongocrypt_buffer_concat (_mongocrypt_buffer_t *dst,
|
552
|
-
const _mongocrypt_buffer_t *srcs,
|
553
|
-
uint32_t num_srcs)
|
554
|
-
{
|
555
|
-
uint32_t total = 0;
|
556
|
-
uint32_t offset;
|
557
|
-
uint32_t i;
|
558
|
-
|
559
|
-
BSON_ASSERT_PARAM (dst);
|
560
|
-
BSON_ASSERT_PARAM (srcs);
|
561
|
-
|
562
|
-
for (i = 0; i < num_srcs; i++) {
|
563
|
-
uint32_t old_total = total;
|
564
|
-
|
565
|
-
total += srcs[i].len;
|
566
|
-
/* If the previous operation overflowed, then total will have a smaller
|
567
|
-
* value than previously. */
|
568
|
-
if (total < old_total) {
|
569
|
-
return false;
|
570
|
-
}
|
571
|
-
}
|
572
|
-
|
573
|
-
_mongocrypt_buffer_init (dst);
|
574
|
-
_mongocrypt_buffer_resize (dst, total);
|
575
|
-
offset = 0;
|
576
|
-
for (i = 0; i < num_srcs; i++) {
|
577
|
-
if (srcs[i].len) {
|
578
|
-
memcpy (dst->data + offset, srcs[i].data, srcs[i].len);
|
579
|
-
}
|
580
|
-
offset += srcs[i].len;
|
581
|
-
}
|
582
|
-
return true;
|
583
|
-
}
|
584
|
-
|
585
|
-
struct _mongocrypt_binary_t *
|
586
|
-
_mongocrypt_buffer_as_binary (_mongocrypt_buffer_t *buf)
|
587
|
-
{
|
588
|
-
BSON_ASSERT_PARAM (buf);
|
589
|
-
|
590
|
-
buf->bin.data = buf->data;
|
591
|
-
buf->bin.len = buf->len;
|
592
|
-
return &buf->bin;
|
593
|
-
}
|
594
|
-
|
595
|
-
bool
|
596
|
-
_mongocrypt_buffer_copy_from_data_and_size (_mongocrypt_buffer_t *buf,
|
597
|
-
const uint8_t *data,
|
598
|
-
size_t len)
|
599
|
-
{
|
600
|
-
BSON_ASSERT_PARAM (buf);
|
601
|
-
BSON_ASSERT_PARAM (data);
|
602
|
-
|
603
|
-
_mongocrypt_buffer_init (buf);
|
604
|
-
|
605
|
-
if (!size_to_uint32 (len, &buf->len)) {
|
606
|
-
return false;
|
607
|
-
}
|
608
|
-
buf->data = bson_malloc (len);
|
609
|
-
memcpy (buf->data, data, len);
|
610
|
-
buf->owned = true;
|
611
|
-
return true;
|
612
|
-
}
|
613
|
-
|
614
|
-
bool
|
615
|
-
_mongocrypt_buffer_steal_from_data_and_size (_mongocrypt_buffer_t *buf,
|
616
|
-
uint8_t *data,
|
617
|
-
size_t len)
|
618
|
-
{
|
619
|
-
BSON_ASSERT_PARAM (buf);
|
620
|
-
BSON_ASSERT_PARAM (data);
|
621
|
-
|
622
|
-
_mongocrypt_buffer_init (buf);
|
623
|
-
if (!size_to_uint32 (len, &buf->len)) {
|
624
|
-
return false;
|
625
|
-
}
|
626
|
-
buf->data = data;
|
627
|
-
buf->owned = true;
|
628
|
-
return true;
|
629
|
-
}
|
630
|
-
|
631
|
-
bool
|
632
|
-
_mongocrypt_buffer_steal_from_string (_mongocrypt_buffer_t *buf, char *str)
|
633
|
-
{
|
634
|
-
BSON_ASSERT_PARAM (buf);
|
635
|
-
BSON_ASSERT_PARAM (str);
|
636
|
-
|
637
|
-
_mongocrypt_buffer_init (buf);
|
638
|
-
if (!size_to_uint32 (strlen (str), &buf->len)) {
|
639
|
-
return false;
|
640
|
-
}
|
641
|
-
buf->data = (uint8_t *) str;
|
642
|
-
buf->owned = true;
|
643
|
-
return true;
|
644
|
-
}
|
645
|
-
|
646
|
-
bool
|
647
|
-
_mongocrypt_buffer_from_string (_mongocrypt_buffer_t *buf, const char *str)
|
648
|
-
{
|
649
|
-
BSON_ASSERT_PARAM (buf);
|
650
|
-
BSON_ASSERT_PARAM (str);
|
651
|
-
|
652
|
-
_mongocrypt_buffer_init (buf);
|
653
|
-
if (!size_to_uint32 (strlen (str), &buf->len)) {
|
654
|
-
return false;
|
655
|
-
}
|
656
|
-
buf->data = (uint8_t *) str;
|
657
|
-
buf->owned = false;
|
658
|
-
return true;
|
659
|
-
}
|
660
|
-
|
661
|
-
void
|
662
|
-
_mongocrypt_buffer_copy_from_uint64_le (_mongocrypt_buffer_t *buf,
|
663
|
-
uint64_t value)
|
664
|
-
{
|
665
|
-
uint64_t value_le = MONGOCRYPT_UINT64_TO_LE (value);
|
666
|
-
|
667
|
-
BSON_ASSERT_PARAM (buf);
|
668
|
-
|
669
|
-
_mongocrypt_buffer_init (buf);
|
670
|
-
_mongocrypt_buffer_resize (buf, sizeof (value));
|
671
|
-
memcpy (buf->data, &value_le, buf->len);
|
672
|
-
}
|
673
|
-
|
674
|
-
bool
|
675
|
-
_mongocrypt_buffer_from_subrange (_mongocrypt_buffer_t *out,
|
676
|
-
const _mongocrypt_buffer_t *in,
|
677
|
-
uint32_t offset,
|
678
|
-
uint32_t len)
|
679
|
-
{
|
680
|
-
BSON_ASSERT_PARAM (out);
|
681
|
-
BSON_ASSERT_PARAM (in);
|
682
|
-
|
683
|
-
_mongocrypt_buffer_init (out);
|
684
|
-
BSON_ASSERT (offset <= UINT32_MAX - len);
|
685
|
-
if (offset + len > in->len) {
|
686
|
-
return false;
|
687
|
-
}
|
688
|
-
out->data = in->data + offset;
|
689
|
-
out->len = len;
|
690
|
-
return true;
|
532
|
+
bool _mongocrypt_buffer_from_string(_mongocrypt_buffer_t *buf, const char *str) {
|
533
|
+
BSON_ASSERT_PARAM(buf);
|
534
|
+
BSON_ASSERT_PARAM(str);
|
535
|
+
|
536
|
+
_mongocrypt_buffer_init(buf);
|
537
|
+
if (!size_to_uint32(strlen(str), &buf->len)) {
|
538
|
+
return false;
|
539
|
+
}
|
540
|
+
buf->data = (uint8_t *)str;
|
541
|
+
buf->owned = false;
|
542
|
+
return true;
|
543
|
+
}
|
544
|
+
|
545
|
+
void _mongocrypt_buffer_copy_from_uint64_le(_mongocrypt_buffer_t *buf, uint64_t value) {
|
546
|
+
uint64_t value_le = MONGOCRYPT_UINT64_TO_LE(value);
|
547
|
+
|
548
|
+
BSON_ASSERT_PARAM(buf);
|
549
|
+
|
550
|
+
_mongocrypt_buffer_init(buf);
|
551
|
+
_mongocrypt_buffer_resize(buf, sizeof(value));
|
552
|
+
memcpy(buf->data, &value_le, buf->len);
|
553
|
+
}
|
554
|
+
|
555
|
+
bool _mongocrypt_buffer_from_subrange(_mongocrypt_buffer_t *out,
|
556
|
+
const _mongocrypt_buffer_t *in,
|
557
|
+
uint32_t offset,
|
558
|
+
uint32_t len) {
|
559
|
+
BSON_ASSERT_PARAM(out);
|
560
|
+
BSON_ASSERT_PARAM(in);
|
561
|
+
|
562
|
+
_mongocrypt_buffer_init(out);
|
563
|
+
BSON_ASSERT(offset <= UINT32_MAX - len);
|
564
|
+
if (offset + len > in->len) {
|
565
|
+
return false;
|
566
|
+
}
|
567
|
+
out->data = in->data + offset;
|
568
|
+
out->len = len;
|
569
|
+
return true;
|
691
570
|
}
|