Botan 2.19.1
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Botan::PKCS11::Object Class Reference

#include <p11_object.h>

Public Member Functions

ObjectHandle copy (const AttributeContainer &modified_attributes) const
 
void destroy () const
 Destroys the object. More...
 
secure_vector< uint8_t > get_attribute_value (AttributeType attribute) const
 
ObjectHandle handle () const
 
Modulemodule () const
 
 Object (const Object &)=default
 
 Object (Session &session, const ObjectProperties &obj_props)
 
 Object (Session &session, ObjectHandle handle)
 
Objectoperator= (const Object &)=delete
 
Sessionsession () const
 
void set_attribute_value (AttributeType attribute, const secure_vector< uint8_t > &value) const
 Sets the given value for the attribute (using C_SetAttributeValue) More...
 
virtual ~Object ()=default
 

Static Public Member Functions

template<typename T >
static std::vector< Tsearch (Session &session)
 Searches for all objects of the given type. More...
 
template<typename T >
static std::vector< Tsearch (Session &session, const std::string &label)
 Searches for all objects of the given type using the label (CKA_LABEL) More...
 
template<typename T >
static std::vector< Tsearch (Session &session, const std::string &label, const std::vector< uint8_t > &id)
 Searches for all objects of the given type using the label (CKA_LABEL) and id (CKA_ID) More...
 
template<typename T >
static std::vector< Tsearch (Session &session, const std::vector< Attribute > &search_template)
 Searches for all objects of the given type that match search_template More...
 
template<typename T >
static std::vector< Tsearch (Session &session, const std::vector< uint8_t > &id)
 Searches for all objects of the given type using the id (CKA_ID) More...
 

Protected Member Functions

 Object (Session &session)
 
void reset_handle (ObjectHandle handle)
 

Detailed Description

Represents a PKCS#11 object.

Definition at line 633 of file p11_object.h.

Constructor & Destructor Documentation

◆ Object() [1/4]

Botan::PKCS11::Object::Object ( Session session,
ObjectHandle  handle 
)

Creates an Object from an existing PKCS#11 object

Parameters
sessionthe session the object belongs to
handlehandle of the object

Definition at line 190 of file p11_object.cpp.

191 : m_session(session), m_handle(handle)
192 {}
ObjectHandle handle() const
Definition: p11_object.h:691
Session & session() const
Definition: p11_object.h:697

◆ Object() [2/4]

Botan::PKCS11::Object::Object ( Session session,
const ObjectProperties obj_props 
)

Creates the object

Parameters
sessionthe session in which the object should be created
obj_propsproperties of this object

Definition at line 194 of file p11_object.cpp.

195 : m_session(session), m_handle(0)
196 {
197 m_session.get().module()->C_CreateObject(m_session.get().handle(), obj_props.data(), static_cast<Ulong>(obj_props.count()), &m_handle);
198 }
CK_ULONG Ulong
Definition: p11.h:838

References Botan::PKCS11::AttributeContainer::count(), and Botan::PKCS11::AttributeContainer::data().

◆ Object() [3/4]

Botan::PKCS11::Object::Object ( const Object )
default

◆ ~Object()

virtual Botan::PKCS11::Object::~Object ( )
virtualdefault

◆ Object() [4/4]

Botan::PKCS11::Object::Object ( Session session)
inlineprotected

Definition at line 708 of file p11_object.h.

709 : m_session(session)
710 {}

Member Function Documentation

◆ copy()

ObjectHandle Botan::PKCS11::Object::copy ( const AttributeContainer modified_attributes) const

Copies the object

Parameters
modified_attributesthe attributes of the copied object

Definition at line 218 of file p11_object.cpp.

219 {
220 ObjectHandle copied_handle;
221 module()->C_CopyObject(m_session.get().handle(), m_handle,
222 modified_attributes.data(), static_cast<Ulong>(modified_attributes.count()),
223 &copied_handle);
224 return copied_handle;
225 }
bool C_CopyObject(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ObjectHandle *new_object_ptr, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:314
Module & module() const
Definition: p11_object.h:703
CK_OBJECT_HANDLE ObjectHandle
Definition: p11.h:848

References Botan::PKCS11::LowLevel::C_CopyObject(), Botan::PKCS11::AttributeContainer::count(), Botan::PKCS11::AttributeContainer::data(), and module().

◆ destroy()

void Botan::PKCS11::Object::destroy ( ) const

Destroys the object.

Definition at line 213 of file p11_object.cpp.

214 {
215 module()->C_DestroyObject(m_session.get().handle(), m_handle);
216 }
bool C_DestroyObject(SessionHandle session, ObjectHandle object, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:325

References Botan::PKCS11::LowLevel::C_DestroyObject(), and module().

◆ get_attribute_value()

secure_vector< uint8_t > Botan::PKCS11::Object::get_attribute_value ( AttributeType  attribute) const
Returns
the value of the given attribute (using C_GetAttributeValue)

Definition at line 200 of file p11_object.cpp.

201 {
202 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute, secure_vector<uint8_t>() } };
203 module()->C_GetAttributeValue(m_session.get().handle(), m_handle, attribute_map);
204 return attribute_map.at(attribute);
205 }
bool C_GetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:340

References Botan::PKCS11::LowLevel::C_GetAttributeValue(), and module().

◆ handle()

ObjectHandle Botan::PKCS11::Object::handle ( ) const
inline
Returns
the handle of this object.

Definition at line 691 of file p11_object.h.

692 {
693 return m_handle;
694 }

Referenced by search().

◆ module()

Module & Botan::PKCS11::Object::module ( ) const
inline
Returns
the module this object belongs to

Definition at line 703 of file p11_object.h.

704 {
705 return m_session.get().module();
706 }

Referenced by copy(), destroy(), get_attribute_value(), and set_attribute_value().

◆ operator=()

Object & Botan::PKCS11::Object::operator= ( const Object )
delete

◆ reset_handle()

void Botan::PKCS11::Object::reset_handle ( ObjectHandle  handle)
inlineprotected

Definition at line 712 of file p11_object.h.

713 {
714 if(m_handle != CK_INVALID_HANDLE)
715 throw Invalid_Argument("Cannot reset handle on already valid PKCS11 object");
716 m_handle = handle;
717 }
#define CK_INVALID_HANDLE
Definition: pkcs11t.h:75

References CK_INVALID_HANDLE.

◆ search() [1/5]

template<typename T >
std::vector< T > Botan::PKCS11::Object::search ( Session session)
static

Searches for all objects of the given type.

Definition at line 764 of file p11_object.h.

765 {
766 return search<T>(session, AttributeContainer(T::Class).attributes());
767 }

References session().

◆ search() [2/5]

template<typename T >
std::vector< T > Botan::PKCS11::Object::search ( Session session,
const std::string &  label 
)
static

Searches for all objects of the given type using the label (CKA_LABEL)

Definition at line 739 of file p11_object.h.

740 {
741 AttributeContainer search_template(T::Class);
742 search_template.add_string(AttributeType::Label, label);
743 return search<T>(session, search_template.attributes());
744 }

References Botan::PKCS11::AttributeContainer::add_string(), Botan::PKCS11::AttributeContainer::attributes(), Botan::PKCS11::Label, and session().

◆ search() [3/5]

template<typename T >
std::vector< T > Botan::PKCS11::Object::search ( Session session,
const std::string &  label,
const std::vector< uint8_t > &  id 
)
static

Searches for all objects of the given type using the label (CKA_LABEL) and id (CKA_ID)

Definition at line 755 of file p11_object.h.

756 {
757 AttributeContainer search_template(T::Class);
758 search_template.add_string(AttributeType::Label, label);
759 search_template.add_binary(AttributeType::Id, id);
760 return search<T>(session, search_template.attributes());
761 }

References Botan::PKCS11::AttributeContainer::add_binary(), Botan::PKCS11::AttributeContainer::add_string(), Botan::PKCS11::AttributeContainer::attributes(), Botan::PKCS11::Id, Botan::PKCS11::Label, and session().

◆ search() [4/5]

template<typename T >
std::vector< T > Botan::PKCS11::Object::search ( Session session,
const std::vector< Attribute > &  search_template 
)
static

Searches for all objects of the given type that match search_template

Definition at line 725 of file p11_object.h.

726 {
727 ObjectFinder finder(session, search_template);
728 std::vector<ObjectHandle> handles = finder.find();
729 std::vector<T> result;
730 result.reserve(handles.size());
731 for(const auto& handle : handles)
732 {
733 result.emplace_back(T(session, handle));
734 }
735 return result;
736 }
fe T
Definition: ge.cpp:37

References Botan::PKCS11::ObjectFinder::find(), handle(), session(), and T.

◆ search() [5/5]

template<typename T >
std::vector< T > Botan::PKCS11::Object::search ( Session session,
const std::vector< uint8_t > &  id 
)
static

Searches for all objects of the given type using the id (CKA_ID)

Definition at line 747 of file p11_object.h.

748 {
749 AttributeContainer search_template(T::Class);
750 search_template.add_binary(AttributeType::Id, id);
751 return search<T>(session, search_template.attributes());
752 }

References Botan::PKCS11::AttributeContainer::add_binary(), Botan::PKCS11::AttributeContainer::attributes(), Botan::PKCS11::Id, and session().

◆ session()

Session & Botan::PKCS11::Object::session ( ) const
inline
Returns
the session this objects belongs to

Definition at line 697 of file p11_object.h.

698 {
699 return m_session;
700 }

Referenced by search().

◆ set_attribute_value()

void Botan::PKCS11::Object::set_attribute_value ( AttributeType  attribute,
const secure_vector< uint8_t > &  value 
) const

Sets the given value for the attribute (using C_SetAttributeValue)

Definition at line 207 of file p11_object.cpp.

208 {
209 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute, value } };
210 module()->C_SetAttributeValue(m_session.get().handle(), m_handle, attribute_map);
211 }
bool C_SetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:350

References Botan::PKCS11::LowLevel::C_SetAttributeValue(), and module().


The documentation for this class was generated from the following files: