Botan 3.13.0
Crypto and TLS for C&
Botan::TPM2::Object Class Reference

#include <tpm2_object.h>

Public Member Functions

void _disengage () noexcept
 Reset the object's internal state without flushing its TPM handles.
PublicInfo_public_info (const SessionBundle &sessions, std::optional< TPMI_ALG_PUBLIC > expected_type={}) const
void _reset () noexcept
 Flush the object's TPM handles and reset its internal state.
ObjectAttributes attributes (const SessionBundle &sessions) const
const std::shared_ptr< Context > & context () const
bool has_persistent_handle () const
bool has_transient_handle () const
 Object (const Object &)=delete
 Object (Object &&other) noexcept
 Object (std::shared_ptr< Context > ctx)
 Object (std::shared_ptr< Context > ctx, ESYS_TR handle)
Objectoperator= (const Object &)=delete
Objectoperator= (Object &&other) noexcept
TPM2_HANDLE persistent_handle () const
ESYS_TR transient_handle () const noexcept
virtual ~Object ()

Friends

class ObjectSetter

Detailed Description

Wraps and manages the lifetime of TPM2 object handles both for transient and persistent objects. When this object is destroyed, the handles are released accordingly.

Note that some TSS2 library functions may internally release handles passed to them. In such cases, the Object instance can be disengaged, ensuring that the handles are not released twice. This is an internal functionality and should not be used directly.

Definition at line 85 of file tpm2_object.h.

Constructor & Destructor Documentation

◆ Object() [1/4]

Botan::TPM2::Object::Object ( std::shared_ptr< Context > ctx)
explicit

Definition at line 48 of file tpm2_object.cpp.

48 : m_ctx(std::move(ctx)), m_handles(std::make_unique<ObjectHandles>()) {
50}
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:114

References BOTAN_ASSERT_NONNULL.

Referenced by Object(), Object(), Object(), operator=(), and operator=().

◆ Object() [2/4]

Botan::TPM2::Object::Object ( std::shared_ptr< Context > ctx,
ESYS_TR handle )

Create an object wrapper from a user-provided transient handle.

Use this to wrap an externally created transient object handle into a Botan::TPM2::Object instance. This is useful when the object is created by the application and not by the Botan::TPM2 library.

Note that this will take ownership of the ESYS_TR handle and will release it when the object is destroyed.

Parameters
ctxthe TPM context to use
handlethe transient handle to wrap

Definition at line 52 of file tpm2_object.cpp.

52 : Object(std::move(ctx)) {
53 m_handles->transient = handle;
54}
Object(std::shared_ptr< Context > ctx)

References Object().

◆ ~Object()

Botan::TPM2::Object::~Object ( )
virtual

Definition at line 63 of file tpm2_object.cpp.

63 {
64 if(m_handles) {
65 flush();
66 }
67}

◆ Object() [3/4]

Botan::TPM2::Object::Object ( const Object & )
delete

References Object().

◆ Object() [4/4]

Botan::TPM2::Object::Object ( Object && other)
noexcept

Definition at line 56 of file tpm2_object.cpp.

56 :
57 m_ctx(std::move(other.m_ctx)),
58 m_handles(std::move(other.m_handles)),
59 m_public_info(std::move(other.m_public_info)) {
60 other.scrub();
61}

References Object().

Member Function Documentation

◆ _disengage()

void Botan::TPM2::Object::_disengage ( )
noexcept

Reset the object's internal state without flushing its TPM handles.

Definition at line 107 of file tpm2_object.cpp.

107 {
108 if(m_handles) {
109 *m_handles = ObjectHandles();
110 }
111 m_public_info.reset();
112}

Referenced by _reset().

◆ _public_info()

PublicInfo & Botan::TPM2::Object::_public_info ( const SessionBundle & sessions,
std::optional< TPMI_ALG_PUBLIC > expected_type = {} ) const

Definition at line 136 of file tpm2_object.cpp.

