9#include <botan/p11_object.h>
23 m_numerics.emplace_back(
static_cast< uint64_t
>(object_class));
25 reinterpret_cast< uint8_t*
>(&m_numerics.back()),
31 m_strings.push_back(value);
33 reinterpret_cast<const uint8_t*
>(m_strings.back().data()),
34 static_cast<uint32_t
>(value.size()));
41 reinterpret_cast<const uint8_t*
>(m_vectors.back().data()),
42 static_cast<uint32_t
>(length));
47 m_numerics.push_back(value ?
True :
False);
49 reinterpret_cast<uint8_t*
>(&m_numerics.back()),
57 for(
auto& existing_attribute : m_attributes)
62 m_strings.erase(std::remove_if(m_strings.begin(), m_strings.end(), [ &existing_attribute ](
const std::string&
data)
64 return data.data() == existing_attribute.pValue;
67 m_numerics.erase(std::remove_if(m_numerics.begin(), m_numerics.end(), [ &existing_attribute ](
const uint64_t&
data)
69 return &data == existing_attribute.pValue;
70 }), m_numerics.end());
72 m_vectors.erase(std::remove_if(m_vectors.begin(),
75 return data.data() == existing_attribute.pValue;
78 existing_attribute.pValue =
const_cast< uint8_t*
>(value);
79 existing_attribute.ulValueLen = size;
94 : m_session(session), m_search_terminated(false)
97 const_cast< Attribute*
>(search_template.data()),
98 static_cast<Ulong>(search_template.size()));
105 if(m_search_terminated ==
false)
118 std::vector<ObjectHandle> result(max_count);
119 Ulong objectCount = 0;
121 if(objectCount < max_count)
123 result.resize(objectCount);
131 m_search_terminated =
true;
197 : m_session(session), m_handle(handle)
201 : m_session(session), m_handle(0)
203 m_session.get().module()->C_CreateObject(m_session.get().handle(), obj_props.
data(),
static_cast<Ulong>(obj_props.
count()), &m_handle);
208 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute,
secure_vector<uint8_t>() } };
210 return attribute_map.at(attribute);
215 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute, value } };
228 modified_attributes.
data(),
static_cast<Ulong>(modified_attributes.
count()),
230 return copied_handle;
Helper class to build the Attribute / CK_ATTRIBUTE structures.
void add_string(AttributeType attribute, const std::string &value)
AttributeContainer()=default
void add_attribute(AttributeType attribute, const uint8_t *value, uint32_t size)
Add an attribute with the given value and size to the attribute collection m_attributes
void add_numeric(AttributeType attribute, T value)
void add_bool(AttributeType attribute, bool 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