Skip to content

PHPC-2401: Support QEv2 range protocol #1583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/MongoDB/ClientEncryption.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,17 @@ static mongoc_client_encryption_encrypt_range_opts_t* phongo_clientencryption_en
return opts;
}

if (php_array_existsc(options, "trimFactor")) {
int64_t trimfactor = php_array_fetchc_long(options, "trimFactor");

if (trimfactor < 0 || trimfactor > INT32_MAX) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"trimFactor\" range option to be a positive 32-bit integer, %" PRId64 " given", trimfactor);
goto cleanup;
}

mongoc_client_encryption_encrypt_range_opts_set_trim_factor(opts, (int32_t) trimfactor);
}

if (php_array_existsc(options, "sparsity")) {
int64_t sparsity = php_array_fetchc_long(options, "sparsity");

Expand Down
14 changes: 14 additions & 0 deletions src/MongoDB/ClientEncryption.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ final class ClientEncryption
public const ALGORITHM_UNINDEXED = UNKNOWN;

/**
* @var string
* @cvalue MONGOC_ENCRYPT_ALGORITHM_RANGE
*/
public const ALGORITHM_RANGE = UNKNOWN;

/**
* @deprecated
* @var string
* @cvalue MONGOC_ENCRYPT_ALGORITHM_RANGEPREVIEW
*/
Expand All @@ -46,6 +53,13 @@ final class ClientEncryption
public const QUERY_TYPE_EQUALITY = UNKNOWN;

/**
* @var string
* @cvalue MONGOC_ENCRYPT_QUERY_TYPE_RANGE
*/
public const QUERY_TYPE_RANGE = UNKNOWN;

/**
* @deprecated
* @var string
* @cvalue MONGOC_ENCRYPT_QUERY_TYPE_RANGEPREVIEW
*/
Expand Down
20 changes: 17 additions & 3 deletions src/MongoDB/ClientEncryption_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions tests/clientEncryption/clientEncryption-constants.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ var_dump(MongoDB\Driver\ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMIN
var_dump(MongoDB\Driver\ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_RANDOM);
var_dump(MongoDB\Driver\ClientEncryption::ALGORITHM_INDEXED);
var_dump(MongoDB\Driver\ClientEncryption::ALGORITHM_UNINDEXED);
var_dump(MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE);
var_dump(MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE_PREVIEW);
var_dump(MongoDB\Driver\ClientEncryption::QUERY_TYPE_EQUALITY);
var_dump(MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE);
var_dump(MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE_PREVIEW);

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
--EXPECTF--
string(43) "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
string(36) "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
string(7) "Indexed"
string(9) "Unindexed"
string(12) "RangePreview"
string(5) "Range"
%Astring(12) "RangePreview"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP 8.3+ emits deprecation notices when referencing these constants. I'm sure that has to do with using ZEND_ACC_DEPRECATED to define the constant, but it's not clear to me why earlier versions don't report anything. I found no mention of this in the 8.3 migration guide.

In any event, I thought it easier to conditionally ignore the notices instead of split this test into two.

string(8) "equality"
string(12) "rangePreview"
string(5) "range"
%Astring(12) "rangePreview"
===DONE===
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ $keyId = $clientEncryption->createDataKey('local');

$encryptOpts = [
'keyId' => $keyId,
'algorithm' => MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE_PREVIEW,
'queryType' => MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE_PREVIEW,
'algorithm' => MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE,
'queryType' => MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE,
'contentionFactor' => 0,
'rangeOpts' => ['min' => 0, 'max' => 200, 'sparsity' => 1],
'rangeOpts' => ['min' => 0, 'max' => 200, 'sparsity' => 1, 'trimFactor' => 1],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we get language tickets for DRIVERS-2927, sparsity and trimFactor can be removed as they'll no longer be required by libmongocrypt. That's also going to necessitate a bump to libmongocrypt 1.11.0 (MONGOCRYPT-698).

];

$expr = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ $keyId = $clientEncryption->createDataKey('local');

$encryptOpts = [
'keyId' => $keyId,
'algorithm' => MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE_PREVIEW,
'queryType' => MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE_PREVIEW,
'algorithm' => MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE,
'queryType' => MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE,
'contentionFactor' => 0,
'rangeOpts' => ['min' => 0, 'max' => 200, 'sparsity' => 1],
'rangeOpts' => ['min' => 0, 'max' => 200, 'sparsity' => 1, 'trimFactor' => 1],
];

echo throws(function() use ($clientEncryption, $encryptOpts) {
Expand Down