136 {
137 if(!m_public_info) {
138 m_public_info = std::make_unique<PublicInfo>();
139
140 check_rc("Esys_ReadPublic",
141 Esys_ReadPublic(m_ctx->esys_context(),
142 m_handles->transient,
143 sessions[0],
144 sessions[1],
145 sessions[2],
146 out_ptr(m_public_info->pub),
147 out_ptr(m_public_info->name),
148 out_ptr(m_public_info->qualified_name)));
149 BOTAN_ASSERT_NONNULL(m_public_info->pub);
150
151 if(expected_type) {
152 BOTAN_STATE_CHECK(m_public_info->pub->publicArea.type == *expected_type);
153 }
154 }
155
156 return *m_public_info;
157}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
constexpr void check_rc(std::string_view location, TSS2_RC rc)
Definition tpm2_util.h:55
constexpr auto out_ptr(T &outptr) noexcept
Definition stl_util.h:148

References BOTAN_ASSERT_NONNULL, BOTAN_STATE_CHECK, Botan::TPM2::check_rc(), and Botan::out_ptr().

Referenced by attributes().

◆ _reset()

void Botan::TPM2::Object::_reset ( )
noexcept

Flush the object's TPM handles and reset its internal state.

Definition at line 101 of file tpm2_object.cpp.

101 {
102 flush();
103 _disengage();
104}
void _disengage() noexcept
Reset the object's internal state without flushing its TPM handles.

References _disengage().

◆ attributes()

ObjectAttributes Botan::TPM2::Object::attributes ( const SessionBundle & sessions) const

Definition at line 131 of file tpm2_object.cpp.

131 {
132 const auto attrs = _public_info(sessions).pub->publicArea.objectAttributes;
133 return ObjectAttributes::read(attrs);
134}
PublicInfo & _public_info(const SessionBundle &sessions, std::optional< TPMI_ALG_PUBLIC > expected_type={}) const
static ObjectAttributes read(TPMA_OBJECT attributes)
unique_esys_ptr< TPM2B_PUBLIC > pub
Definition tpm2_util.h:166

References _public_info(), Botan::TPM2::PublicInfo::pub, and Botan::TPM2::ObjectAttributes::read().

◆ context()

const std::shared_ptr< Context > & Botan::TPM2::Object::context ( ) const
inline

Definition at line 110 of file tpm2_object.h.

110{ return m_ctx; }

◆ has_persistent_handle()

bool Botan::TPM2::Object::has_persistent_handle ( ) const

Definition at line 114 of file tpm2_object.cpp.

114 {
115 return m_handles->persistent.has_value();
116}

Referenced by persistent_handle().

◆ has_transient_handle()

bool Botan::TPM2::Object::has_transient_handle ( ) const

Definition at line 118 of file tpm2_object.cpp.

118 {
119 return m_handles->transient != ESYS_TR_NONE;
120}

Referenced by Botan::TPM2::PrivateKey::create_transient_from_template().

◆ operator=() [1/2]

Object & Botan::TPM2::Object::operator= ( const Object & )
delete

References Object(), and operator=().

Referenced by operator=().

◆ operator=() [2/2]

Object & Botan::TPM2::Object::operator= ( Object && other)
noexcept

Definition at line 69 of file tpm2_object.cpp.

69 {
70 if(this != &other) {
71 flush();
72 m_ctx = std::move(other.m_ctx);
73 m_handles = std::move(other.m_handles);
74 m_public_info = std::move(other.m_public_info);
75 other.scrub();
76 }
77 return *this;
78}

References Object().

◆ persistent_handle()

TPM2_HANDLE Botan::TPM2::Object::persistent_handle ( ) const

Definition at line 122 of file tpm2_object.cpp.

122 {
124 return *m_handles->persistent;
125}
bool has_persistent_handle() const

References BOTAN_STATE_CHECK, and has_persistent_handle().

◆ transient_handle()

ESYS_TR Botan::TPM2::Object::transient_handle ( ) const
noexcept

◆ ObjectSetter

friend class ObjectSetter
friend

Definition at line 125 of file tpm2_object.h.

References ObjectSetter.

Referenced by ObjectSetter.


The documentation for this class was generated from the following files: