client_encryption.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2020 MongoDB Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <bsoncxx/types/bson_value/value.hpp>
  16. #include <bsoncxx/types/bson_value/view.hpp>
  17. #include <mongocxx/options/client_encryption.hpp>
  18. #include <mongocxx/options/data_key.hpp>
  19. #include <mongocxx/options/encrypt.hpp>
  20. #include <mongocxx/config/prelude.hpp>
  21. namespace mongocxx {
  22. MONGOCXX_INLINE_NAMESPACE_BEGIN
  23. class MONGOCXX_API client_encryption {
  24. public:
  25. ///
  26. /// Creates a client_encryption object.
  27. ///
  28. /// @param opts
  29. /// An object representing encryption options.
  30. ///
  31. /// @see https://docs.mongodb.com/ecosystem/use-cases/client-side-field-level-encryption-guide
  32. ///
  33. client_encryption(options::client_encryption opts);
  34. ///
  35. /// Destroys a client_encryption.
  36. ///
  37. ~client_encryption() noexcept;
  38. ///
  39. /// Creates a new key document and inserts into the key vault collection.
  40. ///
  41. /// @param kms_provider
  42. /// A string identifying the KMS service to use to encrypt the datakey
  43. /// (must be "aws" or "local")
  44. /// @param opts
  45. /// Optional arguments, see options::data_key.
  46. ///
  47. /// @return The id of the created document as a bson_value::value containing
  48. /// a UUID (BSON binary subtype 4).
  49. ///
  50. /// @throws mongocxx::exception if there is an error creating the key.
  51. ///
  52. /// @see
  53. /// https://docs.mongodb.com/ecosystem/use-cases/client-side-field-level-encryption-guide/#b-create-a-data-encryption-key
  54. ///
  55. bsoncxx::types::bson_value::value create_data_key(std::string kms_provider,
  56. const options::data_key& opts = {});
  57. ///
  58. /// Encrypts a BSON value with a given key and algorithm.
  59. ///
  60. /// @param value
  61. /// The BSON value to encrypt.
  62. /// @param opts
  63. /// Options must be given in order to specify an encryption algorithm
  64. /// and a key_id or key_alt_name. See options::encrypt.
  65. ///
  66. /// @return The encrypted value (BSON binary subtype 6).
  67. ///
  68. /// @throws mongocxx::exception if there is an error encrypting the value.
  69. ///
  70. /// @see
  71. /// https://docs.mongodb.com/manual/reference/method/ClientEncryption.encrypt/#ClientEncryption.encrypt
  72. ///
  73. bsoncxx::types::bson_value::value encrypt(bsoncxx::types::bson_value::view value,
  74. const options::encrypt& opts);
  75. ///
  76. /// Decrypts an encrypted value (BSON binary of subtype 6).
  77. ///
  78. /// @param
  79. /// The encrypted value.
  80. ///
  81. /// @return The original BSON value.
  82. ///
  83. /// @throws mongocxx::exception if there is an error decrypting the value.
  84. ///
  85. /// @see
  86. /// https://docs.mongodb.com/manual/reference/method/ClientEncryption.decrypt/#ClientEncryption.decrypt
  87. ///
  88. bsoncxx::types::bson_value::value decrypt(bsoncxx::types::bson_value::view value);
  89. private:
  90. class MONGOCXX_PRIVATE impl;
  91. std::unique_ptr<impl> _impl;
  92. };
  93. MONGOCXX_INLINE_NAMESPACE_END
  94. } // namespace mongocxx
  95. #include <mongocxx/config/postlude.hpp>