Botan 3.13.0
Crypto and TLS for C&
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.
secure_vector< uint8_t > get_attribute_value (AttributeType attribute) const
ObjectHandle handle () const
Modulemodule () const
 Object (const Object &)=default
 Object (Object &&)=default
 Object (Session &session, const ObjectProperties &obj_props)
 Object (Session &session, ObjectHandle handle)
Objectoperator= (const Object &)=delete
Objectoperator= (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).
virtual ~Object ()=default

Static Public Member Functions

template<typename T>
static std::vector< T > search (Session &session)
 Searches for all objects of the given type.
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.
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).
template<typename T>
static std::vector< T > search (Session &session, std::string_view label)
 Searches for all objects of the given type using the label (CKA_LABEL).
template<typename T>
static std::vector< T > search (Session &session, std::string_view label, const std::vector< uint8_t > &id)
 Searches for all objects of the given type using the label (CKA_LABEL) and id (CKA_ID).

Protected Member Functions

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

Detailed Description

Represents a PKCS#11 object.

Definition at line 481 of file p11_object.h.

Constructor & Destructor Documentation

◆ Object() [1/5]

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

153: m_session(session), m_handle(handle) {}
ObjectHandle handle() const
Definition p11_object.h:541
Session & session() const
Definition p11_object.h:544

References handle(), and session().

Referenced by Object(), Object(), operator=(), and operator=().

◆ Object() [2/5]

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

155 : m_session(session), m_handle(0) {
156 m_session.get().module()->C_CreateObject(
157 m_session.get().handle(), obj_props.data(), checked_ulong_cast(obj_props.count()), &m_handle);
158}
Ulong checked_ulong_cast(size_t v)
Definition p11.h:1228

References C_CreateObject(), Botan::PKCS11::checked_ulong_cast(), Botan::PKCS11::AttributeContainer::count(), Botan::PKCS11::AttributeContainer::data(), module(), and session().

◆ Object() [3/5]

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

References Object().

◆ Object() [4/5]

Botan::PKCS11::Object::Object ( Object && )
default

References Object().

◆ ~Object()

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

◆ Object() [5/5]

Botan::PKCS11::Object::Object ( Session & session)
inlineexplicitprotected

Definition at line 550 of file p11_object.h.

550: m_session(session) {}

References session().

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

175 {
176 ObjectHandle copied_handle = {};
177 module()->C_CopyObject(m_session.get().handle(),
178 m_handle,
179 modified_attributes.data(),
180 checked_ulong_cast(modified_attributes.count()),
181 &copied_handle);
182 return copied_handle;
183}
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:337
Module & module() const
Definition p11_object.h:547
CK_OBJECT_HANDLE ObjectHandle
Definition p11.h:1214

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

Referenced by ~Object().

◆ destroy()

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

Destroys the object.

Definition at line 171 of file p11_object.cpp.

171 {
172 module()->C_DestroyObject(m_session.get().handle(), m_handle);
173}
bool C_DestroyObject(SessionHandle session, ObjectHandle object, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:348

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

Referenced by ~Object().

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

160 {
161 std::map<AttributeType, secure_vector<uint8_t>> attribute_map = {{attribute, secure_vector<uint8_t>()}};
162 module()->C_GetAttributeValue(m_session.get().handle(), m_handle, attribute_map);
163 return attribute_map.at(attribute);
164}
bool C_GetAttributeValue(SessionHandle session, ObjectHandle object, Attribute *attribute_template_ptr, Ulong count, ReturnValue *return_value=ThrowException) const
Definition p11.cpp:359
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128

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

Referenced by ~Object().

◆ handle()

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

Definition at line 541 of file p11_object.h.

541{ return m_handle; }

Referenced by Object(), reset_handle(), and search().

◆ module()

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

Definition at line 547 of file p11_object.h.

547{ return m_session.get().module(); }

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

◆ operator=() [1/2]

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

References Object().

◆ operator=() [2/2]

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

References Object().

◆ reset_handle()

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

Definition at line 552 of file p11_object.h.

552 {
553 if(m_handle != CK_INVALID_HANDLE) {
554 throw Invalid_Argument("Cannot reset handle on already valid PKCS11 object");
555 }
556 m_handle = handle;
557 }
#define CK_INVALID_HANDLE
Definition pkcs11.h:35

References CK_INVALID_HANDLE, and 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 606 of file p11_object.h.

606 {
607 return search<T>(session, AttributeContainer(T::Class).attributes());
608}
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.
Definition p11_object.h:565

References search(), and session().

◆ search() [2/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 565 of file p11_object.h.

565 {
566 const ObjectFinder finder(session, search_template);
567 std::vector<T> result;
568 // C_FindObjects returns up to the requested batch; the search is exhausted
569 // when a call yields zero handles. Loop until then so callers see all matches.
570 for(;;) {
571 const std::vector<ObjectHandle> handles = finder.find();
572 if(handles.empty()) {
573 break;
574 }
575 result.reserve(result.size() + handles.size());
576 for(const auto& handle : handles) {
577 result.emplace_back(T(session, handle));
578 }
579 }
580 return result;
581}

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

Referenced by search(), search(), search(), search(), and ~Object().

◆ search() [3/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 591 of file p11_object.h.

591 {
592 AttributeContainer search_template(T::Class);
593 search_template.add_binary(AttributeType::Id, id);
594 return search<T>(session, search_template.attributes());
595}

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

◆ search() [4/5]

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

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

Definition at line 584 of file p11_object.h.

584 {
585 AttributeContainer search_template(T::Class);
586 search_template.add_string(AttributeType::Label, label);
587 return search<T>(session, search_template.attributes());
588}

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

◆ search() [5/5]

template<typename T>
std::vector< T > Botan::PKCS11::Object::search ( Session & session,
std::string_view 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 598 of file p11_object.h.

598 {
599 AttributeContainer search_template(T::Class);
600 search_template.add_string(AttributeType::Label, label);
601 search_template.add_binary(AttributeType::Id, id);
602 return search<T>(session, search_template.attributes());
603}

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

◆ session()

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

Definition at line 544 of file p11_object.h.

544{ return m_session; }

Referenced by Object(), Object(), Object(), search(), search(), search(), search(), search(), and ~Object().

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

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

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

Referenced by ~Object().


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