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 /*! 18 * \file 19 * \brief Member C++ wrapper interface. 20 */ 21 #ifndef EPID_COMMON_TESTHELPER_MEMBER_WRAPPER_TESTHELPER_H_ 22 #define EPID_COMMON_TESTHELPER_MEMBER_WRAPPER_TESTHELPER_H_ 23 24 extern "C" { 25 #include "epid/member/api.h" 26 } 27 28 /// C++ Wrapper to manage memory for MemberCtx via RAII 29 class MemberCtxObj { 30 public: 31 /// Create a MemberCtx 32 explicit MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, 33 BitSupplier rnd_func, void* rnd_param); 34 /// Create a MemberCtx 35 explicit MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, 36 HashAlg hash_alg, BitSupplier rnd_func, 37 void* rnd_param); 38 /// Create a MemberCtx 39 explicit MemberCtxObj(BitSupplier rnd_func, void* rnd_param); 40 /// Create a MemberCtx 41 explicit MemberCtxObj(MemberParams const* params); 42 /// Create a MemberCtx 43 explicit MemberCtxObj(GroupPubKey const& pub_key, 44 MembershipCredential const& cred, BitSupplier rnd_func, 45 void* rnd_param); 46 /// Create a MemberCtx given precomputation blob 47 MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, 48 MemberPrecomp const& precomp, BitSupplier rnd_func, 49 void* rnd_param); 50 /// Create a MemberCtx given precomputation blob 51 MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key, 52 HashAlg hash_alg, MemberPrecomp const& precomp, 53 BitSupplier rnd_func, void* rnd_param); 54 /// Create a MemberCtx given precomputation blob 55 MemberCtxObj(GroupPubKey const& pub_key, MembershipCredential const& cred, 56 MemberPrecomp const& precomp, BitSupplier rnd_func, 57 void* rnd_param); 58 /// Create a MemberCtx given precomputation blob 59 MemberCtxObj(GroupPubKey const& pub_key, MembershipCredential const& cred, 60 HashAlg hash_alg, BitSupplier rnd_func, void* rnd_param); 61 // This class instances are not meant to be copied. 62 // Explicitly delete copy constructor and assignment operator. 63 MemberCtxObj(const MemberCtxObj&) = delete; 64 MemberCtxObj& operator=(const MemberCtxObj&) = delete; 65 66 /// Destroy the MemberCtx 67 ~MemberCtxObj(); 68 /// get a pointer to the stored MemberCtx 69 MemberCtx* ctx() const; 70 /// cast operator to get the pointer to the stored MemberCtx 71 operator MemberCtx*() const; 72 /// const cast operator to get the pointer to the stored MemberCtx 73 operator const MemberCtx*() const; 74 75 private: 76 /// Creates and initializes new member given parameters. 77 MemberCtx* CreateMember(MemberParams const* params) const; 78 /// Deletes the member created by CreateMember(). 79 void DeleteMember(MemberCtx** ctx) const; 80 /// The stored MemberCtx 81 MemberCtx* ctx_; 82 }; 83 84 #endif // EPID_COMMON_TESTHELPER_MEMBER_WRAPPER_TESTHELPER_H_ 85