Skip to content

Commit

Permalink
PHPC-2401: Support QEv2 range protocol (#1583)
Browse files Browse the repository at this point in the history
Existing RANGE_PREVIEW constants are deprecated in favor of new RANGE constants introduced in libmongoc 1.28.0. PHP 8.3+ emits deprecation messages when accessing the RANGE_PREVIEW constants, so we ignore such output in the constants test. It wasn't worth splitting that test by PHP version.

Support trimFactor range option.

Specify default value for trimFactor range option in tests. This is temporary until sparsity and trimFactor are made optional prior to the GA release for range indexes (PHPC-2403).
  • Loading branch information
jmikola committed Jun 14, 2024
1 parent 2944d9d commit 4956b57
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 12 deletions.
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"
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],
];

$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

0 comments on commit 4956b57

Please sign in to comment.