member-testhelper.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*############################################################################
  2. # Copyright 2016 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_MEMBER_UNITTESTS_MEMBER_TESTHELPER_H_
  21. #define EPID_MEMBER_UNITTESTS_MEMBER_TESTHELPER_H_
  22. #include <vector>
  23. #include "gtest/gtest.h"
  24. extern "C" {
  25. #include "epid/member/api.h"
  26. }
  27. /// C++ Wrapper to manage memory for MemberCtx via RAII
  28. class MemberCtxObj {
  29. public:
  30. /// Create a MemberCtx
  31. explicit MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key,
  32. BitSupplier rnd_func, void* rnd_param);
  33. /// Create a MemberCtx given precomputation blob
  34. MemberCtxObj(GroupPubKey const& pub_key, PrivKey const& priv_key,
  35. MemberPrecomp const& precomp, BitSupplier rnd_func,
  36. void* rnd_param);
  37. // This class instances are not meant to be copied.
  38. // Explicitly delete copy constructor and assignment operator.
  39. MemberCtxObj(const MemberCtxObj&) = delete;
  40. MemberCtxObj& operator=(const MemberCtxObj&) = delete;
  41. /// Destroy the MemberCtx
  42. ~MemberCtxObj();
  43. /// get a pointer to the stored MemberCtx
  44. MemberCtx* ctx() const;
  45. /// cast operator to get the pointer to the stored MemberCtx
  46. operator MemberCtx*() const;
  47. /// const cast operator to get the pointer to the stored MemberCtx
  48. operator const MemberCtx*() const;
  49. private:
  50. /// The stored MemberCtx
  51. MemberCtx* ctx_;
  52. };
  53. /// Test fixture class for EpidMember
  54. class EpidMemberTest : public ::testing::Test {
  55. public:
  56. /// test data
  57. static const GroupPubKey kGroupPublicKey;
  58. /// test data
  59. static const PrivKey kMemberPrivateKey;
  60. /// test data
  61. static const std::vector<uint8_t> kGroupPublicKeyDataIkgf;
  62. /// test data
  63. static const std::vector<uint8_t> kMemberPrivateKeyDataIkgf;
  64. /// test data
  65. static const MemberPrecomp kMemberPrecomp;
  66. /// test data
  67. static const PreComputedSignature kPrecomputedSignatures[2];
  68. /// test data
  69. static const std::vector<uint8_t> kGrp01Member0SigTest1Sha256;
  70. /// test data
  71. static const std::vector<uint8_t> kGrp01Member0SigTest1Sha384;
  72. /// test data
  73. static const std::vector<uint8_t> kGrp01Member0SigTest1Sha512;
  74. /// test data
  75. static const std::vector<uint8_t> kTest1Msg;
  76. /// signature based revocation list with 50 entries
  77. static std::vector<uint8_t> kSigRlData;
  78. /// signature based revocation list with 5 entries
  79. static std::vector<uint8_t> kSigRl5EntryData;
  80. /// a message
  81. static const std::vector<uint8_t> kMsg0;
  82. /// a message
  83. static const std::vector<uint8_t> kMsg1;
  84. /// a basename
  85. static const std::vector<uint8_t> kBsn0;
  86. /// a basename
  87. static const std::vector<uint8_t> kBsn1;
  88. /// a group key in group X
  89. static const GroupPubKey kGrpXKey;
  90. /// a compressed private key in group X
  91. static const CompressedPrivKey kGrpXMember9CompressedKey;
  92. /// a private key in group X
  93. static const PrivKey kGrpXMember9PrivKey;
  94. /// a group key in group Y
  95. static const GroupPubKey kGrpYKey;
  96. /// a compressed private key in group Y
  97. static const CompressedPrivKey kGrpYMember9CompressedKey;
  98. /// setup called before each TEST_F starts
  99. virtual void SetUp() {}
  100. /// teardown called after each TEST_F finishes
  101. virtual void TearDown() {}
  102. };
  103. #endif // EPID_MEMBER_UNITTESTS_MEMBER_TESTHELPER_H_