Botan  2.1.0
Crypto and TLS for C++11
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | 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 (Session &session, ObjectHandle handle)
 
 Object (Session &session, const ObjectProperties &obj_props)
 
 Object (const Object &)=default
 
Objectoperator= (const Object &)=default
 
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< T > search (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< T > search (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< T > search (Session &session, const std::vector< uint8_t > &id)
 Searches for all objects of the given type using the id (CKA_ID) More...
 
template<typename T >
static std::vector< T > search (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< T > search (Session &session)
 Searches for all objects of the given type. More...
 

Protected Member Functions

 Object (Session &session)
 

Protected Attributes

ObjectHandle m_handle = CK_INVALID_HANDLE
 
const std::reference_wrapper< Sessionm_session
 

Detailed Description

Represents a PKCS#11 object.

Definition at line 641 of file p11_object.h.

Constructor & Destructor Documentation

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 188 of file p11_object.cpp.

190  {}
const std::reference_wrapper< Session > m_session
Definition: p11_object.h:720
ObjectHandle handle() const
Definition: p11_object.h:699
Session & session() const
Definition: p11_object.h:705
ObjectHandle m_handle
Definition: p11_object.h:721
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 192 of file p11_object.cpp.

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

193  : m_session(session), m_handle(0)
194  {
195  m_session.get().module()->C_CreateObject(m_session.get().handle(), obj_props.data(), obj_props.count(), &m_handle);
196  }
const std::reference_wrapper< Session > m_session
Definition: p11_object.h:720
Session & session() const
Definition: p11_object.h:705
ObjectHandle m_handle
Definition: p11_object.h:721
Botan::PKCS11::Object::Object ( const Object )
default
virtual Botan::PKCS11::Object::~Object ( )
virtualdefault
Botan::PKCS11::Object::Object ( Session session)
inlineprotected

Definition at line 716 of file p11_object.h.

717  : m_session(session)
718  {}
const std::reference_wrapper< Session > m_session
Definition: p11_object.h:720
Session & session() const
Definition: p11_object.h:705

Member Function Documentation

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

Copies the object

Parameters
modified_attributesthe attributes of the copied object

Definition at line 216 of file p11_object.cpp.

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

217  {
218  ObjectHandle copied_handle;
219  module()->C_CopyObject(m_session.get().handle(), m_handle, modified_attributes.data(), modified_attributes.count(),
220  &copied_handle);
221  return copied_handle;
222  }
const std::reference_wrapper< Session > m_session
Definition: p11_object.h:720
CK_OBJECT_HANDLE ObjectHandle
Definition: p11.h:846
Module & module() const
Definition: p11_object.h:711
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:313
ObjectHandle m_handle
Definition: p11_object.h:721
void Botan::PKCS11::Object::destroy ( ) const

Destroys the object.

Definition at line 211 of file p11_object.cpp.

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

212  {
213  module()->C_DestroyObject(m_session.get().handle(), m_handle);
214  }
const std::reference_wrapper< Session > m_session
Definition: p11_object.h:720
bool C_DestroyObject(SessionHandle session, ObjectHandle object, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:324
Module & module() const
Definition: p11_object.h:711
ObjectHandle m_handle
Definition: p11_object.h:721
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 198 of file p11_object.cpp.

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

199  {
200  std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute, secure_vector<uint8_t>() } };
201  module()->C_GetAttributeValue(m_session.get().handle(), m_handle, attribute_map);
202  return attribute_map.at(attribute);
203  }
const std::reference_wrapper< Session > m_session
Definition: p11_object.h:720
bool C_GetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:339
Module & module() const
Definition: p11_object.h:711
ObjectHandle m_handle
Definition: p11_object.h:721
ObjectHandle Botan::PKCS11::Object::handle ( ) const
inline
Returns
the handle of this object.

Definition at line 699 of file p11_object.h.

References m_handle.

Referenced by search().

700  {
701  return m_handle;
702  }
ObjectHandle m_handle
Definition: p11_object.h:721
Module& Botan::PKCS11::Object::module ( ) const
inline
Returns
the module this object belongs to

Definition at line 711 of file p11_object.h.

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

712  {
713  return m_session.get().module();
714  }
const std::reference_wrapper< Session > m_session
Definition: p11_object.h:720
Object& Botan::PKCS11::Object::operator= ( const Object )
default
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.

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

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  }
ObjectHandle handle() const
Definition: p11_object.h:699
Session & session() const
Definition: p11_object.h:705
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.

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

740  {
741  AttributeContainer search_template(T::Class);
742  search_template.add_string(AttributeType::Label, label);
743  return search<T>(session, search_template.attributes());
744  }
Session & session() const
Definition: p11_object.h:705
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.

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

748  {
749  AttributeContainer search_template(T::Class);
750  search_template.add_binary(AttributeType::Id, id);
751  return search<T>(session, search_template.attributes());
752  }
Session & session() const
Definition: p11_object.h:705
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.

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

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  }
Session & session() const
Definition: p11_object.h:705
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.

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

765  {
766  return search<T>(session, AttributeContainer(T::Class).attributes());
767  }
Session & session() const
Definition: p11_object.h:705
Session& Botan::PKCS11::Object::session ( ) const
inline
Returns
the session this objects belongs to

Definition at line 705 of file p11_object.h.

Referenced by search().

706  {
707  return m_session;
708  }
const std::reference_wrapper< Session > m_session
Definition: p11_object.h:720
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 205 of file p11_object.cpp.

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

206  {
207  std::map<AttributeType, secure_vector<uint8_t>> attribute_map = { { attribute, value } };
208  module()->C_SetAttributeValue(m_session.get().handle(), m_handle, attribute_map);
209  }
const std::reference_wrapper< Session > m_session
Definition: p11_object.h:720
bool C_SetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
Definition: p11.cpp:349
Module & module() const
Definition: p11_object.h:711
ObjectHandle m_handle
Definition: p11_object.h:721

Member Data Documentation

ObjectHandle Botan::PKCS11::Object::m_handle = CK_INVALID_HANDLE
protected

Definition at line 721 of file p11_object.h.

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

const std::reference_wrapper<Session> Botan::PKCS11::Object::m_session
protected

Definition at line 720 of file p11_object.h.

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


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