|
| 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