Botan 2.19.5 Crypto and TLS for C&

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:

## 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<typename T >
void | add_numeric (AttributeType attribute, T value)
void | add_string (AttributeType attribute, const std::string &value)
| AttributeContainer ()=default
| AttributeContainer (AttributeContainer &&other)=default
| AttributeContainer (const AttributeContainer &other)=delete
| AttributeContainer (ObjectClass object_class)
const std::vector< Attribute > & | attributes () const
size_t | count () const
Attribute * | data () const
AttributeContainer & | operator= (AttributeContainer &&other)=default
AttributeContainer & | operator= (const AttributeContainer &other)=delete
virtual | ~AttributeContainer ()

## 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_class | the class type of this container

Definition at line 16 of file p11_object.cpp.

17 {
18 add_class(object_class);
19 }
Botan::PKCS11::AttributeContainer::add_class
void add_class(ObjectClass object_class)
Definition: p11_object.cpp:21

References add_class().

## ◆ ~AttributeContainer()

virtual Botan::PKCS11::AttributeContainer::~AttributeContainer | ( |  | ) |
| inline virtual

Definition at line 36 of file p11_object.h.

36{}

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

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

References data(), and CK_ATTRIBUTE::pValue.

Referenced by add_binary(), add_bool(), add_class(), 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

  attribute | attribute type
  binary | binary attribute value to add

Definition at line 90 of file p11_object.h.

91 {
92 add_binary(attribute, binary.data(), binary.size());
93 }
Botan::PKCS11::AttributeContainer::add_binary
void add_binary(AttributeType attribute, const uint8_t *value, size_t length)
Definition: p11_object.cpp:37

## ◆ 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

  attribute | attribute type
  value | binary attribute value to add
  length | size of the binary attribute value in bytes

Definition at line 37 of file p11_object.cpp.

38 {
39 m_vectors.push_back(secure_vector<uint8_t>(value, value + length));
40 add_attribute(attribute,
41 reinterpret_cast<const uint8_t*>(m_vectors.back().data()),
42 static_cast<uint32_t>(length));
43 }
Botan::PKCS11::AttributeContainer::add_attribute
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:53

References add_attribute().

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

## ◆ add_bool()

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

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

Parameters

  attribute | attribute type
  value | boolean value to add

Definition at line 45 of file p11_object.cpp.

46 {
47 m_numerics.push_back(value ? True : False);
48 add_attribute(attribute,
49 reinterpret_cast<uint8_t*>(&m_numerics.back()),
50 sizeof(Bbool));
51 }
Botan::PKCS11::Bbool
CK_BBOOL Bbool
Definition: p11.h:836
Botan::PKCS11::True
const Bbool True
Definition: p11.h:857
Botan::PKCS11::False
const Bbool False
Definition: p11.h:858

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

## ◆ add_class()

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

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

Parameters

  object_class | class attribute to add

Definition at line 21 of file p11_object.cpp.

22 {
23 m_numerics.emplace_back(static_cast< uint64_t >(object_class));
24 add_attribute(AttributeType::Class,
25 reinterpret_cast< uint8_t* >(&m_numerics.back()),
26 static_cast<uint32_t>(sizeof(ObjectClass)));
27 }
Botan::PKCS11::AttributeType::Class
@ Class
Botan::PKCS11::ObjectClass
ObjectClass
Definition: p11.h:681

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

Referenced by AttributeContainer().

## ◆ 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

  attribute | attribute type
  value | numeric value to add

Definition at line 108 of file p11_object.h.

109 {
110 static_assert(std::is_integral<T>::value, "Numeric value required.");
111 m_numerics.push_back(static_cast< uint64_t >(value));
112 add_attribute(attribute, reinterpret_cast< uint8_t* >(&m_numerics.back()), sizeof(T));
113 }
T
fe T
Definition: ge.cpp:37

References T.

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

## ◆ 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

  attribute | attribute type
  value | string value to add

Definition at line 29 of file p11_object.cpp.

30 {
31 m_strings.push_back(value);
32 add_attribute(attribute,
33 reinterpret_cast<const uint8_t*>(m_strings.back().data()),
34 static_cast<uint32_t>(value.size()));
35 }

References add_attribute().

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

## ◆ attributes()

const std::vector< Attribute > & Botan::PKCS11::AttributeContainer::attributes | ( |  | ) | const
| inline

Returns
  the attributes this container contains

Definition at line 46 of file p11_object.h.

47 {
48 return m_attributes;
49 }

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

## ◆ count()

size_t Botan::PKCS11::AttributeContainer::count | ( |  | ) | const
| inline

Returns
  the number of attributes in this container

Definition at line 58 of file p11_object.h.

59 {
60 return m_attributes.size();
61 }

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 52 of file p11_object.h.

53 {
54 return const_cast< Attribute* >(m_attributes.data());
55 }

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

## ◆ 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:

- src/lib/prov/pkcs11/p11_object.h
- src/lib/prov/pkcs11/p11_object.cpp