Botan  2.6.0
Crypto and TLS for C++11
Public Member Functions | Protected Member Functions | List of all members
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

void add_binary (AttributeType attribute, const uint8_t *value, size_t length)
 
template<typename TAlloc >
void add_binary (AttributeType attribute, const std::vector< uint8_t, TAlloc > &binary)
 
void add_bool (AttributeType attribute, bool value)
 
void add_class (ObjectClass object_class)
 
template<typename T >
void add_numeric (AttributeType attribute, T value)
 
void add_string (AttributeType attribute, const std::string &value)
 
 AttributeContainer ()=default
 
 AttributeContainer (ObjectClass object_class)
 
 AttributeContainer (AttributeContainer &&other)=default
 
 AttributeContainer (const AttributeContainer &other)=delete
 
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, uint32_t size)
 Add an attribute with the given value and size to the attribute collection m_attributes More...
 

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

References add_class().

18  {
19  add_class(object_class);
20  }
void add_class(ObjectClass object_class)
Definition: p11_object.cpp:22

◆ ~AttributeContainer()

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

◆ AttributeContainer() [3/4]

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

◆ AttributeContainer() [4/4]

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

Member Function Documentation

◆ add_attribute()

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

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

Definition at line 46 of file p11_object.cpp.

References data(), and CK_ATTRIBUTE::pValue.

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

47  {
48  bool exists = false;
49  // check if the attribute has been added already
50  for(auto& existing_attribute : m_attributes)
51  {
52  if(existing_attribute.type == static_cast< CK_ATTRIBUTE_TYPE >(attribute))
53  {
54  // remove old entries
55  m_strings.erase(std::remove_if(m_strings.begin(), m_strings.end(), [ &existing_attribute ](const std::string& data)
56  {
57  return data.data() == existing_attribute.pValue;
58  }), m_strings.end());
59 
60  m_numerics.erase(std::remove_if(m_numerics.begin(), m_numerics.end(), [ &existing_attribute ](const uint64_t& data)
61  {
62  return &data == existing_attribute.pValue;
63  }), m_numerics.end());
64 
65  m_vectors.erase(std::remove_if(m_vectors.begin(),
66  m_vectors.end(), [ &existing_attribute ](const secure_vector<uint8_t>& data)
67  {
68  return data.data() == existing_attribute.pValue;
69  }), m_vectors.end());
70 
71  existing_attribute.pValue = const_cast< uint8_t* >(value);
72  existing_attribute.ulValueLen = size;
73  exists = true;
74  break;
75  }
76  }
77 
78  if(!exists)
79  {
80  m_attributes.push_back(Attribute{ static_cast< CK_ATTRIBUTE_TYPE >(attribute), const_cast< uint8_t* >(value), size });
81  }
82  }
CK_ULONG CK_ATTRIBUTE_TYPE
Definition: pkcs11t.h:416
Attribute * data() const
Definition: p11_object.h:56
CK_ATTRIBUTE Attribute
Definition: p11.h:845
CK_VOID_PTR pValue
Definition: pkcs11t.h:566

◆ add_binary() [1/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 34 of file p11_object.cpp.

References add_attribute().

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

35  {
36  m_vectors.push_back(secure_vector<uint8_t>(value, value + length));
37  add_attribute(attribute, reinterpret_cast< const uint8_t* >(m_vectors.back().data()), length);
38  }
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 ...
Definition: p11_object.cpp:46

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

95  {
96  add_binary(attribute, binary.data(), binary.size());
97  }
void add_binary(AttributeType attribute, const uint8_t *value, size_t length)
Definition: p11_object.cpp:34

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

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

41  {
42  m_numerics.push_back(value ? True : False);
43  add_attribute(attribute, reinterpret_cast< uint8_t* >(&m_numerics.back()), sizeof(Bbool));
44  }
const Bbool False
Definition: p11.h:856
const Bbool True
Definition: p11.h:855
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 ...
Definition: p11_object.cpp:46
CK_BBOOL Bbool
Definition: p11.h:834

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

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

Referenced by AttributeContainer().

23  {
24  m_numerics.push_back(static_cast< uint64_t >(object_class));
25  add_attribute(AttributeType::Class, reinterpret_cast< uint8_t* >(&m_numerics.back()), sizeof(ObjectClass));
26  }
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 ...
Definition: p11_object.cpp:46

◆ add_numeric()

template<typename 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 112 of file p11_object.h.

References T.

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

113  {
114  static_assert(std::is_integral<T>::value, "Numeric value required.");
115  m_numerics.push_back(static_cast< uint64_t >(value));
116  add_attribute(attribute, reinterpret_cast< uint8_t* >(&m_numerics.back()), sizeof(T));
117  }
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 ...
Definition: p11_object.cpp:46
fe T
Definition: ge.cpp:37

◆ add_string()

void Botan::PKCS11::AttributeContainer::add_string ( AttributeType  attribute,
const std::string &  value 
)

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

Parameters
attributeattribute type
valuestring value to add

Definition at line 28 of file p11_object.cpp.

References add_attribute().

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

29  {
30  m_strings.push_back(value);
31  add_attribute(attribute, reinterpret_cast< const uint8_t* >(m_strings.back().data()), value.size());
32  }
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 ...
Definition: p11_object.cpp:46

◆ attributes()

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

Definition at line 50 of file p11_object.h.

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

51  {
52  return m_attributes;
53  }

◆ count()

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

Definition at line 62 of file p11_object.h.

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

63  {
64  return m_attributes.size();
65  }

◆ data()

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

Definition at line 56 of file p11_object.h.

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

57  {
58  return const_cast< Attribute* >(m_attributes.data());
59  }
CK_ATTRIBUTE Attribute
Definition: p11.h:845

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

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