Skip to content

Commit a187945

Browse files
authored
MONGOCRYPT-821 text indexes for explicit encryption (#1037)
* Support explicit encryption for algorithm type: `textPreview` and query types `prefixPreview`, `suffixPreview` and `substringPreview` * Add `mongocrypt_setopt_algorithm_text`.
1 parent 56048cf commit a187945

22 files changed

+1186
-9
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ set (MONGOCRYPT_SOURCES
121121
src/mc-range-mincover.c
122122
src/mc-range-encoding.c
123123
src/mc-rangeopts.c
124+
src/mc-textopts.c
124125
src/mc-reader.c
125126
src/mc-schema-broker.c
126127
src/mc-str-encode-string-sets.c
@@ -483,6 +484,7 @@ set (TEST_MONGOCRYPT_SOURCES
483484
test/test-mc-range-edge-generation.c
484485
test/test-mc-range-mincover.c
485486
test/test-mc-rangeopts.c
487+
test/test-mc-textopts.c
486488
test/test-mc-reader.c
487489
test/test-mc-text-search-str-encode.c
488490
test/test-mc-schema-broker.c

src/mc-textopts-private.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2025-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef MC_TEXTOPTS_PRIVATE_H
18+
#define MC_TEXTOPTS_PRIVATE_H
19+
20+
#include <bson/bson.h>
21+
22+
#include "mc-optional-private.h"
23+
#include "mongocrypt-private.h"
24+
25+
typedef struct {
26+
bool set;
27+
mc_optional_int32_t strMaxLength;
28+
int32_t strMinQueryLength;
29+
int32_t strMaxQueryLength;
30+
} mc_TextOptsPerIndex_t;
31+
32+
typedef struct {
33+
mc_TextOptsPerIndex_t substring;
34+
mc_TextOptsPerIndex_t prefix;
35+
mc_TextOptsPerIndex_t suffix;
36+
37+
bool caseSensitive;
38+
bool diacriticSensitive;
39+
} mc_TextOpts_t;
40+
41+
/* mc_TextOpts_parse parses a BSON document into mc_TextOpts_t.
42+
* The document is expected to have the form:
43+
* {
44+
* "caseSensitive": bool,
45+
* . "diacriticSensitive": bool,
46+
* . "prefix": {
47+
* . "strMaxQueryLength": Int32,
48+
* . "strMinQueryLength": Int32,
49+
* . },
50+
* . "suffix": {
51+
* . "strMaxQueryLength": Int32,
52+
* . "strMinQueryLength": Int32,
53+
* . },
54+
* . "substring": {
55+
* . "strMaxLength": Int32,
56+
* . "strMaxQueryLength": Int32,
57+
* . "strMinQueryLength": Int32,
58+
* . },
59+
* }
60+
*/
61+
bool mc_TextOpts_parse(mc_TextOpts_t *txo, const bson_t *in, mongocrypt_status_t *status);
62+
63+
/*
64+
* mc_TextOpts_to_FLE2TextSearchInsertSpec creates a placeholder value to be
65+
* encrypted. It is only expected to be called when query_type is unset. The
66+
* output FLE2TextSearchInsertSpec is a BSON document of the form:
67+
* https://github.com/mongodb/mongo/blob/219e90bfad3c712c9642da29ee52229908f06bcd/src/mongo/crypto/fle_field_schema.idl#L689
68+
*
69+
* v is expect to be a BSON document of the form:
70+
* { "v": BSON value to encrypt }.
71+
*
72+
* Preconditions: out must be initialized by caller.
73+
*/
74+
bool mc_TextOpts_to_FLE2TextSearchInsertSpec(const mc_TextOpts_t *txo,
75+
const bson_t *v,
76+
bson_t *out,
77+
mongocrypt_status_t *status);
78+
79+
#endif // MC_TEXTOPTS_PRIVATE_H

0 commit comments

Comments
 (0)