Botan 3.9.0
Crypto and TLS for C&
Botan::PKCS11::AttributeContainer Class Reference

Helper class to build the Attribute / CK_ATTRIBUTE structures. More...

#include <p11_object.h>

Inheritance diagram for Botan::PKCS11::AttributeContainer:
Botan::PKCS11::ObjectProperties Botan::PKCS11::StorageObjectProperties Botan::PKCS11::CertificateProperties Botan::PKCS11::DataObjectProperties Botan::PKCS11::DomainParameterProperties Botan::PKCS11::KeyProperties Botan::PKCS11::PrivateKeyProperties Botan::PKCS11::PublicKeyProperties Botan::PKCS11::SecretKeyProperties

Public Member Functions

template<typename TAlloc>
void add_binary (AttributeType attribute, const std::vector< uint8_t, TAlloc > &binary)
void add_binary (AttributeType attribute, const uint8_t *value, size_t length)
void add_bool (AttributeType attribute, bool value)
void add_class (ObjectClass object_class)
template<std::integral T>
void add_numeric (AttributeType attribute, T value)
void add_string (AttributeType attribute, std::string_view value)
 AttributeContainer ()=default
 AttributeContainer (AttributeContainer &&other)=default
 AttributeContainer (const AttributeContainer &other)=delete
BOTAN_FUTURE_EXPLICIT AttributeContainer (ObjectClass object_class)
const std::vector< Attribute > & attributes () const
size_t count () const
Attributedata () const
AttributeContaineroperator= (AttributeContainer &&other)=default
AttributeContaineroperator= (const AttributeContainer &other)=delete
virtual ~AttributeContainer ()=default

Protected Member Functions

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

Detailed Description

Helper class to build the Attribute / CK_ATTRIBUTE structures.

Definition at line 28 of file p11_object.h.

Constructor & Destructor Documentation

◆ AttributeContainer() [1/4]

Botan::PKCS11::AttributeContainer::AttributeContainer ( )
default

◆ AttributeContainer() [2/4]

Botan::PKCS11::AttributeContainer::AttributeContainer ( ObjectClass object_class)
Parameters
object_classthe class type of this container

Definition at line 14 of file p11_object.cpp.

14 {
15 add_class(object_class);
16}
void add_class(ObjectClass object_class)

References add_class().

◆ ~AttributeContainer()

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

◆ AttributeContainer() [3/4]

Botan::PKCS11::AttributeContainer::AttributeContainer ( AttributeContainer && other)
default

References AttributeContainer().

◆ AttributeContainer() [4/4]

Botan::PKCS11::AttributeContainer::AttributeContainer ( const AttributeContainer & other)
delete

References AttributeContainer().

Member Function Documentation

◆ add_attribute()

void Botan::PKCS11::AttributeContainer::add_attribute ( AttributeType attribute,
const uint8_t * value,
Ulong size )
protected

Add an attribute with the given value and size to the attribute collection m_attributes

Definition at line 40 of file p11_object.cpp.

40 {
41 bool exists = false;
42 // check if the attribute has been added already
43 for(auto& existing_attribute : m_attributes) {
44 if(existing_attribute.type == static_cast<CK_ATTRIBUTE_TYPE>(attribute)) {
45 // remove old entries
46 m_strings.remove_if(
47 [&existing_attribute](std::string_view data) { return data.data() == existing_attribute.pValue; });
48
49 m_numerics.remove_if(
50 [&existing_attribute](const uint64_t& data) { return &data == existing_attribute.pValue; });
51
52 m_vectors.remove_if([&existing_attribute](const secure_vector<uint8_t>& data) {
53 return data.data() == existing_attribute.pValue;
54 });
55
56 existing_attribute.pValue = const_cast<uint8_t*>(value);
57 existing_attribute.ulValueLen = size;
58 exists = true;
59 break;
60 }
61 }
62
63 if(!exists) {
64 m_attributes.push_back(Attribute{static_cast<CK_ATTRIBUTE_TYPE>(attribute), const_cast<uint8_t*>(value), size});
65 }
66}
CK_ATTRIBUTE Attribute
Definition p11.h:834
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:69
CK_ULONG CK_ATTRIBUTE_TYPE
Definition pkcs11t.h:416

References data().

Referenced by add_binary(), add_bool(), add_class(), add_numeric(), and add_string().

◆ add_binary() [1/2]

