data_key.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <vector>
  17. #include <bsoncxx/document/view_or_value.hpp>
  18. #include <bsoncxx/stdx/optional.hpp>
  19. #include <mongocxx/stdx.hpp>
  20. #include <mongocxx/config/prelude.hpp>
  21. namespace mongocxx {
  22. MONGOCXX_INLINE_NAMESPACE_BEGIN
  23. class client_encryption;
  24. namespace options {
  25. ///
  26. /// Class representing options for data key generation for encryption.
  27. ///
  28. class MONGOCXX_API data_key {
  29. public:
  30. ///
  31. /// Sets a KMS-specific key used to encrypt the new data key. If the
  32. /// kmsProvider is "aws" it is required and has the following fields:
  33. ///
  34. /// - region: String // Required.
  35. ///
  36. /// - key: String // Required. The Amazon Resource Name (ARN) to the
  37. /// AWS customer master key (CMK).
  38. ///
  39. /// - endpoint: String // Optional. An alternate host identifier to send
  40. /// KMS requests to. May include port number.
  41. ///
  42. /// @param master_key
  43. /// The document representing the master key.
  44. ///
  45. /// @return
  46. /// A reference to this object.
  47. ///
  48. /// @see https://docs.mongodb.com/manual/core/security-client-side-encryption-key-management/
  49. ///
  50. data_key& master_key(bsoncxx::document::view_or_value master_key);
  51. ///
  52. /// Gets the master key.
  53. ///
  54. /// @return
  55. /// An optional document containing the master key.
  56. ///
  57. const stdx::optional<bsoncxx::document::view_or_value>& master_key() const;
  58. ///
  59. /// Sets an optional list of string alternate names used to reference the key.
  60. /// If a key is created with alternate names, then encryption may refer to the
  61. /// key by the unique alternate name instead of by _id.
  62. ///
  63. /// @param key_alt_names
  64. /// The alternate names for the key.
  65. ///
  66. /// @return
  67. /// A reference to this object.
  68. ///
  69. /// @see https://docs.mongodb.com/manual/reference/method/getClientEncryption/
  70. ///
  71. data_key& key_alt_names(std::vector<std::string> key_alt_names);
  72. ///
  73. /// Gets the alternate names for the data key.
  74. ///
  75. /// @return
  76. /// The alternate names for the data key.
  77. ///
  78. const std::vector<std::string>& key_alt_names() const;
  79. private:
  80. friend class mongocxx::client_encryption;
  81. MONGOCXX_PRIVATE void* convert() const;
  82. stdx::optional<bsoncxx::document::view_or_value> _master_key;
  83. std::vector<std::string> _key_alt_names;
  84. };
  85. } // namespace options
  86. MONGOCXX_INLINE_NAMESPACE_END
  87. } // namespace mongocxx