Skip to content

Commit f8fbbf5

Browse files
authored
DOCSP-42150: CSFLE standardization (#102)
* DOCSP-42150: CSFLE standardization * edits * code * edits * edits * fix build errors * SA feedback * remove * KA feedback * link * KA feedback 2
1 parent 2539163 commit f8fbbf5

File tree

6 files changed

+182
-171
lines changed

6 files changed

+182
-171
lines changed

config/redirects

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ raw: /docs/languages/cxx -> /docs/languages/cpp
2727

2828
(v3.10-master]: ${prefix}/${version}/installation/ -> ${base}/${version}/get-started/
2929
(v3.10-master]: ${prefix}/${version}/configuration/ -> ${base}/${version}/security/
30-
(v3.10-master]: ${prefix}/${version}/client-side-encryption/ -> ${base}/${version}/security/client-side-encryption/
30+
(v3.10-master]: ${prefix}/${version}/client-side-encryption/ -> ${base}/${version}/security/in-use-encryption/
3131
(v3.10-master]: ${prefix}/${version}/tutorial/ -> ${base}/${version}/
3232
(v3.10-master]: ${prefix}/${version}/connection-pools/ -> ${base}/${version}/connect/connection-pools/
3333
(v3.10-master]: ${prefix}/${version}/working-with-bson/ -> ${base}/${version}/data-formats/working-with-bson/

source/include-link.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The examples on this page reference {+driver-short+} library targets. Examples i
4747
The availability of targets depends on the particular installation method.
4848

4949
.. _cpp-include-cmake:
50+
5051
CMake
5152
-----
5253

@@ -83,8 +84,7 @@ After installing the {+driver-short+}, you can use CMake's ``find_package`` comm
8384
To use the ``find_package`` command, create a ``CMakeLists.txt`` file in your project directory. The following example creates a ``CMakeLists.txt`` file in the ``/home/user/project1`` project directory that uses ``find_package``:
8485

8586
.. literalinclude:: /includes/cmake_with_driver_installation.txt
86-
:caption: /home/user/project1/CMakeLists.txt
87-
:start-after: -- sphinx-include-start --
87+
:caption: /home/user/project1/CMakeLists.txt
8888

8989
Then, run the following commands to build your project:
9090

@@ -140,8 +140,7 @@ Alternatively, you can use CMake's ``add_subdirectory`` command without installi
140140
To use the ``add_subdirectory`` command, create a ``CMakeLists.txt`` file in your project directory. The following example creates a ``CMakeLists.txt`` file in the ``/home/user/project2`` project directory that uses ``add_subdirectory``:
141141

142142
.. literalinclude:: /includes/cmake_without_driver_installation.txt
143-
:caption: /home/user/project2/CMakeLists.txt
144-
:start-after: -- sphinx-include-start --
143+
:caption: /home/user/project2/CMakeLists.txt
145144

146145
.. note::
147146

@@ -190,6 +189,7 @@ The output resembles the following:
190189
members
191190

192191
.. _cpp-include-pkg-config:
192+
193193
pkg-config
194194
----------
195195

source/includes/csfle.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// start-auto-encrypt
2+
auto mongocryptd_options = make_document(kvp("mongocryptdBypassSpawn", true));
3+
4+
options::auto_encryption auto_encrypt_opts{};
5+
auto_encrypt_opts.extra_options({mongocryptd_options.view()});
6+
7+
options::client client_opts;
8+
client_opts.auto_encryption_opts(std::move(auto_encrypt_opts));
9+
10+
// Create and use your client here
11+
// end-auto-encrypt
12+
13+
// start-json-schema
14+
auto data_key_id = client_encryption.create_data_key("local");
15+
auto json_schema = document{} << "properties" << open_document << "encryptedFieldName" << open_document << "encrypt"
16+
<< open_document << "keyId" << open_array << data_key_id << close_array << "bsonType"
17+
<< "string"
18+
<< "algorithm"
19+
<< "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" << close_document << close_document
20+
<< close_document << "bsonType"
21+
<< "object" << finalize;
22+
// end-json-schema
23+
24+
// start-explicit-encrypt
25+
// Configure your MongoDB client's encryption options here
26+
27+
class client_encryption client_encryption(std::move(client_encryption_opts));
28+
29+
auto data_key_id = client_encryption.create_data_key("local");
30+
options::encrypt encrypt_opts{};
31+
encrypt_opts.key_id(data_key_id.view());
32+
encrypt_opts.algorithm(options::encrypt::encryption_algorithm::k_deterministic);
33+
34+
// Explicitly encrypts a BSON value
35+
auto to_encrypt = bsoncxx::types::bson_value::make_value("secret message");
36+
auto encrypted_message = client_encryption.encrypt(to_encrypt, encrypt_opts);
37+
38+
// Explicitly decrypts a BSON value
39+
auto decrypted_message = client_encryption.decrypt(encrypted_message);
40+
41+
// Inserts the encrypted value into the database
42+
coll.insert_one(make_document(kvp("encryptedField", encrypted_message)));
43+
// end-explicit-encrypt
44+
45+
// start-auto-decrypt
46+
options::auto_encryption auto_encrypt_opts{};
47+
auto_encrypt_opts.bypass_auto_encryption(true);
48+
49+
options::client client_opts{};
50+
client_opts.auto_encryption_opts(std::move(auto_encrypt_opts));
51+
class client client_encrypted {uri{}, std::move(client_opts)};
52+
// end-auto-decrypt

source/security.txt

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Secure Your Data
2525
Authentication </security/authentication>
2626
Enterprise Authentication </security/enterprise-authentication>
2727
In-Use Encryption </security/in-use-encryption>
28-
Client-Side Encryption </security/client-side-encryption>
2928

3029
Overview
3130
--------

source/security/client-side-encryption.txt

-162
This file was deleted.

0 commit comments

Comments
 (0)