template<typename TAlloc>
void Botan::PKCS11::AttributeContainer::add_binary ( AttributeType attribute,
const std::vector< uint8_t, TAlloc > & binary )
inline

Add a binary attribute (e.g. CKA_ID / AttributeType::Id).

Parameters
attributeattribute type
binarybinary attribute value to add

Definition at line 80 of file p11_object.h.

80 {
81 add_binary(attribute, binary.data(), binary.size());
82 }
void add_binary(AttributeType attribute, const uint8_t *value, size_t length)

References add_binary().

◆ add_binary() [2/2]

void Botan::PKCS11::AttributeContainer::add_binary ( AttributeType attribute,
const uint8_t * value,
size_t length )

Add a binary attribute (e.g. CKA_ID / AttributeType::Id).

Parameters
attributeattribute type
valuebinary attribute value to add
lengthsize of the binary attribute value in bytes

Definition at line 30 of file p11_object.cpp.

30 {
31 m_vectors.push_back(secure_vector<uint8_t>(value, value + length));
32 add_attribute(attribute, reinterpret_cast<const uint8_t*>(m_vectors.back().data()), static_cast<Ulong>(length));
33}
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
CK_ULONG Ulong
Definition p11.h:825

References add_attribute().

Referenced by add_binary(), Botan::PKCS11::Object::search(), Botan::PKCS11::Object::search(), Botan::PKCS11::CertificateProperties::set_check_value(), Botan::PKCS11::SecretKeyProperties::set_check_value(), Botan::PKCS11::CertificateProperties::set_end_date(), Botan::PKCS11::KeyProperties::set_end_date(), Botan::PKCS11::KeyProperties::set_id(), Botan::PKCS11::DataObjectProperties::set_object_id(), Botan::PKCS11::CertificateProperties::set_public_key_info(), Botan::PKCS11::PrivateKeyProperties::set_public_key_info(), Botan::PKCS11::PublicKeyProperties::set_public_key_info(), Botan::PKCS11::CertificateProperties::set_start_date(), Botan::PKCS11::KeyProperties::set_start_date(), Botan::PKCS11::PrivateKeyProperties::set_subject(), Botan::PKCS11::PublicKeyProperties::set_subject(), and Botan::PKCS11::DataObjectProperties::set_value().

◆ add_bool()

void Botan::PKCS11::AttributeContainer::add_bool ( AttributeType attribute,
bool value )

Add a bool attribute (e.g. CKA_SENSITIVE / AttributeType::Sensitive).

Parameters
attributeattribute type
valueboolean value to add

Definition at line 35 of file p11_object.cpp.

35 {
36 m_numerics.push_back(value ? True : False);
37 add_attribute(attribute, reinterpret_cast<uint8_t*>(&m_numerics.back()), sizeof(Bbool));
38}
const Bbool True
Definition p11.h:845
const Bbool False
Definition p11.h:846
CK_BBOOL Bbool
Definition p11.h:823

References add_attribute(), Botan::PKCS11::False, and Botan::PKCS11::True.

Referenced by Botan::PKCS11::PrivateKeyProperties::set_always_authenticate(), Botan::PKCS11::SecretKeyProperties::set_always_authenticate(), Botan::PKCS11::StorageObjectProperties::set_copyable(), Botan::PKCS11::PrivateKeyProperties::set_decrypt(), Botan::PKCS11::SecretKeyProperties::set_decrypt(), Botan::PKCS11::KeyProperties::set_derive(), Botan::PKCS11::StorageObjectProperties::set_destroyable(), Botan::PKCS11::PublicKeyProperties::set_encrypt(), Botan::PKCS11::SecretKeyProperties::set_encrypt(), Botan::PKCS11::PrivateKeyProperties::set_extractable(), Botan::PKCS11::SecretKeyProperties::set_extractable(), Botan::PKCS11::StorageObjectProperties::set_modifiable(), Botan::PKCS11::StorageObjectProperties::set_private(), Botan::PKCS11::PrivateKeyProperties::set_sensitive(), Botan::PKCS11::SecretKeyProperties::set_sensitive(), Botan::PKCS11::PrivateKeyProperties::set_sign(), Botan::PKCS11::SecretKeyProperties::set_sign(), Botan::PKCS11::PrivateKeyProperties::set_sign_recover(), Botan::PKCS11::StorageObjectProperties::set_token(), Botan::PKCS11::CertificateProperties::set_trusted(), Botan::PKCS11::PublicKeyProperties::set_trusted(), Botan::PKCS11::SecretKeyProperties::set_trusted(), Botan::PKCS11::PrivateKeyProperties::set_unwrap(), Botan::PKCS11::SecretKeyProperties::set_unwrap(), Botan::PKCS11::PublicKeyProperties::set_verify(), Botan::PKCS11::SecretKeyProperties::set_verify(), Botan::PKCS11::PublicKeyProperties::set_verify_recover(), Botan::PKCS11::PublicKeyProperties::set_wrap(), Botan::PKCS11::SecretKeyProperties::set_wrap(), Botan::PKCS11::PrivateKeyProperties::set_wrap_with_trusted(), and Botan::PKCS11::SecretKeyProperties::set_wrap_with_trusted().

