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(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));
49 for(
auto& existing_attribute : m_attributes)
54 m_strings.erase(std::remove_if(m_strings.begin(), m_strings.end(), [ &existing_attribute ](
const std::string&
data)
56 return data.data() == existing_attribute.pValue;
59 m_numerics.erase(std::remove_if(m_numerics.begin(), m_numerics.end(), [ &existing_attribute ](
const uint64_t&
data)
61 return &data == existing_attribute.pValue;
62 }), m_numerics.end());
64 m_vectors.erase(std::remove_if(m_vectors.begin(),
67 return data.data() == existing_attribute.pValue;
70 existing_attribute.pValue =
const_cast<uint8_t*
>(value);
71 existing_attribute.ulValueLen = size;
79 m_attributes.push_back(
82 const_cast<uint8_t*
>(value),
91 : m_session(session), m_search_terminated(false)
94 const_cast< Attribute*
>(search_template.data()),
95 static_cast<Ulong>(search_template.size()));
102 if(m_search_terminated ==
false)
115 std::vector<ObjectHandle> result(max_count);
116 Ulong objectCount = 0;
118 if(objectCount < max_count)
120 result.resize(objectCount);
128 m_search_terminated =
true;
194 : m_session(session), m_handle(handle)
198 : m_session(session), m_handle(0)
200 m_session.get().module()->C_CreateObject(m_session.get().handle(), obj_props.
data(),
static_cast<Ulong>(obj_props.
count()), &m_handle);
205 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute,
secure_vector<uint8_t>() } };
207 return attribute_map.at(attribute);
212 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute, value } };
225 modified_attributes.
data(),
static_cast<Ulong>(modified_attributes.
count()),
227 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, Ulong 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