9#include <botan/p11_object.h>
19 m_numerics.emplace_back(
static_cast<uint64_t
>(object_class));
25 m_strings.push_back(std::string(value));
27 attribute,
reinterpret_cast<const uint8_t*
>(m_strings.back().data()),
static_cast<Ulong>(value.size()));
32 add_attribute(attribute,
reinterpret_cast<const uint8_t*
>(m_vectors.back().data()),
static_cast<Ulong>(length));
36 m_numerics.push_back(value ?
True :
False);
37 add_attribute(attribute,
reinterpret_cast<uint8_t*
>(&m_numerics.back()),
sizeof(
Bbool));
43 for(
auto& existing_attribute : m_attributes) {
47 [&existing_attribute](std::string_view
data) {
return data.data() == existing_attribute.
pValue; });
50 [&existing_attribute](
const uint64_t&
data) {
return &
data == existing_attribute.
pValue; });
53 return data.data() == existing_attribute.
pValue;
56 existing_attribute.pValue =
const_cast<uint8_t*
>(value);
57 existing_attribute.ulValueLen = size;
71 m_session(session), m_search_terminated(false) {
73 const_cast<Attribute*
>(search_template.data()),
74 static_cast<Ulong>(search_template.size()));
79 if(m_search_terminated ==
false) {
88 std::vector<ObjectHandle> result(max_count);
89 Ulong objectCount = 0;
91 if(objectCount < max_count) {
92 result.resize(objectCount);
99 m_search_terminated =
true;
153 m_session.get().
module()->C_CreateObject(
154 m_session.get().handle(), obj_props.
data(),
static_cast<Ulong>(obj_props.
count()), &m_handle);
160 return attribute_map.at(attribute);
164 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = {{attribute, value}};
176 modified_attributes.
data(),
177 static_cast<Ulong>(modified_attributes.
count()),
179 return copied_handle;
Helper class to build the Attribute / CK_ATTRIBUTE structures.
void add_numeric(AttributeType attribute, T value)
AttributeContainer()=default
void add_attribute(AttributeType attribute, const uint8_t *value, Ulong size)
Add an attribute with the given value and size to the attribute collection m_attributes
void add_bool(AttributeType attribute, bool value)
void add_string(AttributeType attribute, std::string_view value)
void add_binary(AttributeType attribute, const uint8_t *value, size_t length)
void add_class(ObjectClass object_class)
CertificateProperties(CertificateType cert_type)
DomainParameterProperties(KeyType key_type)
Common attributes of all key objects.
KeyProperties(ObjectClass object_class, KeyType key_type)
bool C_SetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
bool C_FindObjectsInit(SessionHandle session, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
bool C_GetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
bool C_DestroyObject(SessionHandle session, ObjectHandle object, ReturnValue *return_value=ThrowException) const
bool C_CopyObject(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *new_object_ptr, ReturnValue *return_value=ThrowException) const
bool C_FindObjectsFinal(SessionHandle session, ReturnValue *return_value=ThrowException) const
bool C_FindObjects(SessionHandle session, ObjectHandle *object_ptr, Ulong max_object_count, Ulong *object_count_ptr, ReturnValue *return_value=ThrowException) const
std::vector< ObjectHandle > find(std::uint32_t max_count=100) const
~ObjectFinder() noexcept
Terminates a search for token and session objects (calls C_FindObjectsFinal)
void finish()
Finishes the search operation manually to allow a new ObjectFinder to exist.
ObjectFinder(Session &session, const std::vector< Attribute > &search_template)
Common attributes of all objects.
ObjectProperties(ObjectClass object_class)
secure_vector< uint8_t > get_attribute_value(AttributeType attribute) const
void destroy() const
Destroys the object.
Object(Session &session, ObjectHandle handle)
void set_attribute_value(AttributeType attribute, const secure_vector< uint8_t > &value) const
Sets the given value for the attribute (using C_SetAttributeValue)
ObjectHandle copy(const AttributeContainer &modified_attributes) const
PrivateKeyProperties(KeyType key_type)
PublicKeyProperties(KeyType key_type)
SecretKeyProperties(KeyType key_type)
Represents a PKCS#11 session.
Common attributes of all storage objects.
StorageObjectProperties(ObjectClass object_class)
CK_OBJECT_HANDLE ObjectHandle
std::vector< T, secure_allocator< T > > secure_vector
unsigned long int CK_ULONG
CK_ULONG CK_CERTIFICATE_TYPE
CK_ULONG CK_ATTRIBUTE_TYPE