member_wrapper-testhelper.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*############################################################################
  2. # Copyright 2017 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################*/
  16. /*!
  17. * \file
  18. * \brief Member C++ wrapper interface.
  19. */
  20. #ifndef EPID_COMMON_TESTHELPER_MEMBER_WRAPPER_TESTHELPER_H_
  21. #define EPID_COMMON_TESTHELPER_MEMBER_WRAPPER_TESTHELPER_H_
  22. extern "C" {
  23. #include "epid/member/api.h"
  24. }
  25. /// C++ Wrapper to manage memory for MemberCtx via RAII
  26. class MemberCtxObj {
  27. public:
  28. /// Create a MemberCtx
  29. explicit MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key,
  30. BitSupplier rnd_func, void* rnd_param);
  31. /// Create a MemberCtx
  32. explicit MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key,
  33. HashAlg hash_alg, BitSupplier rnd_func,
  34. void* rnd_param);
  35. /// Create a MemberCtx
  36. explicit MemberCtxObj(BitSupplier rnd_func, void* rnd_param);
  37. /// Create a MemberCtx
  38. explicit MemberCtxObj(MemberParams const* params);
  39. /// Create a MemberCtx
  40. explicit MemberCtxObj(GroupPubKey const& pub_key,
  41. MembershipCredential const& cred, BitSupplier rnd_func,
  42. void* rnd_param);
  43. /// Create a MemberCtx given precomputation blob
  44. MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key,
  45. MemberPrecomp const& precomp, BitSupplier rnd_func,
  46. void* rnd_param);
  47. /// Create a MemberCtx given precomputation blob
  48. MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key,
  49. HashAlg hash_alg, MemberPrecomp const& precomp,
  50. BitSupplier rnd_func, void* rnd_param);
  51. /// Create a MemberCtx given precomputation blob
  52. MemberCtxObj(GroupPubKey const& pub_key, MembershipCredential const& cred,
  53. MemberPrecomp const& precomp, BitSupplier rnd_func,
  54. void* rnd_param);
  55. /// Create a MemberCtx given precomputation blob
  56. MemberCtxObj(GroupPubKey const& pub_key, MembershipCredential const& cred,
  57. HashAlg hash_alg, BitSupplier rnd_func, void* rnd_param);
  58. // This class instances are not meant to be copied.
  59. // Explicitly delete copy constructor and assignment operator.
  60. MemberCtxObj(const MemberCtxObj&) = delete;
  61. MemberCtxObj& operator=(const MemberCtxObj&) = delete;
  62. /// Destroy the MemberCtx
  63. ~MemberCtxObj();
  64. /// get a pointer to the stored MemberCtx
  65. MemberCtx* ctx() const;
  66. /// cast operator to get the pointer to the stored MemberCtx
  67. operator MemberCtx*() const;
  68. /// const cast operator to get the pointer to the stored MemberCtx
  69. operator const MemberCtx*() const;
  70. private:
  71. /// Creates and initializes new member given parameters.
  72. MemberCtx* CreateMember(MemberParams const* params) const;
  73. /// Deletes the member created by CreateMember().
  74. void DeleteMember(MemberCtx** ctx) const;
  75. /// The stored MemberCtx
  76. MemberCtx* ctx_;
  77. };
  78. #endif // EPID_COMMON_TESTHELPER_MEMBER_WRAPPER_TESTHELPER_H_