Botan 3.6.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:86

References BOTAN_ASSERT_NONNULL.

◆ 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)

◆ ~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

◆ 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}

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 m_handles = std::make_unique<ObjectHandles>();
109 m_public_info.reset();
110}

Referenced by _reset(), and Botan::TPM2::HashFunction::final_with_ticket().

◆ _public_info()

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

Definition at line 134 of file tpm2_object.cpp.

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

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

Referenced by attributes(), Botan::TPM2::PrivateKey::create(), Botan::TPM2::PublicKey::create(), Botan::TPM2::PrivateKey::raw_public_key_bits(), and Botan::TPM2::PublicKey::raw_public_key_bits().

◆ _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().

Referenced by Botan::TPM2::HashFunction::clear().

◆ attributes()

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

Definition at line 129 of file tpm2_object.cpp.

129 {
130 const auto attrs = _public_info(sessions).pub->publicArea.objectAttributes;
131 return ObjectAttributes::read(attrs);
132}
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:157

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

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

◆ context()

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

◆ has_persistent_handle()

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

Definition at line 112 of file tpm2_object.cpp.

112 {
113 return m_handles->persistent.has_value();
114}

Referenced by Botan::TPM2::PrivateKey::create(), Botan::TPM2::PublicKey::create(), persistent_handle(), and Botan::TPM2::PrivateKey::raw_private_key_bits().

◆ has_transient_handle()

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

Definition at line 116 of file tpm2_object.cpp.

116 {
117 return m_handles->transient != ESYS_TR_NONE;
118}

Referenced by Botan::TPM2::PrivateKey::create_transient_from_template(), and Botan::TPM2::HashFunction::final_with_ticket().

◆ operator=() [1/2]

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

◆ 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}

◆ persistent_handle()

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

Definition at line 120 of file tpm2_object.cpp.

120 {
122 return *m_handles->persistent;
123}
bool has_persistent_handle() const

References BOTAN_STATE_CHECK, and has_persistent_handle().

◆ transient_handle()

Friends And Related Symbol Documentation

◆ ObjectSetter

friend class ObjectSetter
friend

Definition at line 125 of file tpm2_object.h.


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