9#include <botan/p11_object.h>
21 m_numerics.emplace_back(
static_cast< uint64_t
>(object_class));
23 reinterpret_cast< uint8_t*
>(&m_numerics.back()),
29 m_strings.push_back(std::string(value));
30 add_attribute(attribute,
reinterpret_cast<const uint8_t*
>(m_strings.back().data()),
static_cast<Ulong>(value.size()));
36 add_attribute(attribute,
reinterpret_cast< const uint8_t*
>(m_vectors.back().data()),
static_cast<Ulong>(length));
41 m_numerics.push_back(value ?
True :
False);
42 add_attribute(attribute,
reinterpret_cast< uint8_t*
>(&m_numerics.back()),
sizeof(
Bbool));
45void AttributeContainer::add_attribute(
AttributeType attribute,
const uint8_t* value,
Ulong size)
49 for(
auto& existing_attribute : m_attributes)
54 m_strings.remove_if([ &existing_attribute ](std::string_view
data)
56 return data.data() == existing_attribute.
pValue;
59 m_numerics.remove_if([ &existing_attribute ](
const uint64_t&
data)
64 m_vectors.remove_if([ &existing_attribute ](
const secure_vector<uint8_t>&
data)
66 return data.data() == existing_attribute.
pValue;
69 existing_attribute.pValue =
const_cast<uint8_t*
>(value);
70 existing_attribute.ulValueLen = size;
78 m_attributes.push_back(
81 const_cast<uint8_t*
>(value),
90 : m_session(session), m_search_terminated(false)
93 const_cast< Attribute*
>(search_template.data()),
94 static_cast<Ulong>(search_template.size()));
101 if(m_search_terminated ==
false)
114 std::vector<ObjectHandle> result(max_count);
115 Ulong objectCount = 0;
117 if(objectCount < max_count)
119 result.resize(objectCount);
127 m_search_terminated =
true;
193 : m_session(session), m_handle(handle)
197 : m_session(session), m_handle(0)
199 m_session.get().module()->C_CreateObject(m_session.get().handle(), obj_props.
data(),
static_cast<Ulong>(obj_props.
count()), &m_handle);
204 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute,
secure_vector<uint8_t>() } };
206 return attribute_map.at(attribute);
211 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute, value } };
224 modified_attributes.
data(),
static_cast<Ulong>(modified_attributes.
count()),
226 return copied_handle;
Helper class to build the Attribute / CK_ATTRIBUTE structures.
AttributeContainer()=default
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