◆ add_class()

void Botan::PKCS11::AttributeContainer::add_class ( ObjectClass object_class)

Add a class attribute (CKA_CLASS / AttributeType::Class).

Parameters
object_classclass attribute to add

Definition at line 18 of file p11_object.cpp.

18 {
19 m_numerics.emplace_back(static_cast<uint64_t>(object_class));
21 AttributeType::Class, reinterpret_cast<uint8_t*>(&m_numerics.back()), static_cast<Ulong>(sizeof(ObjectClass)));
22}

References add_attribute(), and Botan::PKCS11::Class.

Referenced by AttributeContainer().

◆ add_numeric()

template<std::integral T>
void Botan::PKCS11::AttributeContainer::add_numeric ( AttributeType attribute,
T value )
inline

Add a numeric attribute (e.g. CKA_MODULUS_BITS / AttributeType::ModulusBits).

Parameters
attributeattribute type
valuenumeric value to add

Definition at line 97 of file p11_object.h.

97 {
98 m_numerics.push_back(static_cast<uint64_t>(value));
99 add_attribute(attribute, reinterpret_cast<uint8_t*>(&m_numerics.back()), sizeof(T));
100 }

References add_attribute().

Referenced by Botan::PKCS11::CertificateProperties::CertificateProperties(), Botan::PKCS11::DomainParameterProperties::DomainParameterProperties(), Botan::PKCS11::KeyProperties::KeyProperties(), and Botan::PKCS11::CertificateProperties::set_category().

◆ add_string()

void Botan::PKCS11::AttributeContainer::add_string ( AttributeType attribute,
std::string_view value )

Add a string attribute (e.g. CKA_LABEL / AttributeType::Label).

Parameters
attributeattribute type
valuestring value to add

Definition at line 24 of file p11_object.cpp.

24 {
25 m_strings.push_back(std::string(value));
27 attribute, reinterpret_cast<const uint8_t*>(m_strings.back().data()), static_cast<Ulong>(value.size()));
28}

References add_attribute().

Referenced by Botan::PKCS11::Object::search(), Botan::PKCS11::Object::search(), Botan::PKCS11::DataObjectProperties::set_application(), and Botan::PKCS11::StorageObjectProperties::set_label().

◆ attributes()

const std::vector< Attribute > & Botan::PKCS11::AttributeContainer::attributes ( ) const
inline
Returns
the attributes this container contains

Definition at line 45 of file p11_object.h.

45{ return m_attributes; }

Referenced by Botan::PKCS11::Object::search(), Botan::PKCS11::Object::search(), and Botan::PKCS11::Object::search().

◆ count()

size_t Botan::PKCS11::AttributeContainer::count ( ) const
inline
Returns
the number of attributes in this container

Definition at line 51 of file p11_object.h.

51{ return m_attributes.size(); }

Referenced by Botan::PKCS11::Object::copy(), and Botan::PKCS11::Object::Object().

◆ data()

Attribute * Botan::PKCS11::AttributeContainer::data ( ) const
inline
Returns
raw attribute data

Definition at line 48 of file p11_object.h.

48{ return const_cast<Attribute*>(m_attributes.data()); }

Referenced by add_attribute(), Botan::PKCS11::Object::copy(), and Botan::PKCS11::Object::Object().

◆ operator=() [1/2]

AttributeContainer & Botan::PKCS11::AttributeContainer::operator= ( AttributeContainer && other)
default

References AttributeContainer().

◆ operator=() [2/2]

AttributeContainer & Botan::PKCS11::AttributeContainer::operator= ( const AttributeContainer & other)
delete

References AttributeContainer().


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