tpm2_wrapper-testhelper.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /// Tpm2Ctx wrapper class implementation.
  17. /*! \file */
  18. #include "epid/member/tpm2/unittests/tpm2_wrapper-testhelper.h"
  19. #include <cstring>
  20. #include <string>
  21. #include "epid/common-testhelper/epid2params_wrapper-testhelper.h"
  22. #include "epid/common-testhelper/epid_params-testhelper.h"
  23. #include "epid/common-testhelper/mem_params-testhelper.h"
  24. extern "C" {
  25. #include "epid/common/src/epid2params.h"
  26. #include "epid/common/src/hashsize.h"
  27. #include "epid/common/stdtypes.h"
  28. #include "epid/common/types.h"
  29. #include "epid/member/tpm2/context.h"
  30. #include "epid/member/tpm2/sign.h"
  31. }
  32. Tpm2CtxObj::Tpm2CtxObj(BitSupplier rnd_func, void* rnd_param,
  33. const FpElemStr* f, Epid2ParamsObj const& params)
  34. : ctx_(nullptr) {
  35. EpidStatus sts = kEpidNoErr;
  36. BitSupplier rnd_func_ = NULL;
  37. void* rnd_param_ = NULL;
  38. const FpElemStr* f_ = NULL;
  39. MemberParams mem_params = {0};
  40. SetMemberParams(rnd_func, rnd_param, f, &mem_params);
  41. sts = Tpm2CreateContext(&mem_params, params, &rnd_func_, &rnd_param_, &f_,
  42. &ctx_);
  43. if (kEpidNoErr != sts) {
  44. printf("%s(%d): %s\n", __FILE__, __LINE__, "test defect:");
  45. throw std::logic_error(std::string("Failed to call: ") +
  46. "Tpm2CreateContext()");
  47. }
  48. }
  49. Tpm2CtxObj::~Tpm2CtxObj() { Tpm2DeleteContext(&ctx_); }
  50. Tpm2Ctx* Tpm2CtxObj::ctx() const { return ctx_; }
  51. Tpm2CtxObj::operator Tpm2Ctx*() const { return ctx_; }
  52. Tpm2CtxObj::operator const Tpm2Ctx*() const { return ctx_; }