Botan 3.14.1
Crypto and TLS for C&
Botan_FFI::botan_ffi_obj_base Struct Referenceabstract

#include <ffi_util.h>

Inheritance diagram for Botan_FFI::botan_ffi_obj_base:
Botan_FFI::botan_ffi_obj< Botan::Cipher_Mode, 0xB4A2BF9C, std::unique_ptr > Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >

Public Member Functions

bool appears_to_be_valid_ffi_handle () const
 botan_ffi_obj_base (botan_ffi_obj_base &&other)=delete
 botan_ffi_obj_base (const botan_ffi_obj_base &other)=delete
virtual bool is_shared () const =0
botan_ffi_obj_base & operator= (botan_ffi_obj_base &&other)=delete
botan_ffi_obj_base & operator= (const botan_ffi_obj_base &other)=delete
virtual size_t use_count () const =0

Protected Member Functions

constexpr botan_ffi_obj_base (uint32_t magic)
void invalidate_magic ()
uint32_t magic () const
 ~botan_ffi_obj_base ()=default

Detailed Description

Base class of all FFI object handles. This allows dealing with arbitrary handles generically, e.g. when the downstream consumer passes them as void*.

Definition at line 59 of file ffi_util.h.

Constructor & Destructor Documentation

◆ botan_ffi_obj_base() [1/3]

Botan_FFI::botan_ffi_obj_base::botan_ffi_obj_base ( uint32_t magic)
inlineexplicitconstexprprotected

Definition at line 61 of file ffi_util.h.

61: m_magic(magic), m_magic_expected(magic) {}

References magic().

Referenced by Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::botan_ffi_obj(), botan_ffi_obj_base(), botan_ffi_obj_base(), operator=(), and operator=().

◆ ~botan_ffi_obj_base()

Botan_FFI::botan_ffi_obj_base::~botan_ffi_obj_base ( )
protecteddefault

Protected destructor to ensure that this class is never destroyed via this base type.

◆ botan_ffi_obj_base() [2/3]

Botan_FFI::botan_ffi_obj_base::botan_ffi_obj_base ( const botan_ffi_obj_base & other)
delete

References botan_ffi_obj_base().

◆ botan_ffi_obj_base() [3/3]

Botan_FFI::botan_ffi_obj_base::botan_ffi_obj_base ( botan_ffi_obj_base && other)
delete

References botan_ffi_obj_base().

Member Function Documentation

◆ appears_to_be_valid_ffi_handle()

bool Botan_FFI::botan_ffi_obj_base::appears_to_be_valid_ffi_handle ( ) const
inline

Heuristic, type-agnostic check whether some casted void* pointer plausibly points to a live FFI object handle. This deliberately does not use virtual dispatch, so that the check works without relying on a potentially bogus vtable.

Note
Calling this on any pointer that isn't actually a Botan FFI object handle is undefined behavior. This is really just a best effort check to avoid dereferencing a pointer that is definitely not a valid FFI object handle.
Returns
false if the this-pointer definitely does not reference an alive FFI object handle. In contrast, returns true if it plausibly references an alive FFI object with the possibility of false-positives.

Definition at line 97 of file ffi_util.h.

97{ return m_magic != 0 && m_magic == m_magic_expected; }

◆ invalidate_magic()

void Botan_FFI::botan_ffi_obj_base::invalidate_magic ( )
inlineprotected

Definition at line 100 of file ffi_util.h.

100{ m_magic = 0; }

Referenced by Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::~botan_ffi_obj().

◆ is_shared()

virtual bool Botan_FFI::botan_ffi_obj_base::is_shared ( ) const
pure virtual
Returns
true if the underlying type is managed via a shared_ptr

Implemented in Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >, and Botan_FFI::botan_ffi_obj< Botan::Cipher_Mode, 0xB4A2BF9C, std::unique_ptr >.

Referenced by botan_is_shared().

◆ magic()

uint32_t Botan_FFI::botan_ffi_obj_base::magic ( ) const
inlineprotected

Definition at line 102 of file ffi_util.h.

102{ return m_magic; }

Referenced by botan_ffi_obj_base(), and Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >::magic_ok().

◆ operator=() [1/2]

botan_ffi_obj_base & Botan_FFI::botan_ffi_obj_base::operator= ( botan_ffi_obj_base && other)
delete

References botan_ffi_obj_base().

◆ operator=() [2/2]

botan_ffi_obj_base & Botan_FFI::botan_ffi_obj_base::operator= ( const botan_ffi_obj_base & other)
delete

References botan_ffi_obj_base().

◆ use_count()

virtual size_t Botan_FFI::botan_ffi_obj_base::use_count ( ) const
pure virtual
Returns
internal reference count of the underlying object

Implemented in Botan_FFI::botan_ffi_obj< T, MAGIC, PtrType >, and Botan_FFI::botan_ffi_obj< Botan::Cipher_Mode, 0xB4A2BF9C, std::unique_ptr >.

Referenced by botan_use_count().


The documentation for this struct was generated from the following file: