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);
32 add_attribute(attribute, reinterpret_cast<const uint8_t*>(m_strings.back().data()), static_cast<Ulong>(value.size()));
38 add_attribute(attribute, reinterpret_cast< const uint8_t* >(m_vectors.back().data()), static_cast<Ulong>(length));
43 m_numerics.push_back(value ?
True :
False);
44 add_attribute(attribute, reinterpret_cast< uint8_t* >(&m_numerics.back()),
sizeof(
Bbool));
51 for(
auto& existing_attribute : m_attributes)
53 if(existing_attribute.type == static_cast< CK_ATTRIBUTE_TYPE >(attribute))
56 m_strings.erase(std::remove_if(m_strings.begin(), m_strings.end(), [ &existing_attribute ](
const std::string&
data)
58 return data.data() == existing_attribute.
pValue;
61 m_numerics.erase(std::remove_if(m_numerics.begin(), m_numerics.end(), [ &existing_attribute ](
const uint64_t&
data)
64 }), m_numerics.end());
66 m_vectors.erase(std::remove_if(m_vectors.begin(),
69 return data.data() == existing_attribute.
pValue;
72 existing_attribute.pValue =
const_cast< uint8_t*
>(value);
73 existing_attribute.ulValueLen = size;
88 : m_session(session), m_search_terminated(false)
91 const_cast< Attribute*
>(search_template.data()),
92 static_cast<Ulong>(search_template.size()));
99 if(m_search_terminated ==
false)
112 std::vector<ObjectHandle> result(max_count);
113 Ulong objectCount = 0;
115 if(objectCount < max_count)
117 result.resize(objectCount);
125 m_search_terminated =
true;
191 : m_session(session), m_handle(handle)
195 : m_session(session), m_handle(0)
197 m_session.get().module()->C_CreateObject(m_session.get().handle(), obj_props.
data(),
static_cast<Ulong>(obj_props.
count()), &m_handle);
202 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute,
secure_vector<uint8_t>() } };
204 return attribute_map.at(attribute);
209 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute, value } };
222 modified_attributes.
data(),
static_cast<Ulong>(modified_attributes.
count()),
224 return copied_handle;
Common attributes of all objects.
~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.
bool C_FindObjectsFinal(SessionHandle session, ReturnValue *return_value=ThrowException) const
ObjectFinder(Session &session, const std::vector< Attribute > &search_template)
AttributeContainer()=default
CK_ULONG CK_ATTRIBUTE_TYPE
Object(Session &session, ObjectHandle handle)
void add_binary(AttributeType attribute, const uint8_t *value, size_t length)
DomainParameterProperties(KeyType key_type)
std::vector< T, secure_allocator< T >> secure_vector
SecretKeyProperties(KeyType key_type)
void add_class(ObjectClass object_class)
void destroy() const
Destroys the object.
StorageObjectProperties(ObjectClass object_class)
void add_bool(AttributeType attribute, bool value)
CertificateProperties(CertificateType cert_type)
secure_vector< uint8_t > get_attribute_value(AttributeType attribute) const
bool C_FindObjectsInit(SessionHandle session, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
void set_attribute_value(AttributeType attribute, const secure_vector< uint8_t > &value) const
Sets the given value for the attribute (using C_SetAttributeValue)
CK_OBJECT_HANDLE ObjectHandle
bool C_FindObjects(SessionHandle session, ObjectHandle *object_ptr, Ulong max_object_count, Ulong *object_count_ptr, ReturnValue *return_value=ThrowException) const
Common attributes of all storage objects.
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
PublicKeyProperties(KeyType key_type)
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 ...
PrivateKeyProperties(KeyType key_type)
bool C_SetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
ObjectProperties(ObjectClass object_class)
void add_numeric(AttributeType attribute, T value)
Common attributes of all key objects.
Helper class to build the Attribute / CK_ATTRIBUTE structures.
KeyProperties(ObjectClass object_class, KeyType key_type)
bool C_CopyObject(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *new_object_ptr, ReturnValue *return_value=ThrowException) const
void add_string(AttributeType attribute, const std::string &value)
std::vector< ObjectHandle > find(std::uint32_t max_count=100) const
Represents a PKCS#11 session.
ObjectHandle copy(const AttributeContainer &modified_attributes) const