client_encryption.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 <string>
  16. #include <bsoncxx/document/view_or_value.hpp>
  17. #include <bsoncxx/stdx/optional.hpp>
  18. #include <mongocxx/stdx.hpp>
  19. #include <mongocxx/config/prelude.hpp>
  20. namespace mongocxx {
  21. MONGOCXX_INLINE_NAMESPACE_BEGIN
  22. class client;
  23. class client_encryption;
  24. namespace options {
  25. ///
  26. /// Class representing options for the object managing explicit client-side encryption.
  27. ///
  28. class MONGOCXX_API client_encryption {
  29. public:
  30. ///
  31. /// When the key vault collection is on a separate MongoDB cluster,
  32. /// sets the optional client to use to route data key queries to
  33. /// that cluster.
  34. ///
  35. /// @param
  36. /// A client to use for routing queries to the key vault collection.
  37. ///
  38. /// @return
  39. /// A reference to this object to facilitate method chaining.
  40. ///
  41. /// @see https://docs.mongodb.com/manual/core/security-client-side-encryption/
  42. ///
  43. client_encryption& key_vault_client(mongocxx::client* client);
  44. ///
  45. /// Gets the key vault client.
  46. ///
  47. /// @return
  48. /// An optional pointer to the key vault client.
  49. ///
  50. const stdx::optional<client*>& key_vault_client() const;
  51. ///
  52. /// Sets the namespace to use to access the key vault collection, which
  53. /// contains all data keys used for encryption and decryption. This
  54. /// option must be set:
  55. ///
  56. /// client_encryption.key_vault_namespace({ "db", "coll" });
  57. ///
  58. /// @param ns
  59. /// A std::pair of strings representing the db and collection to use
  60. /// to access the key vault.
  61. ///
  62. /// @return
  63. /// A reference to this object to facilitate method chaining.
  64. ///
  65. /// @see https://docs.mongodb.com/manual/core/security-client-side-encryption/
  66. ///
  67. using ns_pair = std::pair<std::string, std::string>;
  68. client_encryption& key_vault_namespace(ns_pair ns);
  69. ///
  70. /// Gets the key vault namespace.
  71. ///
  72. /// @return
  73. /// An optional pair of strings representing the namespace of the
  74. /// key vault collection.
  75. ///
  76. const stdx::optional<ns_pair>& key_vault_namespace() const;
  77. ///
  78. /// Sets the KMS providers to use for client side encryption.
  79. ///
  80. /// Multiple KMS providers may be specified. Two KMS providers are
  81. /// supported: "aws" and "local". The kmsProviders map values differ
  82. /// by provider:
  83. ///
  84. /// aws: {
  85. /// accessKeyId: String,
  86. /// secretAccessKey: String
  87. /// }
  88. ///
  89. /// local: {
  90. /// key: byte[96] // The master key used to encrypt/decrypt data keys.
  91. /// }
  92. ///
  93. /// @param kms_providers
  94. /// A document containing the KMS providers.
  95. ///
  96. /// @return
  97. /// A reference to this object to facilitate method chaining.
  98. ///
  99. /// @see https://docs.mongodb.com/manual/core/security-client-side-encryption/
  100. ///
  101. client_encryption& kms_providers(bsoncxx::document::view_or_value kms_providers);
  102. ///
  103. /// Gets the KMS providers.
  104. ///
  105. /// @return
  106. /// An optional document containing the KMS providers.
  107. ///
  108. const stdx::optional<bsoncxx::document::view_or_value>& kms_providers() const;
  109. private:
  110. friend class mongocxx::client_encryption;
  111. MONGOCXX_PRIVATE void* convert() const;
  112. stdx::optional<mongocxx::client*> _key_vault_client;
  113. stdx::optional<ns_pair> _key_vault_namespace;
  114. stdx::optional<bsoncxx::document::view_or_value> _kms_providers;
  115. };
  116. } // namespace options
  117. MONGOCXX_INLINE_NAMESPACE_END
  118. } // namespace mongocxx
  119. #include <mongocxx/config/postlude.hpp>