Skip to content

Commit 4956b57

Browse files
authored
PHPC-2401: Support QEv2 range protocol (#1583)
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).
1 parent 2944d9d commit 4956b57

6 files changed

+55
-12
lines changed

src/MongoDB/ClientEncryption.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,17 @@ static mongoc_client_encryption_encrypt_range_opts_t* phongo_clientencryption_en
850850
return opts;
851851
}
852852

853+
if (php_array_existsc(options, "trimFactor")) {
854+
int64_t trimfactor = php_array_fetchc_long(options, "trimFactor");
855+
856+
if (trimfactor < 0 || trimfactor > INT32_MAX) {
857+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected \"trimFactor\" range option to be a positive 32-bit integer, %" PRId64 " given", trimfactor);
858+
goto cleanup;
859+
}
860+
861+
mongoc_client_encryption_encrypt_range_opts_set_trim_factor(opts, (int32_t) trimfactor);
862+
}
863+
853864
if (php_array_existsc(options, "sparsity")) {
854865
int64_t sparsity = php_array_fetchc_long(options, "sparsity");
855866

src/MongoDB/ClientEncryption.stub.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ final class ClientEncryption
3434
public const ALGORITHM_UNINDEXED = UNKNOWN;
3535

3636
/**
37+
* @var string
38+
* @cvalue MONGOC_ENCRYPT_ALGORITHM_RANGE
39+
*/
40+
public const ALGORITHM_RANGE = UNKNOWN;
41+
42+
/**
43+
* @deprecated
3744
* @var string
3845
* @cvalue MONGOC_ENCRYPT_ALGORITHM_RANGEPREVIEW
3946
*/
@@ -46,6 +53,13 @@ final class ClientEncryption
4653
public const QUERY_TYPE_EQUALITY = UNKNOWN;
4754

4855
/**
56+
* @var string
57+
* @cvalue MONGOC_ENCRYPT_QUERY_TYPE_RANGE
58+
*/
59+
public const QUERY_TYPE_RANGE = UNKNOWN;
60+
61+
/**
62+
* @deprecated
4963
* @var string
5064
* @cvalue MONGOC_ENCRYPT_QUERY_TYPE_RANGEPREVIEW
5165
*/

src/MongoDB/ClientEncryption_arginfo.h

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/clientEncryption/clientEncryption-constants.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ var_dump(MongoDB\Driver\ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMIN
77
var_dump(MongoDB\Driver\ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_RANDOM);
88
var_dump(MongoDB\Driver\ClientEncryption::ALGORITHM_INDEXED);
99
var_dump(MongoDB\Driver\ClientEncryption::ALGORITHM_UNINDEXED);
10+
var_dump(MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE);
1011
var_dump(MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE_PREVIEW);
1112
var_dump(MongoDB\Driver\ClientEncryption::QUERY_TYPE_EQUALITY);
13+
var_dump(MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE);
1214
var_dump(MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE_PREVIEW);
1315

1416
?>
1517
===DONE===
1618
<?php exit(0); ?>
17-
--EXPECT--
19+
--EXPECTF--
1820
string(43) "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
1921
string(36) "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
2022
string(7) "Indexed"
2123
string(9) "Unindexed"
22-
string(12) "RangePreview"
24+
string(5) "Range"
25+
%Astring(12) "RangePreview"
2326
string(8) "equality"
24-
string(12) "rangePreview"
27+
string(5) "range"
28+
%Astring(12) "rangePreview"
2529
===DONE===

tests/clientEncryption/clientEncryption-encryptExpression-001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ $keyId = $clientEncryption->createDataKey('local');
2222

2323
$encryptOpts = [
2424
'keyId' => $keyId,
25-
'algorithm' => MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE_PREVIEW,
26-
'queryType' => MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE_PREVIEW,
25+
'algorithm' => MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE,
26+
'queryType' => MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE,
2727
'contentionFactor' => 0,
28-
'rangeOpts' => ['min' => 0, 'max' => 200, 'sparsity' => 1],
28+
'rangeOpts' => ['min' => 0, 'max' => 200, 'sparsity' => 1, 'trimFactor' => 1],
2929
];
3030

3131
$expr = [

tests/clientEncryption/clientEncryption-encryptExpression_error-002.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ $keyId = $clientEncryption->createDataKey('local');
2222

2323
$encryptOpts = [
2424
'keyId' => $keyId,
25-
'algorithm' => MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE_PREVIEW,
26-
'queryType' => MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE_PREVIEW,
25+
'algorithm' => MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE,
26+
'queryType' => MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE,
2727
'contentionFactor' => 0,
28-
'rangeOpts' => ['min' => 0, 'max' => 200, 'sparsity' => 1],
28+
'rangeOpts' => ['min' => 0, 'max' => 200, 'sparsity' => 1, 'trimFactor' => 1],
2929
];
3030

3131
echo throws(function() use ($clientEncryption, $encryptOpts) {

0 commit comments

Comments
 (0)