Botan
3.14.1
Crypto and TLS for C&
src
lib
prov
pkcs11
p11_object_guard.h
Go to the documentation of this file.
1
/*
2
* PKCS#11 Object Guard
3
* (C) 2026 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_P11_OBJECT_GUARD_H_
9
#define BOTAN_P11_OBJECT_GUARD_H_
10
11
#include <botan/p11_types.h>
12
#include <initializer_list>
13
#include <vector>
14
15
namespace
Botan::PKCS11
{
16
17
/**
18
* Destroys newly created token objects unless released, so that a failure
19
* after creating an object (for example while reading back its attributes)
20
* does not leave an unreachable object behind on the token.
21
*/
22
class
Object_Creation_Guard
final {
23
public
:
24
Object_Creation_Guard
(
Session
& session, std::initializer_list<ObjectHandle> handles) :
25
m_session(session), m_handles(handles) {}
26
27
~Object_Creation_Guard
() noexcept {
28
for
(
const
auto
handle : m_handles) {
29
try
{
30
m_session.module()->C_DestroyObject(m_session.handle(), handle,
nullptr
);
31
}
catch
(...) {
// NOLINT(*-empty-catch)
32
}
33
}
34
}
35
36
/// Call once construction has succeeded
37
void
release
() { m_handles.clear(); }
38
39
Object_Creation_Guard
(
const
Object_Creation_Guard
&) =
delete
;
40
Object_Creation_Guard
&
operator=
(
const
Object_Creation_Guard
&) =
delete
;
41
Object_Creation_Guard
(
Object_Creation_Guard
&&) =
delete
;
42
Object_Creation_Guard
&
operator=
(
Object_Creation_Guard
&&) =
delete
;
43
44
private
:
45
Session
& m_session;
46
std::vector<ObjectHandle> m_handles;
47
};
48
49
}
// namespace Botan::PKCS11
50
51
#endif
Botan::PKCS11::Object_Creation_Guard::Object_Creation_Guard
Object_Creation_Guard(Session &session, std::initializer_list< ObjectHandle > handles)
Definition
p11_object_guard.h:24
Botan::PKCS11::Object_Creation_Guard::operator=
Object_Creation_Guard & operator=(Object_Creation_Guard &&)=delete
Botan::PKCS11::Object_Creation_Guard::release
void release()
Call once construction has succeeded.
Definition
p11_object_guard.h:37
Botan::PKCS11::Object_Creation_Guard::Object_Creation_Guard
Object_Creation_Guard(Object_Creation_Guard &&)=delete
Botan::PKCS11::Object_Creation_Guard::~Object_Creation_Guard
~Object_Creation_Guard() noexcept
Definition
p11_object_guard.h:27
Botan::PKCS11::Object_Creation_Guard::Object_Creation_Guard
Object_Creation_Guard(const Object_Creation_Guard &)=delete
Botan::PKCS11::Object_Creation_Guard::operator=
Object_Creation_Guard & operator=(const Object_Creation_Guard &)=delete
Botan::PKCS11::Session
Represents a PKCS#11 session.
Definition
p11_types.h:139
Botan::PKCS11
Definition
p11.cpp:19
Generated by
1.16.1