SharedSecretHandle.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
  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. /*!
  15. * @file SharedSecretHandle.h
  16. */
  17. #ifndef _FASTDDS_RTPS_SECURITY_COMMON_SHAREDSECRETHANDLE_H_
  18. #define _FASTDDS_RTPS_SECURITY_COMMON_SHAREDSECRETHANDLE_H_
  19. #include <fastdds/rtps/security/common/Handle.h>
  20. #include <vector>
  21. namespace eprosima {
  22. namespace fastrtps {
  23. namespace rtps {
  24. namespace security {
  25. class SharedSecret
  26. {
  27. public:
  28. class BinaryData
  29. {
  30. public:
  31. BinaryData() {}
  32. BinaryData(const BinaryData& data) :
  33. name_(data.name_),
  34. value_(data.value_) {}
  35. BinaryData(BinaryData&& data) :
  36. name_(std::move(data.name_)),
  37. value_(std::move(data.value_)) {}
  38. BinaryData(const std::string& name,
  39. const std::vector<uint8_t>& value) :
  40. name_(name), value_(value) {}
  41. BinaryData(std::string&& name,
  42. std::vector<uint8_t>&& value) :
  43. name_(std::move(name)), value_(std::move(value)) {}
  44. BinaryData& operator=(const BinaryData& data)
  45. {
  46. name_ = data.name_;
  47. value_ = data.value_;
  48. return *this;
  49. }
  50. BinaryData& operator=(BinaryData&& data)
  51. {
  52. name_ = std::move(data.name_);
  53. value_ = std::move(data.value_);
  54. return *this;
  55. }
  56. void name(const std::string& name)
  57. {
  58. name_ = name;
  59. }
  60. void name(std::string&& name)
  61. {
  62. name_ = std::move(name);
  63. }
  64. const std::string& name() const
  65. {
  66. return name_;
  67. }
  68. std::string& name()
  69. {
  70. return name_;
  71. }
  72. void value(const std::vector<uint8_t>& value)
  73. {
  74. value_ = value;
  75. }
  76. void value(std::vector<uint8_t>&& value)
  77. {
  78. value_ = std::move(value);
  79. }
  80. const std::vector<uint8_t>& value() const
  81. {
  82. return value_;
  83. }
  84. std::vector<uint8_t>& value()
  85. {
  86. return value_;
  87. }
  88. private:
  89. std::string name_;
  90. std::vector<uint8_t> value_;
  91. };
  92. static const char* const class_id_;
  93. std::vector<BinaryData> data_;
  94. };
  95. typedef HandleImpl<SharedSecret> SharedSecretHandle;
  96. class SharedSecretHelper
  97. {
  98. public:
  99. static std::vector<uint8_t>* find_data_value(SharedSecret& sharedsecret, const std::string& name);
  100. static const std::vector<uint8_t>* find_data_value(const SharedSecret& sharedsecret, const std::string& name);
  101. };
  102. } //namespace security
  103. } //namespace rtps
  104. } //namespace fastrtps
  105. } //namespace eprosima
  106. #endif // _FASTDDS_RTPS_SECURITY_COMMON_SHAREDSECRETHANDLE_H_