Skip to content

Commit 942dbd0

Browse files
marksg07mdb-ad
authored andcommitted
MONGOCRYPT-810 Extend _fle2_append_compactionTokens to append tokens … (#1024)
* MONGOCRYPT-810 Extend _fle2_append_compactionTokens to append tokens for text search
1 parent cddf2ea commit 942dbd0

14 files changed

+698
-99
lines changed

src/mongocrypt-ctx-encrypt.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,15 +695,20 @@ static moe_result must_omit_encryptionInformation(const char *command_name,
695695
// `compactStructuredEncryptionData` is a special case:
696696
// - Server 7.0 prohibits `encryptionInformation`.
697697
// - Server 8.0 requires `encryptionInformation` if "range" fields are referenced. Otherwise ignores.
698-
// Only send `encryptionInformation` if "range" fields are present to support both server versions.
699-
bool uses_range_fields = false;
698+
// - Server 8.2 requires `encryptionInformation` if any range or text-search fields are referenced. Otherwise
699+
// ignores.
700+
// Only send `encryptionInformation` if range or text-search fields are present to support all server
701+
// versions.
702+
bool has_fields_requiring_ei = false;
700703
for (const mc_EncryptedField_t *ef = efc->fields; ef != NULL; ef = ef->next) {
701-
if (ef->supported_queries & SUPPORTS_RANGE_QUERIES) {
702-
uses_range_fields = true;
704+
if (ef->supported_queries
705+
& (SUPPORTS_RANGE_QUERIES | SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_PREVIEW_QUERIES
706+
| SUPPORTS_PREFIX_PREVIEW_QUERIES)) {
707+
has_fields_requiring_ei = true;
703708
break;
704709
}
705710
}
706-
return (moe_result){.ok = true, .must_omit = !uses_range_fields};
711+
return (moe_result){.ok = true, .must_omit = !has_fields_requiring_ei};
707712
}
708713

709714
for (i = 0; i < sizeof(prohibited_commands) / sizeof(prohibited_commands[0]); i++) {
@@ -817,7 +822,9 @@ static bool _fle2_append_compactionTokens(mongocrypt_t *crypt,
817822

818823
const _mongocrypt_buffer_t *ecoct_buf = mc_ECOCToken_get(ecoct);
819824

820-
if ((ptr->supported_queries & SUPPORTS_RANGE_QUERIES)) {
825+
if (ptr->supported_queries
826+
& (SUPPORTS_RANGE_QUERIES | SUPPORTS_SUBSTRING_PREVIEW_QUERIES | SUPPORTS_SUFFIX_PREVIEW_QUERIES
827+
| SUPPORTS_PREFIX_PREVIEW_QUERIES)) {
821828
// Append the document {ecoc: <ECOCToken>, anchorPaddingToken: <AnchorPaddingTokenRoot>}
822829
esct = mc_ESCToken_new(crypto, cl1t, status);
823830
if (!esct) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "cleanupStructuredEncryptionData": "test" }
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"name": "test",
3+
"options": {
4+
"encryptedFields": {
5+
"escCollection": "esc",
6+
"ecocCollection": "ecoc",
7+
"fields": [
8+
{
9+
"keyId": {
10+
"$binary": {
11+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
12+
"subType": "04"
13+
}
14+
},
15+
"path": "encrypted",
16+
"bsonType": "string",
17+
"queries": {
18+
"queryType": "equality",
19+
"contention": 0
20+
}
21+
},
22+
{
23+
"keyId": {
24+
"$binary": {
25+
"base64": "q83vqxI0mHYSNBI0VniQEg==",
26+
"subType": "04"
27+
}
28+
},
29+
"path": "nested.encrypted",
30+
"bsonType": "string",
31+
"queries": {
32+
"queryType": "equality",
33+
"contention": 0
34+
}
35+
},
36+
{
37+
"keyId": {
38+
"$binary": {
39+
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
40+
"subType": "04"
41+
}
42+
},
43+
"path": "nested.notindexed",
44+
"bsonType": "string"
45+
},
46+
{
47+
"keyId": {
48+
"$binary": {
49+
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
50+
"subType": "04"
51+
}
52+
},
53+
"path": "textField1",
54+
"bsonType": "string",
55+
"queries": {
56+
"queryType": "substringPreview",
57+
"contention": {
58+
"$numberLong": "0"
59+
},
60+
"strMaxLength": 100,
61+
"strMinQueryLength": 5,
62+
"strMaxQueryLength": 20,
63+
"caseSensitive": false,
64+
"diacriticSensitive": true
65+
}
66+
},
67+
{
68+
"keyId": {
69+
"$binary": {
70+
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
71+
"subType": "04"
72+
}
73+
},
74+
"path": "textField2",
75+
"bsonType": "string",
76+
"queries": [{
77+
"queryType": "suffixPreview",
78+
"contention": {
79+
"$numberLong": "0"
80+
},
81+
"strMinQueryLength": 1,
82+
"strMaxQueryLength": 10,
83+
"caseSensitive": true,
84+
"diacriticSensitive": false
85+
},
86+
{
87+
"queryType": "prefixPreview",
88+
"contention": {
89+
"$numberLong": "0"
90+
},
91+
"strMinQueryLength": 5,
92+
"strMaxQueryLength": 15,
93+
"caseSensitive": true,
94+
"diacriticSensitive": false
95+
}]
96+
}
97+
]
98+
}
99+
}
100+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"db.test": {
3+
"escCollection": "esc",
4+
"ecocCollection": "ecoc",
5+
"fields": [
6+
{
7+
"keyId": {
8+
"$binary": {
9+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
10+
"subType": "04"
11+
}
12+
},
13+
"path": "encrypted",
14+
"bsonType": "string",
15+
"queries": {
16+
"queryType": "equality",
17+
"contention": 0
18+
}
19+
},
20+
{
21+
"keyId": {
22+
"$binary": {
23+
"base64": "q83vqxI0mHYSNBI0VniQEg==",
24+
"subType": "04"
25+
}
26+
},
27+
"path": "nested.encrypted",
28+
"bsonType": "string",
29+
"queries": {
30+
"queryType": "equality",
31+
"contention": 0
32+
}
33+
},
34+
{
35+
"keyId": {
36+
"$binary": {
37+
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
38+
"subType": "04"
39+
}
40+
},
41+
"path": "nested.notindexed",
42+
"bsonType": "string"
43+
},
44+
{
45+
"keyId": {
46+
"$binary": {
47+
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
48+
"subType": "04"
49+
}
50+
},
51+
"path": "textField1",
52+
"bsonType": "string",
53+
"queries": {
54+
"queryType": "substringPreview",
55+
"contention": {
56+
"$numberLong": "0"
57+
},
58+
"strMaxLength": 100,
59+
"strMinQueryLength": 5,
60+
"strMaxQueryLength": 20,
61+
"caseSensitive": false,
62+
"diacriticSensitive": true
63+
}
64+
},
65+
{
66+
"keyId": {
67+
"$binary": {
68+
"base64": "EjRWeBI0mHYSNBI0VniQEw==",
69+
"subType": "04"
70+
}
71+
},
72+
"path": "textField2",
73+
"bsonType": "string",
74+
"queries": [{
75+
"queryType": "suffixPreview",
76+
"contention": {
77+
"$numberLong": "0"
78+
},
79+
"strMinQueryLength": 1,
80+
"strMaxQueryLength": 10,
81+
"caseSensitive": true,
82+
"diacriticSensitive": false
83+
},
84+
{
85+
"queryType": "prefixPreview",
86+
"contention": {
87+
"$numberLong": "0"
88+
},
89+
"strMinQueryLength": 5,
90+
"strMaxQueryLength": 15,
91+
"caseSensitive": true,
92+
"diacriticSensitive": false
93+
}]
94+
}
95+
]
96+
}
97+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"cleanupStructuredEncryptionData": "test",
3+
"cleanupTokens": {
4+
"textField2": {
5+
"ecoc": {
6+
"$binary": {
7+
"base64": "27J6DZqcjkRzZ3lWEsxH7CsQHr4CZirrGmuPS8ZkRO0=",
8+
"subType": "00"
9+
}
10+
},
11+
"anchorPaddingToken": {
12+
"$binary": {
13+
"base64": "hjezd/cwUfInCg0WjvFlzdn9/BQa8upEyogsU5pMWMU=",
14+
"subType": "00"
15+
}
16+
}
17+
},
18+
"textField1": {
19+
"ecoc": {
20+
"$binary": {
21+
"base64": "27J6DZqcjkRzZ3lWEsxH7CsQHr4CZirrGmuPS8ZkRO0=",
22+
"subType": "00"
23+
}
24+
},
25+
"anchorPaddingToken": {
26+
"$binary": {
27+
"base64": "hjezd/cwUfInCg0WjvFlzdn9/BQa8upEyogsU5pMWMU=",
28+
"subType": "00"
29+
}
30+
}
31+
},
32+
"nested.notindexed": {
33+
"$binary": {
34+
"base64": "27J6DZqcjkRzZ3lWEsxH7CsQHr4CZirrGmuPS8ZkRO0=",
35+
"subType": "00"
36+
}
37+
},
38+
"nested.encrypted": {
39+
"$binary": {
40+
"base64": "SWO8WEoZ2r2Kx/muQKb7+COizy85nIIUFiHh4K9kcvA=",
41+
"subType": "00"
42+
}
43+
},
44+
"encrypted": {
45+
"$binary": {
46+
"base64": "noN+05JsuO1oDg59yypIGj45i+eFH6HOTXOPpeZ//Mk=",
47+
"subType": "00"
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)