Skip to content

Commit

Permalink
Address comments regarding tpm2.h restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
atreiber94 committed Jun 14, 2024
1 parent 2ab6008 commit 70be246
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
23 changes: 1 addition & 22 deletions src/lib/prov/tpm2/tpm2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ std::string TPM2_Error::error_message() const {
return Tss2_RC_Decode(m_rc);
}

class TPM2_Context::Impl {
public:
struct TPM2_Context::Impl {
TSS2_TCTI_CONTEXT* m_tcti_ctx;
ESYS_CONTEXT* m_ctx;
};
Expand All @@ -47,26 +46,6 @@ TPM2_Context::TPM2_Context(const char* tcti_nameconf) : m_impl(std::make_unique<
check_tss2_rc("TPM2 Initialization", Esys_Initialize(&m_impl->m_ctx, m_impl->m_tcti_ctx, nullptr /* ABI version */));
}

TPM2_Context::TPM2_Context(TPM2_Context&& ctx) noexcept {
m_impl->m_ctx = ctx.m_impl->m_ctx;
m_impl->m_tcti_ctx = ctx.m_impl->m_tcti_ctx;

ctx.m_impl->m_ctx = nullptr;
ctx.m_impl->m_tcti_ctx = nullptr;
}

TPM2_Context& TPM2_Context::operator=(TPM2_Context&& ctx) noexcept {
if(this != &ctx) {
m_impl->m_ctx = ctx.m_impl->m_ctx;
m_impl->m_tcti_ctx = ctx.m_impl->m_tcti_ctx;

ctx.m_impl->m_ctx = nullptr;
ctx.m_impl->m_tcti_ctx = nullptr;
}

return *this;
}

void* TPM2_Context::get() {
return m_impl->m_ctx;
}
Expand Down
9 changes: 5 additions & 4 deletions src/lib/prov/tpm2/tpm2.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <botan/exceptn.h>

#include <memory>
#include <optional>

namespace Botan {
Expand Down Expand Up @@ -42,20 +43,20 @@ class BOTAN_PUBLIC_API(3, 6) TPM2_Context final {
static std::shared_ptr<TPM2_Context> create(std::optional<std::string> tcti_nameconf = {});

TPM2_Context(const TPM2_Context&) = delete;
TPM2_Context(TPM2_Context&& ctx) noexcept;
TPM2_Context(TPM2_Context&& ctx) noexcept = default;
~TPM2_Context();

TPM2_Context& operator=(const TPM2_Context&) = delete;
TPM2_Context& operator=(TPM2_Context&& ctx) noexcept;
TPM2_Context& operator=(TPM2_Context&& ctx) noexcept = default;

// Return an ESYS_CONTEXT* for use in other TPM2 functions.
/// @return an ESYS_CONTEXT* for use in other TPM2 functions.
void* get();

private:
TPM2_Context(const char* tcti_nameconf);

private:
class Impl; // PImpl to avoid TPM2-TSS includes in this header
struct Impl; // PImpl to avoid TPM2-TSS includes in this header
std::unique_ptr<Impl> m_impl;
};

Expand Down

0 comments on commit 70be246

Please sign in to comment.