libmongocrypt-helper 1.7.4.0.1002 → 1.11.0.0.1001
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +40 -5
- data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +29 -24
- data/ext/libmongocrypt/libmongocrypt/CODEOWNERS +1 -4
- data/ext/libmongocrypt/libmongocrypt/Earthfile +522 -0
- data/ext/libmongocrypt/libmongocrypt/README.md +36 -40
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/CMakeLists.txt +1 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Driver.snk +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/AssemblyInfo.cs +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Binary.cs +16 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClientFactory.cs +8 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +35 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/LibraryLoader.cs +81 -44
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/MongoDB.Libmongocrypt.csproj +2 -1
- 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/MongoDB.Libmongocrypt.Test/MongoDB.Libmongocrypt.Test.csproj +2 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test32/MongoDB.Libmongocrypt.Test32.csproj +2 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/README.md +3 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +22 -26
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.config +3 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.sh +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/build.gradle.kts +28 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/java/com/mongodb/crypt/benchmark/BenchmarkRunner.java +217 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/benchmarks/src/main/resources/keyDocument.json +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +22 -7
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradle/wrapper/gradle-wrapper.properties +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew +154 -108
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/gradlew.bat +7 -18
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/settings.gradle.kts +1 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPI.java +41 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CAPIHelper.java +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/CipherCallback.java +27 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoCryptImpl.java +34 -19
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/java/com/mongodb/crypt/capi/MongoExplicitEncryptOptions.java +6 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/jni-config.json +180 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/main/resources/META-INF/native-image/reflect-config.json +134 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +50 -6
- 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/{python/test/data/fle2-find-range-explicit → java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2}/int32/rangeopts.json +3 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +4 -771
- data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +86 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +41 -20
- data/ext/libmongocrypt/libmongocrypt/bindings/python/RELEASE.rst +6 -24
- data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +4 -13
- data/ext/libmongocrypt/libmongocrypt/bindings/python/hatch_build.py +36 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/libmongocrypt-version.txt +1 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/__init__.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/auto_encrypter.py +61 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/credentials.py +156 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/explicit_encrypter.py +156 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/asynchronous/state_machine.py +149 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/auto_encrypter.py +2 -46
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binary.py +14 -17
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +232 -296
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +6 -31
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/credentials.py +2 -121
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/crypto.py +31 -20
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/errors.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +2 -233
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +168 -254
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/options.py +265 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/state_machine.py +2 -141
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/auto_encrypter.py +61 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/credentials.py +156 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/explicit_encrypter.py +156 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/synchronous/state_machine.py +149 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pyproject.toml +118 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +97 -61
- data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements-test.txt +7 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/requirements.txt +4 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/sbom.json +76 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/strip_header.py +6 -7
- data/ext/libmongocrypt/libmongocrypt/bindings/python/synchro.py +64 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +2 -10
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/collection-info.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/command.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/compact/success/encrypted-payload.json +21 -21
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-command-reply.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/encrypted-field-config-map.json +1 -1
- 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/data/fle2-find-range-explicit-v2/int32/rangeopts.json +14 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-azure.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document-gcp.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-document.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/key-filter.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/list-collections-filter.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-command.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/mongocryptd-reply.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/schema-map.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/keyDocument.json +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/performance/perf_test.py +165 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_binding.py +8 -12
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_crypto.py +9 -11
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +991 -343
- data/ext/libmongocrypt/libmongocrypt/bindings/python/update-sbom.sh +14 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/FetchMongoC.cmake +19 -1
- data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +31 -6
- data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +20 -227
- data/ext/libmongocrypt/libmongocrypt/cmake/Patch.cmake +54 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
- data/ext/libmongocrypt/libmongocrypt/doc/img/cli-icon.png +0 -0
- data/ext/libmongocrypt/libmongocrypt/doc/img/reference-targets.png +0 -0
- data/ext/libmongocrypt/libmongocrypt/doc/releasing.md +153 -0
- data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
- data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version.py +61 -28
- data/ext/libmongocrypt/libmongocrypt/etc/calc_release_version_selftest.sh +73 -0
- data/ext/libmongocrypt/libmongocrypt/etc/cyclonedx.sbom.json +108 -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/libbson-remove-GCC-diagnostic-pragma.patch +27 -0
- data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-alpine-arm-fix.patch +17 -0
- data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
- data/ext/libmongocrypt/libmongocrypt/etc/packager.py +120 -91
- data/ext/libmongocrypt/libmongocrypt/etc/purls.txt +14 -0
- data/ext/libmongocrypt/libmongocrypt/etc/repo_config.yaml +56 -0
- data/ext/libmongocrypt/libmongocrypt/etc/silk-create-asset-group.sh +70 -0
- data/ext/libmongocrypt/libmongocrypt/etc/ssdlc_compliance_report.md +37 -0
- data/ext/libmongocrypt/libmongocrypt/etc/third_party_vulnerabilities.md +42 -0
- data/ext/libmongocrypt/libmongocrypt/integrating.md +18 -1
- data/ext/libmongocrypt/libmongocrypt/kms-message/CMakeLists.txt +11 -3
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_gcp_request.c +1 -1
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer.c +17 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_reader_writer_private.h +6 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_request.c +211 -1
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_response.c +163 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_kmip_tag_type_private.h +2 -1
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_request.h +17 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_message/kms_kmip_response.h +6 -0
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_port.c +3 -2
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request.c +4 -2
- data/ext/libmongocrypt/libmongocrypt/kms-message/src/kms_request_str.c +2 -2
- data/ext/libmongocrypt/libmongocrypt/kms-message/test/test_kmip_reader_writer.c +23 -2
- 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 +183 -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 +21 -11
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +175 -99
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +69 -70
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +445 -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 +103 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +28 -31
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +173 -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 +130 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +36 -44
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +382 -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 +454 -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 +56 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +520 -580
- data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +47 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +67 -76
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +201 -190
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +55 -42
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +809 -558
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +177 -201
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +54 -53
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +188 -240
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +43 -35
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +484 -337
- 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 +87 -65
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +153 -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 +461 -499
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +256 -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 +1 -9
- 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 +442 -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 +104 -132
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +16 -24
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +110 -93
- 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 +1145 -1567
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +510 -476
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2775 -2697
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +189 -184
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +990 -1139
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +23 -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 +42 -44
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +292 -272
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +70 -110
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +1010 -1033
- 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 +127 -120
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1692 -1611
- 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 +31 -36
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1923 -1479
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +124 -107
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +925 -419
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +99 -122
- 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 +98 -136
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +924 -1339
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +199 -313
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +83 -79
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +64 -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/bulkWrite/bypassQueryAnalysis/payload.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd-to-mongocryptd.json +23 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/jsonSchema/cmd.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd-to-mongocryptd.json +50 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/cmd.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/collinfo.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-field-map.json +24 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/encrypted-payload-pattern.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/simple/mongocryptd-reply.json +62 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd-to-mongocryptd.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/cmd.json +17 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/mongocryptd-reply.json +39 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/bulkWrite/unencrypted/payload.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/missing-key-id/collinfo.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/collinfo.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/no-fields/encrypted-payload.json +4 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/cmd.json +1 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/collinfo.json +63 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-field-config-map.json +61 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload-range-v2.json +37 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/cleanup/success/encrypted-payload.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/cmd.json +1 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/collinfo.json +64 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload-range-v2.json +105 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/anchor-pad/encrypted-payload.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/cmd.json +1 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/collinfo.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-field-config-map.json +47 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/no-range/encrypted-payload.json +23 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/collinfo.json +15 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-field-config-map.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload-range-v2.json +104 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/encrypted-payload.json +6 -0
- 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/collinfo.json +4 -4
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +5 -5
- 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/kms-azure/decrypt-response.txt +16 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/encrypt-response.txt +16 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/kms-azure/oauth-response.txt +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-field-map.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/encrypted-payload.json +62 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/find/mongocryptd-reply.json +69 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-field-map.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/encrypted-payload.json +40 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/no-trimFactor/insert/mongocryptd-reply.json +47 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_decimal128.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_double.cstruct +8637 -7958
- data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int32.cstruct +5522 -1382
- data/ext/libmongocrypt/libmongocrypt/test/data/range-edge-generation/edges_int64.cstruct +5042 -1262
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_decimal128_precision.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_double_precision.cstruct +2 -2
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int32.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-min-cover/mincover_int64.cstruct +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-field-map.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/encrypted-payload.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-find-int32/mongocryptd-reply.json +58 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-field-map.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/encrypted-payload.json +40 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/auto-insert-int32/mongocryptd-reply.json +45 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/expected.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32/to-encrypt.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/expected.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-find-int32-defaults/to-encrypt.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-double/expected.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32/expected.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/range-sends-cryptoParams/explicit-insert-int32-defaults/expected.json +8 -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 +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +25 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +25 -0
- data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
- data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +279 -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 +60 -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 +129 -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 +248 -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 +421 -388
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +974 -825
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +499 -481
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +312 -148
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +249 -213
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +632 -808
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +22 -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 +118 -37
- 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-cleanup.c +374 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +410 -445
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +798 -812
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +142 -135
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +70 -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 +870 -1045
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +5183 -4717
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +1093 -1178
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +348 -420
- 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 +705 -368
- 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 +1073 -690
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-opts.c +42 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +381 -451
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +55 -67
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +7 -10
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +879 -918
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +119 -169
- data/ext/libmongocrypt/libmongocrypt/test/test-named-kms-providers.c +2381 -0
- data/ext/libmongocrypt/libmongocrypt/test/util/HELP.autogen +3 -1
- data/ext/libmongocrypt/libmongocrypt/test/util/README.md +1 -0
- data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +512 -559
- data/ext/libmongocrypt/libmongocrypt/test/util/make_includes.py +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/util/util.c +771 -882
- data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
- data/lib/libmongocrypt_helper/version.rb +2 -2
- metadata +245 -111
- checksums.yaml.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +0 -1
- 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/CHANGELOG.md +0 -81
- data/ext/libmongocrypt/libmongocrypt/bindings/node/LICENSE +0 -201
- data/ext/libmongocrypt/libmongocrypt/bindings/node/binding.gyp +0 -79
- data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/README.hbs +0 -44
- data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +0 -39
- data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +0 -515
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +0 -420
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/buffer_pool.js +0 -123
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +0 -699
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +0 -100
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/cryptoCallbacks.js +0 -87
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +0 -42
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js +0 -66
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +0 -487
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +0 -16051
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +0 -81
- data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +0 -929
- data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.h +0 -114
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +0 -953
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/buffer_pool.test.js +0 -91
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +0 -701
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +0 -284
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/README.md +0 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/cmd.json +0 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/collection-info.json +0 -37
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document-nested.json +0 -8
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encrypted-document.json +0 -11
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/encryptedFields.json +0 -30
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key-document.json +0 -32
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/key1-document.json +0 -30
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/data/mongocryptd-reply.json +0 -18
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +0 -48
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +0 -59
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +0 -29
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +0 -331
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/mongodb_reporter.js +0 -325
- data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +0 -84
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +0 -12
- data/ext/libmongocrypt/libmongocrypt/debian/build_snapshot.sh +0 -79
- data/ext/libmongocrypt/libmongocrypt/debian/changelog +0 -105
- data/ext/libmongocrypt/libmongocrypt/debian/compat +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/control +0 -41
- data/ext/libmongocrypt/libmongocrypt/debian/copyright +0 -129
- data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +0 -23
- data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.dirs +0 -2
- data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt-dev.install +0 -5
- data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.dirs +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/libmongocrypt0.install +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/rules +0 -46
- data/ext/libmongocrypt/libmongocrypt/debian/source/format +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/source/lintian-overrides +0 -3
- data/ext/libmongocrypt/libmongocrypt/debian/source/options +0 -1
- data/ext/libmongocrypt/libmongocrypt/debian/watch +0 -3
- data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
- data/ext/libmongocrypt/libmongocrypt/test/data/compact/success/mongocryptd-reply.json +0 -72
- 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-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.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
- /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/value-to-encrypt.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
- /data/ext/libmongocrypt/libmongocrypt/bindings/{java/mongocrypt/src/test/resources/fle2-find-range-explicit → python/test/data/fle2-find-rangePreview-explicit}/int32/rangeopts.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/{test/data/fle2-find-range-explicit/int32-nominmax → bindings/python/test/data/fle2-find-rangePreview-explicit/int32}/value-to-encrypt.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-decrypt-reply.txt → test/data/kms-aws/decrypt-response.txt} +0 -0
- /data/ext/libmongocrypt/libmongocrypt/{bindings/node/test/data/kms-encrypt-reply.txt → test/data/kms-aws/encrypt-response.txt} +0 -0
- /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/decrypt-response.txt +0 -0
- /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/encrypt-response.txt +0 -0
- /data/ext/libmongocrypt/libmongocrypt/test/data/{gcp-auth → kms-gcp}/oauth-response.txt +0 -0
@@ -31,287 +31,393 @@
|
|
31
31
|
* Encode a signed 32-bit integer as an unsigned 32-bit integer by adding 2^31.
|
32
32
|
* Some documentation references this as making the value "unbiased".
|
33
33
|
*/
|
34
|
-
static uint32_t
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
uint32_t v_u32 = (uint32_t) v;
|
54
|
-
return new_zero + v_u32;
|
34
|
+
static uint32_t encodeInt32(int32_t v) {
|
35
|
+
// Shift the int32_t range [-2^31, 2^31 - 1] to the uint32_t range [0, 2^32].
|
36
|
+
// new_zero is the mapped 0 value.
|
37
|
+
uint32_t new_zero = (UINT32_C(1) << 31);
|
38
|
+
|
39
|
+
if (v < 0) {
|
40
|
+
// Signed integers have a value that there is no positive equivalent and
|
41
|
+
// must be handled specially
|
42
|
+
if (v == INT32_MIN) {
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
int32_t v_pos = v * -1;
|
47
|
+
uint32_t v_u32 = (uint32_t)v_pos;
|
48
|
+
return new_zero - v_u32;
|
49
|
+
}
|
50
|
+
|
51
|
+
uint32_t v_u32 = (uint32_t)v;
|
52
|
+
return new_zero + v_u32;
|
55
53
|
}
|
56
54
|
|
57
|
-
bool
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
v_u32 -= min_u32;
|
98
|
-
max_u32 -= min_u32;
|
99
|
-
|
100
|
-
*out = (mc_OSTType_Int32){v_u32, 0, max_u32};
|
101
|
-
return true;
|
55
|
+
bool mc_getTypeInfo32(mc_getTypeInfo32_args_t args, mc_OSTType_Int32 *out, mongocrypt_status_t *status) {
|
56
|
+
if (args.min.set != args.max.set) {
|
57
|
+
CLIENT_ERR("Must specify both a lower and upper bound or no bounds.");
|
58
|
+
return false;
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!args.min.set) {
|
62
|
+
uint32_t v_u32 = encodeInt32(args.value);
|
63
|
+
*out = (mc_OSTType_Int32){v_u32, 0, UINT32_MAX};
|
64
|
+
return true;
|
65
|
+
}
|
66
|
+
|
67
|
+
if (args.min.value >= args.max.value) {
|
68
|
+
CLIENT_ERR("The minimum value must be less than the maximum value, got "
|
69
|
+
"min: %" PRId32 ", max: %" PRId32,
|
70
|
+
args.min.value,
|
71
|
+
args.max.value);
|
72
|
+
return false;
|
73
|
+
}
|
74
|
+
|
75
|
+
if (args.value > args.max.value || args.value < args.min.value) {
|
76
|
+
CLIENT_ERR("Value must be greater than or equal to the minimum value "
|
77
|
+
"and less than or equal to the maximum value, got min: %" PRId32 ", max: %" PRId32
|
78
|
+
", value: %" PRId32,
|
79
|
+
args.min.value,
|
80
|
+
args.max.value,
|
81
|
+
args.value);
|
82
|
+
return false;
|
83
|
+
}
|
84
|
+
|
85
|
+
// Convert to unbiased uint32. Then subtract the min value.
|
86
|
+
uint32_t v_u32 = encodeInt32(args.value);
|
87
|
+
uint32_t min_u32 = encodeInt32(args.min.value);
|
88
|
+
uint32_t max_u32 = encodeInt32(args.max.value);
|
89
|
+
|
90
|
+
v_u32 -= min_u32;
|
91
|
+
max_u32 -= min_u32;
|
92
|
+
|
93
|
+
*out = (mc_OSTType_Int32){v_u32, 0, max_u32};
|
94
|
+
return true;
|
102
95
|
}
|
103
96
|
|
104
97
|
/**
|
105
98
|
* Encode a signed 64-bit integer as an unsigned 64-bit integer by adding 2^63.
|
106
99
|
* Some documentation references this as making the value "unbiased".
|
107
100
|
*/
|
108
|
-
static uint64_t
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
uint64_t v_u64 = (uint64_t) v;
|
128
|
-
return new_zero + v_u64;
|
101
|
+
static uint64_t encodeInt64(int64_t v) {
|
102
|
+
// Shift the int64_t range [-2^63, 2^63 - 1] to the uint64_t range [0, 2^64].
|
103
|
+
// new_zero is the mapped 0 value.
|
104
|
+
uint64_t new_zero = (UINT64_C(1) << 63);
|
105
|
+
|
106
|
+
if (v < 0) {
|
107
|
+
// Signed integers have a value that there is no positive equivalent and
|
108
|
+
// must be handled specially
|
109
|
+
if (v == INT64_MIN) {
|
110
|
+
return 0;
|
111
|
+
}
|
112
|
+
|
113
|
+
int64_t v_pos = v * -1;
|
114
|
+
uint64_t v_u64 = (uint64_t)v_pos;
|
115
|
+
return new_zero - v_u64;
|
116
|
+
}
|
117
|
+
|
118
|
+
uint64_t v_u64 = (uint64_t)v;
|
119
|
+
return new_zero + v_u64;
|
129
120
|
}
|
130
121
|
|
131
|
-
bool
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
max_u64 -= min_u64;
|
172
|
-
|
173
|
-
*out = (mc_OSTType_Int64){v_u64, 0, max_u64};
|
174
|
-
return true;
|
122
|
+
bool mc_getTypeInfo64(mc_getTypeInfo64_args_t args, mc_OSTType_Int64 *out, mongocrypt_status_t *status) {
|
123
|
+
if (args.min.set != args.max.set) {
|
124
|
+
CLIENT_ERR("Must specify both a lower and upper bound or no bounds.");
|
125
|
+
return false;
|
126
|
+
}
|
127
|
+
|
128
|
+
if (!args.min.set) {
|
129
|
+
uint64_t v_u64 = encodeInt64(args.value);
|
130
|
+
*out = (mc_OSTType_Int64){v_u64, 0, UINT64_MAX};
|
131
|
+
return true;
|
132
|
+
}
|
133
|
+
|
134
|
+
if (args.min.value >= args.max.value) {
|
135
|
+
CLIENT_ERR("The minimum value must be less than the maximum value, got "
|
136
|
+
"min: %" PRId64 ", max: %" PRId64,
|
137
|
+
args.min.value,
|
138
|
+
args.max.value);
|
139
|
+
return false;
|
140
|
+
}
|
141
|
+
|
142
|
+
if (args.value > args.max.value || args.value < args.min.value) {
|
143
|
+
CLIENT_ERR("Value must be greater than or equal to the minimum value "
|
144
|
+
"and less than or equal to the maximum value, got "
|
145
|
+
"min: %" PRId64 ", max: %" PRId64 ", value: %" PRId64,
|
146
|
+
args.min.value,
|
147
|
+
args.max.value,
|
148
|
+
args.value);
|
149
|
+
return false;
|
150
|
+
}
|
151
|
+
|
152
|
+
// Convert to unbiased uint64. Then subtract the min value.
|
153
|
+
uint64_t v_u64 = encodeInt64(args.value);
|
154
|
+
uint64_t min_u64 = encodeInt64(args.min.value);
|
155
|
+
uint64_t max_u64 = encodeInt64(args.max.value);
|
156
|
+
|
157
|
+
v_u64 -= min_u64;
|
158
|
+
max_u64 -= min_u64;
|
159
|
+
|
160
|
+
*out = (mc_OSTType_Int64){v_u64, 0, max_u64};
|
161
|
+
return true;
|
175
162
|
}
|
176
163
|
|
177
|
-
#define exp10Double(x) pow
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
164
|
+
#define exp10Double(x) pow(10, x)
|
165
|
+
#define SCALED_DOUBLE_BOUNDS 9007199254740992.0 // 2^53
|
166
|
+
|
167
|
+
uint64_t subtract_int64_t(int64_t max, int64_t min) {
|
168
|
+
BSON_ASSERT(max > min);
|
169
|
+
// If the values have the same sign, then simple subtraction
|
170
|
+
// will work because we know max > min.
|
171
|
+
if ((max > 0 && min > 0) || (max < 0 && min < 0)) {
|
172
|
+
return (uint64_t)(max - min);
|
173
|
+
}
|
174
|
+
|
175
|
+
// If they are opposite signs, then we can just invert
|
176
|
+
// min to be positive and return the sum.
|
177
|
+
uint64_t u_return = (uint64_t)max;
|
178
|
+
u_return += (uint64_t)(~min + 1);
|
179
|
+
return u_return;
|
180
|
+
}
|
181
|
+
|
182
|
+
bool ceil_log2_double(uint64_t i, uint32_t *maxBitsOut, mongocrypt_status_t *status) {
|
183
|
+
if (i == 0) {
|
184
|
+
CLIENT_ERR("Invalid input to ceil_log2_double function. Input cannot be 0.");
|
185
|
+
return false;
|
186
|
+
}
|
187
|
+
|
188
|
+
uint32_t clz = (uint32_t)_mlibCountLeadingZeros_u64(i);
|
189
|
+
uint32_t bits;
|
190
|
+
if ((i & (i - 1)) == 0) {
|
191
|
+
bits = 64 - clz - 1;
|
192
|
+
} else {
|
193
|
+
bits = 64 - clz;
|
194
|
+
}
|
195
|
+
*maxBitsOut = bits;
|
196
|
+
return true;
|
197
|
+
}
|
198
|
+
|
199
|
+
bool mc_canUsePrecisionModeDouble(double min,
|
200
|
+
double max,
|
201
|
+
int32_t precision,
|
202
|
+
uint32_t *maxBitsOut,
|
203
|
+
mongocrypt_status_t *status) {
|
204
|
+
BSON_ASSERT_PARAM(maxBitsOut);
|
205
|
+
BSON_ASSERT(precision >= 0);
|
206
|
+
|
207
|
+
if (min >= max) {
|
208
|
+
CLIENT_ERR("Invalid bounds for double range precision, min must be less than max. min: %g, max: %g", min, max);
|
209
|
+
return false;
|
210
|
+
}
|
211
|
+
|
212
|
+
const double scaled_prc = exp10Double(precision);
|
213
|
+
|
214
|
+
const double scaled_max = max * scaled_prc;
|
215
|
+
const double scaled_min = min * scaled_prc;
|
216
|
+
|
217
|
+
if (scaled_max != trunc(scaled_max)) {
|
218
|
+
CLIENT_ERR("Invalid upper bound for double precision. Fractional digits must be less than the specified "
|
219
|
+
"precision value. max: %g",
|
220
|
+
max);
|
221
|
+
return false;
|
222
|
+
}
|
223
|
+
|
224
|
+
if (scaled_min != trunc(scaled_min)) {
|
225
|
+
CLIENT_ERR("Invalid lower bound for double precision. Fractional digits must be less than the specified "
|
226
|
+
"precision value. min: %g",
|
227
|
+
min);
|
228
|
+
return false;
|
229
|
+
}
|
230
|
+
|
231
|
+
if (fabs(scaled_max) >= SCALED_DOUBLE_BOUNDS) {
|
232
|
+
CLIENT_ERR(
|
233
|
+
"Invalid upper bound for double precision. Absolute scaled value of max must be less than %g. max: %g",
|
234
|
+
SCALED_DOUBLE_BOUNDS,
|
235
|
+
max);
|
236
|
+
return false;
|
237
|
+
}
|
238
|
+
|
239
|
+
if (fabs(scaled_min) >= SCALED_DOUBLE_BOUNDS) {
|
240
|
+
CLIENT_ERR(
|
241
|
+
"Invalid lower bound for double precision. Absolute scaled value of min must be less than %g. min: %g",
|
242
|
+
SCALED_DOUBLE_BOUNDS,
|
243
|
+
min);
|
244
|
+
return false;
|
245
|
+
}
|
246
|
+
|
247
|
+
const double t_1 = scaled_max - scaled_min;
|
248
|
+
const double t_4 = (double)UINT64_MAX - t_1;
|
249
|
+
const double t_5 = floor(log10(t_4)) - 1;
|
250
|
+
|
251
|
+
if ((double)precision > t_5) {
|
252
|
+
CLIENT_ERR("Invalid value for precision. precision: %" PRId32, precision);
|
253
|
+
return false;
|
254
|
+
}
|
255
|
+
|
256
|
+
const int64_t i_1 = (int64_t)(scaled_max);
|
257
|
+
const int64_t i_2 = (int64_t)(scaled_min);
|
258
|
+
|
259
|
+
const uint64_t range = subtract_int64_t(i_1, i_2);
|
260
|
+
|
261
|
+
if (((uint64_t)scaled_prc) > UINT64_MAX - range) {
|
262
|
+
CLIENT_ERR("Invalid value for min, max, and precision. The calculated domain size is too large. min: %g, max: "
|
263
|
+
"%g, precision: %" PRId32,
|
264
|
+
min,
|
265
|
+
max,
|
266
|
+
precision);
|
267
|
+
return false;
|
268
|
+
}
|
269
|
+
|
270
|
+
const uint64_t i_3 = range + (uint64_t)(scaled_prc);
|
271
|
+
|
272
|
+
if (!ceil_log2_double(i_3, maxBitsOut, status)) {
|
273
|
+
return false;
|
274
|
+
}
|
275
|
+
|
276
|
+
// Integers between -2^53 and 2^53 can be exactly represented. Outside this range, doubles lose precision by a
|
277
|
+
// multiple of 2^(n-52) where n = #bits. We disallow users from using precision mode when the bounds exceed 2^53 to
|
278
|
+
// prevent the users from being surprised by how floating point math works.
|
279
|
+
if (*maxBitsOut >= 53) {
|
280
|
+
return false;
|
281
|
+
}
|
282
|
+
|
283
|
+
return true;
|
284
|
+
}
|
285
|
+
|
286
|
+
bool mc_getTypeInfoDouble(mc_getTypeInfoDouble_args_t args,
|
287
|
+
mc_OSTType_Double *out,
|
288
|
+
mongocrypt_status_t *status,
|
289
|
+
bool use_range_v2) {
|
290
|
+
if (args.min.set != args.max.set || args.min.set != args.precision.set) {
|
291
|
+
CLIENT_ERR("min, max, and precision must all be set or must all be unset");
|
292
|
+
return false;
|
293
|
+
}
|
294
|
+
|
295
|
+
if (mc_isinf(args.value) || mc_isnan(args.value)) {
|
296
|
+
CLIENT_ERR("Infinity and NaN double values are not supported.");
|
297
|
+
return false;
|
298
|
+
}
|
299
|
+
|
300
|
+
if (args.min.set) {
|
301
|
+
if (args.min.value >= args.max.value) {
|
302
|
+
CLIENT_ERR("The minimum value must be less than the maximum value, got "
|
303
|
+
"min: %g, max: %g",
|
304
|
+
args.min.value,
|
305
|
+
args.max.value);
|
306
|
+
return false;
|
307
|
+
}
|
308
|
+
|
309
|
+
if (args.value > args.max.value || args.value < args.min.value) {
|
310
|
+
CLIENT_ERR("Value must be greater than or equal to the minimum value "
|
311
|
+
"and less than or equal to the maximum value, got "
|
312
|
+
"min: %g, max: %g, value: %g",
|
313
|
+
args.min.value,
|
314
|
+
args.max.value,
|
315
|
+
args.value);
|
316
|
+
return false;
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
if (args.precision.set) {
|
321
|
+
if (args.precision.value < 0) {
|
322
|
+
CLIENT_ERR("Precision must be non-negative, but got %" PRId32, args.precision.value);
|
323
|
+
return false;
|
324
|
+
}
|
325
|
+
|
326
|
+
double scaled = exp10Double(args.precision.value);
|
327
|
+
if (!mc_isfinite(scaled)) {
|
328
|
+
CLIENT_ERR("Precision is too large and cannot be used to calculate the scaled range bounds");
|
329
|
+
return false;
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
const bool is_neg = args.value < 0.0;
|
334
|
+
|
335
|
+
// Map negative 0 to zero so sign bit is 0.
|
336
|
+
if (args.value == 0.0) {
|
337
|
+
args.value = 0.0;
|
338
|
+
}
|
339
|
+
|
340
|
+
// When we use precision mode, we try to represent as a double value that
|
341
|
+
// fits in [-2^63, 2^63] (i.e. is a valid int64)
|
342
|
+
//
|
343
|
+
// This check determines if we can represent the precision truncated value as
|
344
|
+
// a 64-bit integer I.e. Is ((ub - lb) * 10^precision) < 64 bits.
|
345
|
+
//
|
346
|
+
bool use_precision_mode = false;
|
347
|
+
uint32_t bits_range;
|
348
|
+
if (args.precision.set) {
|
349
|
+
use_precision_mode =
|
350
|
+
mc_canUsePrecisionModeDouble(args.min.value, args.max.value, args.precision.value, &bits_range, status);
|
351
|
+
|
352
|
+
if (!use_precision_mode && use_range_v2) {
|
353
|
+
if (!mongocrypt_status_ok(status)) {
|
354
|
+
return false;
|
258
355
|
}
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
356
|
+
|
357
|
+
CLIENT_ERR("The domain of double values specified by the min, max, and precision cannot be represented in "
|
358
|
+
"fewer than 53 bits. min: %g, max: %g, precision: %" PRId32,
|
359
|
+
args.min.value,
|
360
|
+
args.max.value,
|
361
|
+
args.precision.value);
|
362
|
+
return false;
|
363
|
+
}
|
364
|
+
|
365
|
+
// If we are not in range_v2, then we don't care about the error returned
|
366
|
+
// from canUsePrecisionMode so we can reset the status.
|
367
|
+
_mongocrypt_status_reset(status);
|
368
|
+
}
|
369
|
+
|
370
|
+
if (use_precision_mode) {
|
371
|
+
// Take a number of xxxx.ppppp and truncate it xxxx.ppp if precision = 3.
|
372
|
+
// We do not change the digits before the decimal place.
|
373
|
+
int64_t v_prime = (int64_t)(trunc(args.value * exp10Double(args.precision.value)));
|
374
|
+
int64_t scaled_min = (int64_t)(args.min.value * exp10Double(args.precision.value));
|
375
|
+
int64_t v_prime2 = v_prime - scaled_min;
|
376
|
+
|
377
|
+
BSON_ASSERT(v_prime2 < INT64_MAX && v_prime2 >= 0);
|
378
|
+
|
379
|
+
uint64_t ret = (uint64_t)v_prime2;
|
380
|
+
|
381
|
+
// Adjust maximum value to be the max bit range. This will be used by
|
382
|
+
// getEdges/minCover to trim bits.
|
383
|
+
uint64_t max_value = (UINT64_C(1) << bits_range) - 1;
|
384
|
+
BSON_ASSERT(ret <= max_value);
|
385
|
+
|
386
|
+
*out = (mc_OSTType_Double){ret, 0, max_value};
|
387
|
+
return true;
|
388
|
+
}
|
389
|
+
|
390
|
+
// Translate double to uint64 by modifying the bit representation and copying
|
391
|
+
// into a uint64. Double is assumed to be a IEEE 754 Binary 64.
|
392
|
+
// It is bit-encoded as sign, exponent, and fraction:
|
393
|
+
// s eeeeeeee ffffffffffffffffffffffffffffffffffffffffffffffffffff
|
394
|
+
|
395
|
+
// When we translate the double into "bits", the sign bit means that the
|
396
|
+
// negative numbers get mapped into the higher 63 bits of a 64-bit integer.
|
397
|
+
// We want them to map into the lower 64-bits so we invert the sign bit.
|
398
|
+
args.value *= -1.0;
|
399
|
+
|
400
|
+
// On Endianness, we support two sets of architectures
|
401
|
+
// 1. Little Endian (ppc64le, x64, aarch64) - in these architectures, int64
|
402
|
+
// and double are both 64-bits and both arranged in little endian byte order.
|
403
|
+
// 2. Big Endian (s390x) - in these architectures, int64 and double are both
|
404
|
+
// 64-bits and both arranged in big endian byte order.
|
405
|
+
//
|
406
|
+
// Therefore, since the order of bytes on each platform is consistent with
|
407
|
+
// itself, the conversion below converts a double into correct 64-bit integer
|
408
|
+
// that produces the same behavior across plaforms.
|
409
|
+
uint64_t uv;
|
410
|
+
memcpy(&uv, &args.value, sizeof(uint64_t));
|
411
|
+
|
412
|
+
if (is_neg) {
|
413
|
+
uint64_t new_zero = UINT64_C(1) << 63;
|
414
|
+
BSON_ASSERT(uv <= new_zero);
|
415
|
+
uv = new_zero - uv;
|
416
|
+
}
|
417
|
+
|
418
|
+
*out = (mc_OSTType_Double){.min = 0, .max = UINT64_MAX, .value = uv};
|
419
|
+
|
420
|
+
return true;
|
315
421
|
}
|
316
422
|
|
317
423
|
#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
|
@@ -322,299 +428,444 @@ mc_getTypeInfoDouble (mc_getTypeInfoDouble_args_t args,
|
|
322
428
|
* @param dec
|
323
429
|
* @return mlib_int128
|
324
430
|
*/
|
325
|
-
static mlib_int128
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
431
|
+
static mlib_int128 dec128_to_uint128(mc_dec128 dec) {
|
432
|
+
// Only normal numbers
|
433
|
+
BSON_ASSERT(mc_dec128_is_finite(dec));
|
434
|
+
BSON_ASSERT(!mc_dec128_is_nan(dec));
|
435
|
+
// We don't support negative numbers
|
436
|
+
BSON_ASSERT(!mc_dec128_is_negative(dec));
|
437
|
+
// There is no fractional part:
|
438
|
+
BSON_ASSERT(mc_dec128_is_zero(mc_dec128_modf(dec).frac));
|
439
|
+
|
440
|
+
mlib_int128 ret = mc_dec128_coeff(dec);
|
441
|
+
|
442
|
+
// Scale the resulting number by a power of ten matching the exponent of the
|
443
|
+
// Decimal128:
|
444
|
+
int32_t exp = ((int32_t)mc_dec128_get_biased_exp(dec)) - MC_DEC128_EXPONENT_BIAS;
|
445
|
+
// We will scale up/down based on whether it is negative:
|
446
|
+
BSON_ASSERT(abs(exp) <= UINT8_MAX);
|
447
|
+
mlib_int128 e1 = mlib_int128_pow10((uint8_t)abs(exp));
|
448
|
+
if (exp < 0) {
|
449
|
+
ret = mlib_int128_div(ret, e1);
|
450
|
+
} else {
|
451
|
+
ret = mlib_int128_mul(ret, e1);
|
452
|
+
}
|
453
|
+
|
454
|
+
return ret;
|
455
|
+
}
|
456
|
+
|
457
|
+
// (2^127 - 1) = the maximum signed 128-bit integer value, as a decimal128
|
458
|
+
#define INT_128_MAX_AS_DECIMAL mc_dec128_from_string("170141183460469231731687303715884105727")
|
459
|
+
// (2^128 - 1) = the max unsigned 128-bit integer value, as a decimal128
|
460
|
+
#define UINT_128_MAX_AS_DECIMAL mc_dec128_from_string("340282366920938463463374607431768211455")
|
461
|
+
|
462
|
+
static mlib_int128 dec128_to_int128(mc_dec128 dec) {
|
463
|
+
BSON_ASSERT(mc_dec128_less(dec, INT_128_MAX_AS_DECIMAL));
|
464
|
+
|
465
|
+
bool negative = false;
|
466
|
+
|
467
|
+
if (mc_dec128_is_negative(dec)) {
|
468
|
+
negative = true;
|
469
|
+
dec = mc_dec128_mul(MC_DEC128(-1), dec);
|
470
|
+
}
|
471
|
+
|
472
|
+
mlib_int128 ret_val = dec128_to_uint128(dec);
|
473
|
+
|
474
|
+
if (negative) {
|
475
|
+
ret_val = mlib_int128_mul(MLIB_INT128(-1), ret_val);
|
476
|
+
}
|
477
|
+
|
478
|
+
return ret_val;
|
479
|
+
}
|
480
|
+
|
481
|
+
bool ceil_log2_int128(mlib_int128 i, uint32_t *maxBitsOut, mongocrypt_status_t *status) {
|
482
|
+
if (mlib_int128_eq(i, MLIB_INT128(0))) {
|
483
|
+
CLIENT_ERR("Invalid input to ceil_log2_int128 function. Input cannot be 0.");
|
484
|
+
return false;
|
485
|
+
}
|
486
|
+
|
487
|
+
uint32_t clz = (uint32_t)_mlibCountLeadingZeros_u128(i);
|
488
|
+
uint32_t bits;
|
489
|
+
|
490
|
+
// if i & (i - 1) == 0
|
491
|
+
if (mlib_int128_eq((mlib_int128_bitand(i, (mlib_int128_sub(i, MLIB_INT128(1))))), MLIB_INT128(0))) {
|
492
|
+
bits = 128 - clz - 1;
|
493
|
+
} else {
|
494
|
+
bits = 128 - clz;
|
495
|
+
}
|
496
|
+
*maxBitsOut = bits;
|
497
|
+
return true;
|
351
498
|
}
|
352
499
|
|
353
|
-
bool
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
{
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
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
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
500
|
+
bool mc_canUsePrecisionModeDecimal(mc_dec128 min,
|
501
|
+
mc_dec128 max,
|
502
|
+
int32_t precision,
|
503
|
+
uint32_t *maxBitsOut,
|
504
|
+
mongocrypt_status_t *status) {
|
505
|
+
BSON_ASSERT_PARAM(maxBitsOut);
|
506
|
+
BSON_ASSERT(precision >= 0);
|
507
|
+
|
508
|
+
if (!mc_dec128_is_finite(max)) {
|
509
|
+
CLIENT_ERR("Invalid upper bound for Decimal128 precision. Max is infinite.");
|
510
|
+
return false;
|
511
|
+
}
|
512
|
+
|
513
|
+
if (!mc_dec128_is_finite(min)) {
|
514
|
+
CLIENT_ERR("Invalid lower bound for Decimal128 precision. Min is infinite.");
|
515
|
+
return false;
|
516
|
+
}
|
517
|
+
|
518
|
+
if (mc_dec128_greater_equal(min, max)) {
|
519
|
+
CLIENT_ERR("Invalid upper and lower bounds for Decimal128 precision. Min must be strictly less than max. min: "
|
520
|
+
"%s, max: %s",
|
521
|
+
mc_dec128_to_string(min).str,
|
522
|
+
mc_dec128_to_string(max).str);
|
523
|
+
return false;
|
524
|
+
}
|
525
|
+
|
526
|
+
mc_dec128 scaled_max = mc_dec128_scale(max, precision);
|
527
|
+
mc_dec128 scaled_min = mc_dec128_scale(min, precision);
|
528
|
+
|
529
|
+
mc_dec128 scaled_max_trunc = mc_dec128_round_integral_ex(scaled_max, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
|
530
|
+
mc_dec128 scaled_min_trunc = mc_dec128_round_integral_ex(scaled_min, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
|
531
|
+
|
532
|
+
if (mc_dec128_not_equal(scaled_max, scaled_max_trunc)) {
|
533
|
+
CLIENT_ERR("Invalid upper bound for Decimal128 precision. Fractional digits must be less than "
|
534
|
+
"the specified precision value. max: %s, precision: %" PRId32,
|
535
|
+
mc_dec128_to_string(max).str,
|
536
|
+
precision);
|
537
|
+
return false;
|
538
|
+
}
|
539
|
+
|
540
|
+
if (mc_dec128_not_equal(scaled_min, scaled_min_trunc)) {
|
541
|
+
CLIENT_ERR("Invalid lower bound for Decimal128 precision. Fractional digits must be less than "
|
542
|
+
"the specified precision value. min: %s, precision: %" PRId32,
|
543
|
+
mc_dec128_to_string(min).str,
|
544
|
+
precision);
|
545
|
+
return false;
|
546
|
+
}
|
547
|
+
|
548
|
+
if (mc_dec128_greater(mc_dec128_abs(scaled_max), INT_128_MAX_AS_DECIMAL)) {
|
549
|
+
CLIENT_ERR("Invalid upper bound for Decimal128 precision. Absolute scaled value must be less than "
|
550
|
+
"or equal to %s. max: %s",
|
551
|
+
mc_dec128_to_string(INT_128_MAX_AS_DECIMAL).str,
|
552
|
+
mc_dec128_to_string(max).str);
|
553
|
+
return false;
|
554
|
+
}
|
555
|
+
|
556
|
+
if (mc_dec128_greater(mc_dec128_abs(scaled_min), INT_128_MAX_AS_DECIMAL)) {
|
557
|
+
CLIENT_ERR("Invalid lower bound for Decimal128 precision. Absolute scaled value must be less than "
|
558
|
+
"or equal to %s. min: %s",
|
559
|
+
mc_dec128_to_string(INT_128_MAX_AS_DECIMAL).str,
|
560
|
+
mc_dec128_to_string(min).str);
|
561
|
+
return false;
|
562
|
+
}
|
563
|
+
|
564
|
+
mc_dec128 t_1 = mc_dec128_sub(scaled_max, scaled_min);
|
565
|
+
mc_dec128 t_4 = mc_dec128_sub(UINT_128_MAX_AS_DECIMAL, t_1);
|
566
|
+
|
567
|
+
// t_5 = floor(log10(t_4)) - 1;
|
568
|
+
mc_dec128 t_5 = mc_dec128_sub(mc_dec128_round_integral_ex(mc_dec128_log10(t_4), MC_DEC128_ROUND_TOWARD_ZERO, NULL),
|
569
|
+
MC_DEC128(1));
|
570
|
+
|
571
|
+
// We convert precision to a double so we can avoid warning C4146 on Windows.
|
572
|
+
mc_dec128 prc_dec = mc_dec128_from_double((double)precision);
|
573
|
+
|
574
|
+
if (mc_dec128_less(t_5, prc_dec)) {
|
575
|
+
CLIENT_ERR("Invalid value for precision. precision: %" PRId32, precision);
|
576
|
+
return false;
|
577
|
+
}
|
578
|
+
|
579
|
+
mlib_int128 i_1 = dec128_to_int128(scaled_max);
|
580
|
+
mlib_int128 i_2 = dec128_to_int128(scaled_min);
|
581
|
+
|
582
|
+
// Because we have guaranteed earlier that max is greater than min, we can
|
583
|
+
// subtract these values and guarantee that taking their unsigned
|
584
|
+
// representation will yield the actual range result.
|
585
|
+
mlib_int128 range128 = mlib_int128_sub(i_1, i_2);
|
586
|
+
|
587
|
+
if (precision > UINT8_MAX) {
|
588
|
+
CLIENT_ERR("Invalid value for precision. Must be less than 255. precision: %" PRId32, precision);
|
589
|
+
return false;
|
590
|
+
}
|
591
|
+
|
592
|
+
mlib_int128 i_3 = mlib_int128_add(range128, mlib_int128_pow10((uint8_t)precision));
|
593
|
+
if (!ceil_log2_int128(i_3, maxBitsOut, status)) {
|
594
|
+
return false;
|
595
|
+
}
|
596
|
+
|
597
|
+
if (*maxBitsOut >= 128) {
|
598
|
+
return false;
|
599
|
+
}
|
600
|
+
|
601
|
+
return true;
|
602
|
+
}
|
603
|
+
|
604
|
+
bool mc_getTypeInfoDecimal128(mc_getTypeInfoDecimal128_args_t args,
|
605
|
+
mc_OSTType_Decimal128 *out,
|
606
|
+
mongocrypt_status_t *status,
|
607
|
+
bool use_range_v2) {
|
608
|
+
/// Basic param checks
|
609
|
+
if (args.min.set != args.max.set || args.min.set != args.precision.set) {
|
610
|
+
CLIENT_ERR("min, max, and precision must all be set or must all be unset");
|
611
|
+
return false;
|
612
|
+
}
|
613
|
+
|
614
|
+
if (args.precision.set) {
|
615
|
+
if (args.precision.value < 0) {
|
616
|
+
CLIENT_ERR("Precision must be non-negative, but got %" PRId32, args.precision.value);
|
617
|
+
return false;
|
618
|
+
}
|
619
|
+
|
620
|
+
mc_dec128 scaled = mc_dec128_scale(MC_DEC128(1), args.precision.value);
|
621
|
+
if (!mc_dec128_is_finite(scaled)) {
|
622
|
+
CLIENT_ERR("Precision is too large and cannot be used to calculate the scaled range bounds");
|
623
|
+
return false;
|
624
|
+
}
|
625
|
+
}
|
626
|
+
|
627
|
+
// We only accept normal numbers
|
628
|
+
if (mc_dec128_is_inf(args.value) || mc_dec128_is_nan(args.value)) {
|
629
|
+
CLIENT_ERR("Infinity and Nan Decimal128 values are not supported.");
|
630
|
+
return false;
|
631
|
+
}
|
632
|
+
|
633
|
+
// Check boundary if a range is set
|
634
|
+
if (args.min.set) {
|
635
|
+
// [min,max] must be valid
|
636
|
+
if (mc_dec128_greater_equal(args.min.value, args.max.value)) {
|
637
|
+
CLIENT_ERR("The minimum value must be less than the maximum value, got "
|
638
|
+
"min: %s, max: %s",
|
639
|
+
mc_dec128_to_string(args.min.value).str,
|
640
|
+
mc_dec128_to_string(args.max.value).str);
|
641
|
+
return false;
|
642
|
+
}
|
643
|
+
|
644
|
+
// Value must be within [min,max)
|
645
|
+
if (mc_dec128_greater(args.value, args.max.value) || mc_dec128_less(args.value, args.min.value)) {
|
646
|
+
CLIENT_ERR("Value must be greater than or equal to the minimum value "
|
647
|
+
"and less than or equal to the maximum value, got "
|
648
|
+
"min: %s, max: %s, value: %s",
|
649
|
+
mc_dec128_to_string(args.min.value).str,
|
650
|
+
mc_dec128_to_string(args.max.value).str,
|
651
|
+
mc_dec128_to_string(args.value).str);
|
652
|
+
return false;
|
653
|
+
}
|
654
|
+
}
|
655
|
+
|
656
|
+
// Should we use precision mode?
|
657
|
+
//
|
658
|
+
// When we use precision mode, we try to represent as a decimal128 value that
|
659
|
+
// fits in [-2^127, 2^127] (i.e. is a valid int128)
|
660
|
+
//
|
661
|
+
// This check determines if we can represent any precision-truncated value as
|
662
|
+
// a 128-bit integer I.e. Is ((ub - lb) * 10^precision) < 128 bits.
|
663
|
+
//
|
664
|
+
// It is important that we determine whether a range and its precision would
|
665
|
+
// fit, regardless of the value to be encoded, because the encoding for
|
666
|
+
// precision-truncated-decimal128 is incompatible with the encoding of the
|
667
|
+
// full range.
|
668
|
+
bool use_precision_mode = false;
|
669
|
+
// The number of bits required to hold the result (used for precision mode)
|
670
|
+
uint32_t bits_range = 0;
|
671
|
+
if (args.precision.set) {
|
672
|
+
use_precision_mode =
|
673
|
+
mc_canUsePrecisionModeDecimal(args.min.value, args.max.value, args.precision.value, &bits_range, status);
|
674
|
+
|
675
|
+
if (use_range_v2 && !use_precision_mode) {
|
676
|
+
if (!mongocrypt_status_ok(status)) {
|
677
|
+
return false;
|
450
678
|
}
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
//
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
679
|
+
|
680
|
+
CLIENT_ERR("The domain of decimal values specified by the min, max, and precision cannot be represented in "
|
681
|
+
"fewer than 128 bits. min: %s, max: %s, precision: %" PRIu32,
|
682
|
+
mc_dec128_to_string(args.min.value).str,
|
683
|
+
mc_dec128_to_string(args.max.value).str,
|
684
|
+
args.precision.value);
|
685
|
+
return false;
|
686
|
+
}
|
687
|
+
|
688
|
+
// If we are not in range_v2, then we don't care about the error returned
|
689
|
+
// from canUsePrecisionMode so we can reset the status.
|
690
|
+
_mongocrypt_status_reset(status);
|
691
|
+
}
|
692
|
+
|
693
|
+
// Constant zero
|
694
|
+
const mlib_int128 i128_zero = MLIB_INT128(0);
|
695
|
+
// Constant 1
|
696
|
+
const mlib_int128 i128_one = MLIB_INT128(1);
|
697
|
+
// Constant 10
|
698
|
+
const mlib_int128 i128_ten = MLIB_INT128(10);
|
699
|
+
// Constant: 2^127
|
700
|
+
const mlib_int128 i128_2pow127 = mlib_int128_lshift(i128_one, 127);
|
701
|
+
// ↑ Coincidentally has the same bit pattern as INT128_SMIN, but we're
|
702
|
+
// treating it as an unsigned number here, so don't get confused!
|
703
|
+
|
704
|
+
if (use_precision_mode) {
|
705
|
+
BSON_ASSERT(args.precision.set);
|
706
|
+
// Example value: 31.4159
|
707
|
+
// Example Precision = 2
|
708
|
+
|
709
|
+
// Shift the number up
|
710
|
+
// Returns: 3141.9
|
711
|
+
mc_dec128 valScaled = mc_dec128_scale(args.value, args.precision.value);
|
712
|
+
|
713
|
+
// Round the number down
|
714
|
+
// Returns 3141.0
|
715
|
+
mc_dec128 valTrunc = mc_dec128_round_integral_ex(valScaled, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
|
716
|
+
|
717
|
+
// Shift the number down
|
718
|
+
// Returns: 31.41
|
719
|
+
mc_dec128 v_prime = mc_dec128_scale(valTrunc, -(int32_t)args.precision.value);
|
720
|
+
|
721
|
+
// Adjust the number by the lower bound
|
722
|
+
// Make it an integer by scaling the number
|
723
|
+
//
|
724
|
+
// Returns 3141.0
|
725
|
+
mc_dec128 v_prime2 = mc_dec128_scale(mc_dec128_sub(v_prime, args.min.value), args.precision.value);
|
726
|
+
// Round the number down again. min may have a fractional value with more
|
727
|
+
// decimal places than the precision (e.g. .001). Subtracting min may have
|
728
|
+
// resulted in v_prime2 with a non-zero fraction. v_prime2 is expected to
|
729
|
+
// have no fractional value when converting to int128.
|
730
|
+
v_prime2 = mc_dec128_round_integral_ex(v_prime2, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
|
731
|
+
|
732
|
+
BSON_ASSERT(mc_dec128_less(mc_dec128_log2(v_prime2), MC_DEC128(128)));
|
733
|
+
BSON_ASSERT(bits_range < 128);
|
734
|
+
// Resulting OST maximum
|
735
|
+
mlib_int128 ost_max = mlib_int128_sub(mlib_int128_pow2((uint8_t)bits_range), i128_one);
|
736
|
+
|
737
|
+
// Now we need to get the Decimal128 out as a 128-bit integer
|
738
|
+
// But Decimal128 does not support conversion to Int128.
|
739
|
+
//
|
740
|
+
// If we think the Decimal128 fits in the range, based on the maximum
|
741
|
+
// value, we try to convert to int64 directly.
|
742
|
+
if (bits_range < 64) {
|
743
|
+
// Try conversion to int64, it may fail but since it is easy we try
|
744
|
+
// this first.
|
745
|
+
mc_dec128_flagset flags = {0};
|
746
|
+
int64_t as64 = mc_dec128_to_int64_ex(v_prime2, &flags);
|
747
|
+
if (flags.bits == 0) {
|
748
|
+
// No error. It fits
|
749
|
+
*out = (mc_OSTType_Decimal128){
|
750
|
+
.value = MLIB_INT128_CAST(as64),
|
751
|
+
.min = i128_zero,
|
752
|
+
.max = ost_max,
|
753
|
+
};
|
754
|
+
return true;
|
755
|
+
} else {
|
756
|
+
// Conversion failure to 64-bit. Possible overflow, imprecision,
|
757
|
+
// etc. Fallback to slower dec128_to_int128
|
758
|
+
}
|
759
|
+
}
|
760
|
+
|
761
|
+
mlib_int128 u_ret = dec128_to_int128(v_prime2);
|
762
|
+
|
763
|
+
*out = (mc_OSTType_Decimal128){
|
764
|
+
.value = u_ret,
|
765
|
+
.min = i128_zero,
|
766
|
+
.max = ost_max,
|
767
|
+
};
|
768
|
+
|
769
|
+
return true;
|
770
|
+
}
|
771
|
+
|
772
|
+
// The coefficient of the number, without exponent/sign
|
773
|
+
const mlib_int128 coeff = mc_dec128_coeff(args.value);
|
774
|
+
|
775
|
+
if (mlib_int128_eq(coeff, i128_zero)) {
|
776
|
+
// If the coefficient is zero, the result is encoded as the midpoint
|
777
|
+
// between zero and 2^128-1
|
778
|
+
*out = (mc_OSTType_Decimal128){
|
779
|
+
.value = i128_2pow127,
|
780
|
+
.min = i128_zero,
|
781
|
+
.max = MLIB_INT128_UMAX,
|
782
|
+
};
|
783
|
+
return true;
|
784
|
+
}
|
785
|
+
|
786
|
+
// Coefficient is an unsigned value. We'll later scale our answer based on
|
787
|
+
// the sign of the actual Decimal128
|
788
|
+
const bool isNegative = mc_dec128_is_negative(args.value);
|
789
|
+
|
790
|
+
// cMax = 10^34 - 1 (The largest integer representable in Decimal128)
|
791
|
+
const mlib_int128 cMax = mlib_int128_sub(mlib_int128_pow10(34), MLIB_INT128_CAST(1));
|
792
|
+
const mlib_int128 cMax_div_ten = mlib_int128_div(cMax, i128_ten);
|
793
|
+
|
794
|
+
// The biased exponent from the decimal number. The paper refers to the
|
795
|
+
// expression (e - e_min), which is the value of the biased exponent.
|
796
|
+
const uint32_t exp_biased = mc_dec128_get_biased_exp(args.value);
|
797
|
+
|
798
|
+
// ρ (rho) is the greatest integer such that: coeff×10^ρ <= cMax
|
799
|
+
unsigned rho = 0;
|
800
|
+
// Keep track of the subexpression coeff×10^ρ rather than recalculating it
|
801
|
+
// time.
|
802
|
+
// Initially: (ρ = 0) -> (10^ρ = 1) -> (coeff×10^ρ = coeff×1 = coeff):
|
803
|
+
mlib_int128 coeff_scaled = coeff;
|
804
|
+
// Calculate ρ: This could be done using a log10 with a division, but that
|
805
|
+
// is far more work than just a few multiplications.
|
806
|
+
// While: coeff×ten^ρ < cMax/10:
|
807
|
+
while (mlib_int128_ucmp(coeff_scaled, cMax_div_ten) < 0) {
|
808
|
+
// Increase rho until we pass cMax/10
|
809
|
+
rho++;
|
810
|
+
// Scale our computed subexpression rather than fully recomputing it
|
811
|
+
coeff_scaled = mlib_int128_mul(coeff_scaled, i128_ten);
|
812
|
+
}
|
813
|
+
|
814
|
+
// No multiplication by 10 should ever send us from N < cMax/10 to N > cMax
|
815
|
+
BSON_ASSERT(mlib_int128_ucmp(coeff_scaled, cMax) <= 0);
|
816
|
+
|
817
|
+
mlib_int128 result;
|
818
|
+
if (rho <= exp_biased) {
|
819
|
+
// ρ is less-than/equal to the exponent with bias.
|
820
|
+
|
821
|
+
// Diff between the biased exponent and ρ.
|
822
|
+
// Value in paper is spelled "e - e_min - ρ"
|
823
|
+
const uint32_t exp_diff = exp_biased - (uint32_t)rho;
|
824
|
+
// cMax * (exp_diff)
|
825
|
+
const mlib_int128 cmax_scaled = mlib_int128_mul(cMax, MLIB_INT128_CAST(exp_diff));
|
826
|
+
// coeff * 10^rho * cMax * (exp_biased - rho)
|
827
|
+
result = mlib_int128_add(coeff_scaled, cmax_scaled);
|
828
|
+
} else {
|
829
|
+
const mlib_int128 biased_scale = mlib_int128_pow10((uint8_t)exp_biased);
|
830
|
+
result = mlib_int128_mul(biased_scale, coeff);
|
831
|
+
}
|
832
|
+
|
833
|
+
// Always add 2^127:
|
834
|
+
result = mlib_int128_add(result, i128_2pow127);
|
835
|
+
|
836
|
+
if (isNegative) {
|
837
|
+
// We calculated the value of the positive coefficient, but the decimal is
|
838
|
+
// negative. That's okay: Just flip the sign of the encoded result:
|
839
|
+
result = mlib_int128_negate(result);
|
840
|
+
}
|
841
|
+
|
842
|
+
*out = (mc_OSTType_Decimal128){
|
843
|
+
.value = result,
|
844
|
+
.min = i128_zero,
|
845
|
+
.max = MLIB_INT128_UMAX,
|
846
|
+
};
|
847
|
+
|
848
|
+
return true;
|
618
849
|
}
|
619
850
|
|
620
851
|
#endif // defined MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
|
852
|
+
|
853
|
+
const int64_t mc_FLERangeSparsityDefault = 2;
|
854
|
+
const int32_t mc_FLERangeTrimFactorDefault = 6;
|
855
|
+
|
856
|
+
int32_t trimFactorDefault(size_t maxlen, mc_optional_int32_t trimFactor, bool use_range_v2) {
|
857
|
+
if (trimFactor.set) {
|
858
|
+
return trimFactor.value;
|
859
|
+
}
|
860
|
+
|
861
|
+
if (!use_range_v2) {
|
862
|
+
// Preserve old default.
|
863
|
+
return 0;
|
864
|
+
}
|
865
|
+
|
866
|
+
if (bson_cmp_greater_su(mc_FLERangeTrimFactorDefault, maxlen - 1)) {
|
867
|
+
return (int32_t)(maxlen - 1);
|
868
|
+
} else {
|
869
|
+
return mc_FLERangeTrimFactorDefault;
|
870
|
+
}
|
871
|
+
}
|