PHPC-2727 PHPC-2728: Bump libmongocrypt 1.19.2 and add stringOpts support#2033
PHPC-2727 PHPC-2728: Bump libmongocrypt 1.19.2 and add stringOpts support#2033GromNaN wants to merge 6 commits into
stringOpts support#2033Conversation
Implements the stringOpts option for explicit string encryption, supporting prefix, suffix, and substring query types with case/diacritic sensitivity options, as required by the QE String Explicit Encryption spec (DRIVERS-3321).
ClientEncryption::encrypt()
Apply clang-format alignment fixes and add a phpt integration test for ClientEncryption::encrypt() with the stringOpts option (substringPreview).
ClientEncryption::encrypt()stringOpts support to ClientEncryption::encrypt()
stringOpts support to ClientEncryption::encrypt()stringOpts support
There was a problem hiding this comment.
Pull request overview
Bumps the bundled/system minimum libmongocrypt version to 1.19.2 and wires stringOpts through MongoDB\Driver\ClientEncryption::encrypt() to support QE string encryption options (case/diacritic sensitivity and prefix/suffix/substring parameters).
Changes:
- Add C driver support for
stringOptsby translating PHP arrays intomongoc_client_encryption_encrypt_text_opts_t. - Add PHPT coverage for successful
substringPreviewencryption and for integer range validation errors withinstringOpts. - Bump libmongocrypt version references to 1.19.2 (current version file + system minimum in
config.m4).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/clientEncryption/clientEncryption-encrypt-stringOpts-001.phpt | New integration test covering successful encryption with stringOpts (substringPreview). |
| tests/clientEncryption/clientEncryption-encrypt-stringOpts_error-001.phpt | New test covering stringOpts integer range validation error messages. |
| src/MongoDB/ClientEncryption.c | Adds stringOpts parsing and passes resulting text opts into libmongoc encryption options. |
| src/LIBMONGOCRYPT_VERSION_CURRENT | Updates bundled/current libmongocrypt version marker to 1.19.2. |
| config.m4 | Raises the minimum required system libmongocrypt version to 1.19.2. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| int64_t v = php_array_fetchc_long(prefix_zval, "strMaxQueryLength"); | ||
|
|
||
| if (v < 0 || v > INT32_MAX) { | ||
| phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"strMaxQueryLength\" to be a positive 32-bit integer, %" PRId64 " given", v); | ||
| mongoc_client_encryption_encrypt_text_prefix_opts_destroy(prefix_opts); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| mongoc_client_encryption_encrypt_text_prefix_opts_set_str_max_query_length(prefix_opts, (int32_t) v); |
| bson_value_destroy(&keyid); | ||
| } | ||
|
|
||
| static mongoc_client_encryption_encrypt_text_opts_t* phongo_clientencryption_encrypt_text_opts_from_zval(zval* options) |
There was a problem hiding this comment.
The name text_opts is inherited from libmongoc/libmongocrypt.
There was a problem hiding this comment.
Heads up: the "text" named C driver API is deprecated for newly added "string" names in CDRIVER-6293. But this is not-yet released. It will be released in C driver 2.4.0.
There was a problem hiding this comment.
So, this PR can wait the release of C driver 2.4.0.
| bson_value_destroy(&keyid); | ||
| } | ||
|
|
||
| static mongoc_client_encryption_encrypt_text_opts_t* phongo_clientencryption_encrypt_text_opts_from_zval(zval* options) |
There was a problem hiding this comment.
Heads up: the "text" named C driver API is deprecated for newly added "string" names in CDRIVER-6293. But this is not-yet released. It will be released in C driver 2.4.0.
| if (v < 0 || v > INT32_MAX) { | ||
| phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"strMaxQueryLength\" to be a positive 32-bit integer, %" PRId64 " given", v); | ||
| mongoc_client_encryption_encrypt_text_prefix_opts_destroy(prefix_opts); | ||
| goto cleanup; | ||
| } |
There was a problem hiding this comment.
| if (v < 0 || v > INT32_MAX) { | |
| phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"strMaxQueryLength\" to be a positive 32-bit integer, %" PRId64 " given", v); | |
| mongoc_client_encryption_encrypt_text_prefix_opts_destroy(prefix_opts); | |
| goto cleanup; | |
| } | |
| if (v < INT32_MIN || v > INT32_MAX) { | |
| phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"strMaxQueryLength\" to be a 32-bit integer, %" PRId64 " given", v); | |
| mongoc_client_encryption_encrypt_text_prefix_opts_destroy(prefix_opts); | |
| goto cleanup; | |
| } |
Minor: consider only checking that v fits within an int32 before the (int32_t) cast. libmongocrypt further validates the value is greater than 0. This may help avoid a needed change in the PHP driver if that validation is ever changed in libmongocrypt to include 0.
Similar suggestion applies to other int32 checks.
There was a problem hiding this comment.
Done. Note that the behavior changes slightly: values that are negative but fit in an int32 (e.g. -1) are no longer rejected by the PHP driver and instead reach libmongocrypt, which throws an EncryptionException ("'strMaxQueryLength' must be greater than zero"). Values that overflow int32 (e.g. PHP_INT_MAX) are still caught early as InvalidArgumentException. The phpt test has been updated to cover both cases.
Bumps libmongocrypt from 1.19.0 to 1.19.2 and adds support for the
stringOptsoption inClientEncryption::encrypt()for QE string encryption (prefix, suffix, substring query types with case/diacritic sensitivity).Jira: https://jira.mongodb.org/browse/PHPC-2727
Jira: https://jira.mongodb.org/browse/PHPC-2728