libmongocrypt-helper 1.7.4.0.1002 → 1.8.0.0.1001
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
- data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
- data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
- data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
- data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
- data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
- data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
- data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
- data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
- data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
- data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
- data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
- data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
- data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
- data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
- data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
- data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
- data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
- data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
- data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
- data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
- data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
- data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
- data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
- data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
- data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
- data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
- data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
- data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
- data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
- data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
- data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
- data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
- data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
- data/lib/libmongocrypt_helper/version.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +154 -26
- metadata.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
- /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -31,287 +31,263 @@
|
|
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
|
-
bool
|
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
|
-
(range + 1) * exp10Double (args.precision.value);
|
251
|
-
|
252
|
-
if (mc_isfinite (rangeAndPrecision)) {
|
253
|
-
double bits_range_double = log2 (rangeAndPrecision);
|
254
|
-
bits_range = (uint32_t) ceil (bits_range_double);
|
255
|
-
|
256
|
-
if (bits_range < 64) {
|
257
|
-
use_precision_mode = true;
|
164
|
+
#define exp10Double(x) pow(10, x)
|
165
|
+
|
166
|
+
bool mc_getTypeInfoDouble(mc_getTypeInfoDouble_args_t args, mc_OSTType_Double *out, mongocrypt_status_t *status) {
|
167
|
+
if (args.min.set != args.max.set || args.min.set != args.precision.set) {
|
168
|
+
CLIENT_ERR("min, max, and precision must all be set or must all be unset");
|
169
|
+
return false;
|
170
|
+
}
|
171
|
+
|
172
|
+
if (mc_isinf(args.value) || mc_isnan(args.value)) {
|
173
|
+
CLIENT_ERR("Infinity and NaN double values are not supported.");
|
174
|
+
return false;
|
175
|
+
}
|
176
|
+
|
177
|
+
if (args.min.set) {
|
178
|
+
if (args.min.value >= args.max.value) {
|
179
|
+
CLIENT_ERR("The minimum value must be less than the maximum value, got "
|
180
|
+
"min: %g, max: %g",
|
181
|
+
args.min.value,
|
182
|
+
args.max.value);
|
183
|
+
return false;
|
184
|
+
}
|
185
|
+
|
186
|
+
if (args.value > args.max.value || args.value < args.min.value) {
|
187
|
+
CLIENT_ERR("Value must be greater than or equal to the minimum value "
|
188
|
+
"and less than or equal to the maximum value, got "
|
189
|
+
"min: %g, max: %g, value: %g",
|
190
|
+
args.min.value,
|
191
|
+
args.max.value,
|
192
|
+
args.value);
|
193
|
+
return false;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
const bool is_neg = args.value < 0.0;
|
198
|
+
|
199
|
+
// Map negative 0 to zero so sign bit is 0.
|
200
|
+
if (args.value == 0.0) {
|
201
|
+
args.value = 0.0;
|
202
|
+
}
|
203
|
+
|
204
|
+
// When we use precision mode, we try to represent as a double value that
|
205
|
+
// fits in [-2^63, 2^63] (i.e. is a valid int64)
|
206
|
+
//
|
207
|
+
// This check determines if we can represent the precision truncated value as
|
208
|
+
// a 64-bit integer I.e. Is ((ub - lb) * 10^precision) < 64 bits.
|
209
|
+
//
|
210
|
+
bool use_precision_mode = false;
|
211
|
+
uint32_t bits_range;
|
212
|
+
if (args.precision.set) {
|
213
|
+
// Subnormal representations can support up to 5x10^-324 as a number
|
214
|
+
if (args.precision.value > 324) {
|
215
|
+
CLIENT_ERR("Precision must be between 0 and 324 inclusive, got: %" PRIu32, args.precision.value);
|
216
|
+
return false;
|
217
|
+
}
|
218
|
+
|
219
|
+
double range = args.max.value - args.min.value;
|
220
|
+
|
221
|
+
// We can overflow if max = max double and min = min double so make sure
|
222
|
+
// we have finite number after we do subtraction
|
223
|
+
// Ignore conversion warnings to fix error with glibc.
|
224
|
+
if (mc_isfinite(range)) {
|
225
|
+
// This creates a range which is wider then we permit by our min/max
|
226
|
+
// bounds check with the +1 but it is as the algorithm is written in
|
227
|
+
// WRITING-11907.
|
228
|
+
double rangeAndPrecision = (range + 1) * exp10Double(args.precision.value);
|
229
|
+
|
230
|
+
if (mc_isfinite(rangeAndPrecision)) {
|
231
|
+
double bits_range_double = log2(rangeAndPrecision);
|
232
|
+
bits_range = (uint32_t)ceil(bits_range_double);
|
233
|
+
|
234
|
+
if (bits_range < 64) {
|
235
|
+
use_precision_mode = true;
|
236
|
+
}
|
258
237
|
}
|
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
|
-
*out = (mc_OSTType_Double){.min = 0, .max = UINT64_MAX, .value = uv};
|
313
|
-
|
314
|
-
return true;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
if (use_precision_mode) {
|
242
|
+
// Take a number of xxxx.ppppp and truncate it xxxx.ppp if precision = 3.
|
243
|
+
// We do not change the digits before the decimal place.
|
244
|
+
double v_prime = trunc(args.value * exp10Double(args.precision.value)) / exp10Double(args.precision.value);
|
245
|
+
int64_t v_prime2 = (int64_t)((v_prime - args.min.value) * exp10Double(args.precision.value));
|
246
|
+
|
247
|
+
BSON_ASSERT(v_prime2 < INT64_MAX && v_prime2 >= 0);
|
248
|
+
|
249
|
+
uint64_t ret = (uint64_t)v_prime2;
|
250
|
+
|
251
|
+
// Adjust maximum value to be the max bit range. This will be used by
|
252
|
+
// getEdges/minCover to trim bits.
|
253
|
+
uint64_t max_value = (UINT64_C(1) << bits_range) - 1;
|
254
|
+
BSON_ASSERT(ret <= max_value);
|
255
|
+
|
256
|
+
*out = (mc_OSTType_Double){ret, 0, max_value};
|
257
|
+
return true;
|
258
|
+
}
|
259
|
+
|
260
|
+
// Translate double to uint64 by modifying the bit representation and copying
|
261
|
+
// into a uint64. Double is assumed to be a IEEE 754 Binary 64.
|
262
|
+
// It is bit-encoded as sign, exponent, and fraction:
|
263
|
+
// s eeeeeeee ffffffffffffffffffffffffffffffffffffffffffffffffffff
|
264
|
+
|
265
|
+
// When we translate the double into "bits", the sign bit means that the
|
266
|
+
// negative numbers get mapped into the higher 63 bits of a 64-bit integer.
|
267
|
+
// We want them to map into the lower 64-bits so we invert the sign bit.
|
268
|
+
args.value *= -1.0;
|
269
|
+
|
270
|
+
// On Endianness, we support two sets of architectures
|
271
|
+
// 1. Little Endian (ppc64le, x64, aarch64) - in these architectures, int64
|
272
|
+
// and double are both 64-bits and both arranged in little endian byte order.
|
273
|
+
// 2. Big Endian (s390x) - in these architectures, int64 and double are both
|
274
|
+
// 64-bits and both arranged in big endian byte order.
|
275
|
+
//
|
276
|
+
// Therefore, since the order of bytes on each platform is consistent with
|
277
|
+
// itself, the conversion below converts a double into correct 64-bit integer
|
278
|
+
// that produces the same behavior across plaforms.
|
279
|
+
uint64_t uv;
|
280
|
+
memcpy(&uv, &args.value, sizeof(uint64_t));
|
281
|
+
|
282
|
+
if (is_neg) {
|
283
|
+
uint64_t new_zero = UINT64_C(1) << 63;
|
284
|
+
BSON_ASSERT(uv <= new_zero);
|
285
|
+
uv = new_zero - uv;
|
286
|
+
}
|
287
|
+
|
288
|
+
*out = (mc_OSTType_Double){.min = 0, .max = UINT64_MAX, .value = uv};
|
289
|
+
|
290
|
+
return true;
|
315
291
|
}
|
316
292
|
|
317
293
|
#if MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
|
@@ -322,299 +298,280 @@ mc_getTypeInfoDouble (mc_getTypeInfoDouble_args_t args,
|
|
322
298
|
* @param dec
|
323
299
|
* @return mlib_int128
|
324
300
|
*/
|
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
|
-
return ret;
|
301
|
+
static mlib_int128 dec128_to_int128(mc_dec128 dec) {
|
302
|
+
// Only normal numbers
|
303
|
+
BSON_ASSERT(mc_dec128_is_finite(dec));
|
304
|
+
BSON_ASSERT(!mc_dec128_is_nan(dec));
|
305
|
+
// We don't support negative numbers
|
306
|
+
BSON_ASSERT(!mc_dec128_is_negative(dec));
|
307
|
+
// There is no fractional part:
|
308
|
+
BSON_ASSERT(mc_dec128_is_zero(mc_dec128_modf(dec).frac));
|
309
|
+
|
310
|
+
mlib_int128 ret = mc_dec128_coeff(dec);
|
311
|
+
|
312
|
+
// Scale the resulting number by a power of ten matching the exponent of the
|
313
|
+
// Decimal128:
|
314
|
+
int32_t exp = ((int32_t)mc_dec128_get_biased_exp(dec)) - MC_DEC128_EXPONENT_BIAS;
|
315
|
+
// We will scale up/down based on whether it is negative:
|
316
|
+
mlib_int128 e1 = mlib_int128_pow10((uint8_t)abs(exp));
|
317
|
+
if (exp < 0) {
|
318
|
+
ret = mlib_int128_div(ret, e1);
|
319
|
+
} else {
|
320
|
+
ret = mlib_int128_mul(ret, e1);
|
321
|
+
}
|
322
|
+
|
323
|
+
return ret;
|
351
324
|
}
|
352
325
|
|
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
|
-
bits_range_dec, MC_DEC128_ROUND_UPWARD, NULL));
|
443
|
-
BSON_ASSERT (r >= 0);
|
444
|
-
BSON_ASSERT (r <= UINT8_MAX);
|
445
|
-
// We've computed the proper 'bits_range'
|
446
|
-
bits_range = (uint8_t) r;
|
447
|
-
|
448
|
-
if (bits_range < 128) {
|
449
|
-
use_precision_mode = true;
|
326
|
+
bool mc_getTypeInfoDecimal128(mc_getTypeInfoDecimal128_args_t args,
|
327
|
+
mc_OSTType_Decimal128 *out,
|
328
|
+
mongocrypt_status_t *status) {
|
329
|
+
/// Basic param checks
|
330
|
+
if (args.min.set != args.max.set || args.min.set != args.precision.set) {
|
331
|
+
CLIENT_ERR("min, max, and precision must all be set or must all be unset");
|
332
|
+
return false;
|
333
|
+
}
|
334
|
+
|
335
|
+
// We only accept normal numbers
|
336
|
+
if (mc_dec128_is_inf(args.value) || mc_dec128_is_nan(args.value)) {
|
337
|
+
CLIENT_ERR("Infinity and Nan Decimal128 values are not supported.");
|
338
|
+
return false;
|
339
|
+
}
|
340
|
+
|
341
|
+
// Check boundary if a range is set
|
342
|
+
if (args.min.set) {
|
343
|
+
// [min,max] must be valid
|
344
|
+
if (mc_dec128_greater_equal(args.min.value, args.max.value)) {
|
345
|
+
CLIENT_ERR("The minimum value must be less than the maximum value, got "
|
346
|
+
"min: %s, max: %s",
|
347
|
+
mc_dec128_to_string(args.min.value).str,
|
348
|
+
mc_dec128_to_string(args.max.value).str);
|
349
|
+
return false;
|
350
|
+
}
|
351
|
+
|
352
|
+
// Value must be within [min,max)
|
353
|
+
if (mc_dec128_greater(args.value, args.max.value) || mc_dec128_less(args.value, args.min.value)) {
|
354
|
+
CLIENT_ERR("Value must be greater than or equal to the minimum value "
|
355
|
+
"and less than or equal to the maximum value, got "
|
356
|
+
"min: %s, max: %s, value: %s",
|
357
|
+
mc_dec128_to_string(args.min.value).str,
|
358
|
+
mc_dec128_to_string(args.max.value).str,
|
359
|
+
mc_dec128_to_string(args.value).str);
|
360
|
+
return false;
|
361
|
+
}
|
362
|
+
}
|
363
|
+
|
364
|
+
// Should we use precision mode?
|
365
|
+
//
|
366
|
+
// When we use precision mode, we try to represent as a decimal128 value that
|
367
|
+
// fits in [-2^127, 2^127] (i.e. is a valid int128)
|
368
|
+
//
|
369
|
+
// This check determines if we can represent any precision-truncated value as
|
370
|
+
// a 128-bit integer I.e. Is ((ub - lb) * 10^precision) < 128 bits.
|
371
|
+
//
|
372
|
+
// It is important that we determine whether a range and its precision would
|
373
|
+
// fit, regardless of the value to be encoded, because the encoding for
|
374
|
+
// precision-truncated-decimal128 is incompatible with the encoding of the
|
375
|
+
// full range.
|
376
|
+
bool use_precision_mode = false;
|
377
|
+
// The number of bits required to hold the result (used for precision mode)
|
378
|
+
uint8_t bits_range = 0;
|
379
|
+
if (args.precision.set) {
|
380
|
+
// Subnormal representations can support up to 5x10^-6182 as a number
|
381
|
+
if (args.precision.value > 6182) {
|
382
|
+
CLIENT_ERR("Precision must be between 0 and 6182 inclusive, got: %" PRIu32, args.precision.value);
|
383
|
+
return false;
|
384
|
+
}
|
385
|
+
|
386
|
+
// max - min
|
387
|
+
mc_dec128 bounds_n1 = mc_dec128_sub(args.max.value, args.min.value);
|
388
|
+
// The size of [min, max]: (max - min) + 1
|
389
|
+
mc_dec128 bounds = mc_dec128_add(bounds_n1, MC_DEC128_ONE);
|
390
|
+
|
391
|
+
// We can overflow if max = max_dec128 and min = min_dec128 so make sure
|
392
|
+
// we have finite number after we do subtraction
|
393
|
+
if (mc_dec128_is_finite(bounds)) {
|
394
|
+
// This creates a range which is wider then we permit by our min/max
|
395
|
+
// bounds check with the +1 but it is as the algorithm is written in
|
396
|
+
// WRITING-11907.
|
397
|
+
mc_dec128 precision_scaled_bounds = mc_dec128_scale(bounds, args.precision.value);
|
398
|
+
/// The number of bits required to hold the result for the given
|
399
|
+
/// precision (as decimal)
|
400
|
+
mc_dec128 bits_range_dec = mc_dec128_log2(precision_scaled_bounds);
|
401
|
+
|
402
|
+
if (mc_dec128_is_finite(bits_range_dec) && mc_dec128_less(bits_range_dec, MC_DEC128(128))) {
|
403
|
+
// We need fewer than 128 bits to hold the result. But round up,
|
404
|
+
// just to be sure:
|
405
|
+
int64_t r =
|
406
|
+
mc_dec128_to_int64(mc_dec128_round_integral_ex(bits_range_dec, MC_DEC128_ROUND_UPWARD, NULL));
|
407
|
+
BSON_ASSERT(r >= 0);
|
408
|
+
BSON_ASSERT(r <= UINT8_MAX);
|
409
|
+
// We've computed the proper 'bits_range'
|
410
|
+
bits_range = (uint8_t)r;
|
411
|
+
|
412
|
+
if (bits_range < 128) {
|
413
|
+
use_precision_mode = true;
|
414
|
+
}
|
450
415
|
}
|
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
|
-
*out = (mc_OSTType_Decimal128){
|
612
|
-
.value = result,
|
613
|
-
.min = i128_zero,
|
614
|
-
.max = MLIB_INT128_UMAX,
|
615
|
-
};
|
616
|
-
|
617
|
-
return true;
|
416
|
+
}
|
417
|
+
}
|
418
|
+
|
419
|
+
// Constant zero
|
420
|
+
const mlib_int128 i128_zero = MLIB_INT128(0);
|
421
|
+
// Constant 1
|
422
|
+
const mlib_int128 i128_one = MLIB_INT128(1);
|
423
|
+
// Constant 10
|
424
|
+
const mlib_int128 i128_ten = MLIB_INT128(10);
|
425
|
+
// Constant: 2^127
|
426
|
+
const mlib_int128 i128_2pow127 = mlib_int128_lshift(i128_one, 127);
|
427
|
+
// ↑ Coincidentally has the same bit pattern as INT128_SMIN, but we're
|
428
|
+
// treating it as an unsigned number here, so don't get confused!
|
429
|
+
|
430
|
+
if (use_precision_mode) {
|
431
|
+
BSON_ASSERT(args.precision.set);
|
432
|
+
// Example value: 31.4159
|
433
|
+
// Example Precision = 2
|
434
|
+
|
435
|
+
// Shift the number up
|
436
|
+
// Returns: 3141.9
|
437
|
+
mc_dec128 valScaled = mc_dec128_scale(args.value, args.precision.value);
|
438
|
+
|
439
|
+
// Round the number down
|
440
|
+
// Returns 3141.0
|
441
|
+
mc_dec128 valTrunc = mc_dec128_round_integral_ex(valScaled, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
|
442
|
+
|
443
|
+
// Shift the number down
|
444
|
+
// Returns: 31.41
|
445
|
+
mc_dec128 v_prime = mc_dec128_scale(valTrunc, -(int32_t)args.precision.value);
|
446
|
+
|
447
|
+
// Adjust the number by the lower bound
|
448
|
+
// Make it an integer by scaling the number
|
449
|
+
//
|
450
|
+
// Returns 3141.0
|
451
|
+
mc_dec128 v_prime2 = mc_dec128_scale(mc_dec128_sub(v_prime, args.min.value), args.precision.value);
|
452
|
+
// Round the number down again. min may have a fractional value with more
|
453
|
+
// decimal places than the precision (e.g. .001). Subtracting min may have
|
454
|
+
// resulted in v_prime2 with a non-zero fraction. v_prime2 is expected to
|
455
|
+
// have no fractional value when converting to int128.
|
456
|
+
v_prime2 = mc_dec128_round_integral_ex(v_prime2, MC_DEC128_ROUND_TOWARD_ZERO, NULL);
|
457
|
+
|
458
|
+
BSON_ASSERT(mc_dec128_less(mc_dec128_log2(v_prime2), MC_DEC128(128)));
|
459
|
+
|
460
|
+
// Resulting OST maximum
|
461
|
+
mlib_int128 ost_max = mlib_int128_sub(mlib_int128_pow2(bits_range), i128_one);
|
462
|
+
|
463
|
+
// Now we need to get the Decimal128 out as a 128-bit integer
|
464
|
+
// But Decimal128 does not support conversion to Int128.
|
465
|
+
//
|
466
|
+
// If we think the Decimal128 fits in the range, based on the maximum
|
467
|
+
// value, we try to convert to int64 directly.
|
468
|
+
if (bits_range < 64) {
|
469
|
+
// Try conversion to int64, it may fail but since it is easy we try
|
470
|
+
// this first.
|
471
|
+
mc_dec128_flagset flags = {0};
|
472
|
+
int64_t as64 = mc_dec128_to_int64_ex(v_prime2, &flags);
|
473
|
+
if (flags.bits == 0) {
|
474
|
+
// No error. It fits
|
475
|
+
*out = (mc_OSTType_Decimal128){
|
476
|
+
.value = MLIB_INT128_CAST(as64),
|
477
|
+
.min = i128_zero,
|
478
|
+
.max = ost_max,
|
479
|
+
};
|
480
|
+
return true;
|
481
|
+
} else {
|
482
|
+
// Conversion failure to 64-bit. Possible overflow, imprecision,
|
483
|
+
// etc. Fallback to slower dec128_to_int128
|
484
|
+
}
|
485
|
+
}
|
486
|
+
|
487
|
+
mlib_int128 u_ret = dec128_to_int128(v_prime2);
|
488
|
+
|
489
|
+
*out = (mc_OSTType_Decimal128){
|
490
|
+
.value = u_ret,
|
491
|
+
.min = i128_zero,
|
492
|
+
.max = ost_max,
|
493
|
+
};
|
494
|
+
|
495
|
+
return true;
|
496
|
+
}
|
497
|
+
|
498
|
+
// The coefficient of the number, without exponent/sign
|
499
|
+
const mlib_int128 coeff = mc_dec128_coeff(args.value);
|
500
|
+
|
501
|
+
if (mlib_int128_eq(coeff, i128_zero)) {
|
502
|
+
// If the coefficient is zero, the result is encoded as the midpoint
|
503
|
+
// between zero and 2^128-1
|
504
|
+
*out = (mc_OSTType_Decimal128){
|
505
|
+
.value = i128_2pow127,
|
506
|
+
.min = i128_zero,
|
507
|
+
.max = MLIB_INT128_UMAX,
|
508
|
+
};
|
509
|
+
return true;
|
510
|
+
}
|
511
|
+
|
512
|
+
// Coefficient is an unsigned value. We'll later scale our answer based on
|
513
|
+
// the sign of the actual Decimal128
|
514
|
+
const bool isNegative = mc_dec128_is_negative(args.value);
|
515
|
+
|
516
|
+
// cMax = 10^34 - 1 (The largest integer representable in Decimal128)
|
517
|
+
const mlib_int128 cMax = mlib_int128_sub(mlib_int128_pow10(34), MLIB_INT128_CAST(1));
|
518
|
+
const mlib_int128 cMax_div_ten = mlib_int128_div(cMax, i128_ten);
|
519
|
+
|
520
|
+
// The biased exponent from the decimal number. The paper refers to the
|
521
|
+
// expression (e - e_min), which is the value of the biased exponent.
|
522
|
+
const uint32_t exp_biased = mc_dec128_get_biased_exp(args.value);
|
523
|
+
|
524
|
+
// ρ (rho) is the greatest integer such that: coeff×10^ρ <= cMax
|
525
|
+
unsigned rho = 0;
|
526
|
+
// Keep track of the subexpression coeff×10^ρ rather than recalculating it
|
527
|
+
// time.
|
528
|
+
// Initially: (ρ = 0) -> (10^ρ = 1) -> (coeff×10^ρ = coeff×1 = coeff):
|
529
|
+
mlib_int128 coeff_scaled = coeff;
|
530
|
+
// Calculate ρ: This could be done using a log10 with a division, but that
|
531
|
+
// is far more work than just a few multiplications.
|
532
|
+
// While: coeff×ten^ρ < cMax/10:
|
533
|
+
while (mlib_int128_ucmp(coeff_scaled, cMax_div_ten) < 0) {
|
534
|
+
// Increase rho until we pass cMax/10
|
535
|
+
rho++;
|
536
|
+
// Scale our computed subexpression rather than fully recomputing it
|
537
|
+
coeff_scaled = mlib_int128_mul(coeff_scaled, i128_ten);
|
538
|
+
}
|
539
|
+
|
540
|
+
// No multiplication by 10 should ever send us from N < cMax/10 to N > cMax
|
541
|
+
BSON_ASSERT(mlib_int128_ucmp(coeff_scaled, cMax) <= 0);
|
542
|
+
|
543
|
+
mlib_int128 result;
|
544
|
+
if (rho <= exp_biased) {
|
545
|
+
// ρ is less-than/equal to the exponent with bias.
|
546
|
+
|
547
|
+
// Diff between the biased exponent and ρ.
|
548
|
+
// Value in paper is spelled "e - e_min - ρ"
|
549
|
+
const uint32_t exp_diff = exp_biased - (uint32_t)rho;
|
550
|
+
// cMax * (exp_diff)
|
551
|
+
const mlib_int128 cmax_scaled = mlib_int128_mul(cMax, MLIB_INT128_CAST(exp_diff));
|
552
|
+
// coeff * 10^rho * cMax * (exp_biased - rho)
|
553
|
+
result = mlib_int128_add(coeff_scaled, cmax_scaled);
|
554
|
+
} else {
|
555
|
+
const mlib_int128 biased_scale = mlib_int128_pow10((uint8_t)exp_biased);
|
556
|
+
result = mlib_int128_mul(biased_scale, coeff);
|
557
|
+
}
|
558
|
+
|
559
|
+
// Always add 2^127:
|
560
|
+
result = mlib_int128_add(result, i128_2pow127);
|
561
|
+
|
562
|
+
if (isNegative) {
|
563
|
+
// We calculated the value of the positive coefficient, but the decimal is
|
564
|
+
// negative. That's okay: Just flip the sign of the encoded result:
|
565
|
+
result = mlib_int128_negate(result);
|
566
|
+
}
|
567
|
+
|
568
|
+
*out = (mc_OSTType_Decimal128){
|
569
|
+
.value = result,
|
570
|
+
.min = i128_zero,
|
571
|
+
.max = MLIB_INT128_UMAX,
|
572
|
+
};
|
573
|
+
|
574
|
+
return true;
|
618
575
|
}
|
619
576
|
|
620
577
|
#endif // defined MONGOCRYPT_HAVE_DECIMAL128_SUPPORT
|