9#ifndef BOTAN_P11_OBJECT_H_
10#define BOTAN_P11_OBJECT_H_
13#include <botan/p11_types.h>
14#include <botan/secmem.h>
45 inline const std::vector<Attribute>&
attributes()
const {
return m_attributes; }
51 inline size_t count()
const {
return m_attributes.size(); }
64 void add_string(
AttributeType attribute, std::string_view value);
72 void add_binary(
AttributeType attribute,
const uint8_t* value,
size_t length);
79 template <
typename TAlloc>
81 add_binary(attribute, binary.data(), binary.size());
96 template <std::
integral T>
98 m_numerics.push_back(
static_cast<uint64_t
>(value));
99 add_attribute(attribute,
reinterpret_cast<uint8_t*
>(&m_numerics.back()),
sizeof(
T));
107 std::vector<Attribute> m_attributes;
108 std::list<uint64_t> m_numerics;
109 std::list<std::string> m_strings;
110 std::list<secure_vector<uint8_t>> m_vectors;
137 std::vector<
ObjectHandle> find(std::uint32_t max_count = 100) const;
146 const std::reference_wrapper<Session> m_session;
147 bool m_search_terminated;
170 inline void set_label(std::string_view label) { add_string(AttributeType::Label, label); }
173 inline void set_token(
bool value) { add_bool(AttributeType::Token, value); }
179 inline void set_private(
bool value) { add_bool(AttributeType::Private, value); }
185 void set_copyable(
bool value) { add_bool(AttributeType::Copyable, value); }
197 inline void set_application(std::string_view value) { add_string(AttributeType::Application, value); }
201 add_binary(AttributeType::ObjectId, object_id);
215 inline void set_trusted(
bool value) { add_bool(AttributeType::Trusted, value); }
227 add_binary(AttributeType::CheckValue, checksum);
232 add_binary(AttributeType::StartDate,
reinterpret_cast<uint8_t*
>(&date),
sizeof(
Date));
237 add_binary(AttributeType::EndDate,
reinterpret_cast<uint8_t*
>(&date),
sizeof(
Date));
242 add_binary(AttributeType::PublicKeyInfo, pubkey_info);
262 inline void set_id(
const std::vector<uint8_t>&
id) { add_binary(AttributeType::Id,
id); }
266 add_binary(AttributeType::StartDate,
reinterpret_cast<uint8_t*
>(&date),
sizeof(
Date));
271 add_binary(AttributeType::EndDate,
reinterpret_cast<uint8_t*
>(&date),
sizeof(
Date));
275 inline void set_derive(
bool value) { add_bool(AttributeType::Derive, value); }
283 const std::vector<MechanismType>& ) {
301 inline void set_subject(
const std::vector<uint8_t>& subject) { add_binary(AttributeType::Subject, subject); }
304 inline void set_encrypt(
bool value) { add_bool(AttributeType::Encrypt, value); }
307 inline void set_verify(
bool value) { add_bool(AttributeType::Verify, value); }
313 inline void set_wrap(
bool value) { add_bool(AttributeType::Wrap, value); }
319 inline void set_trusted(
bool value) { add_bool(AttributeType::Trusted, value); }
335 add_binary(AttributeType::PublicKeyInfo, pubkey_info);
346 inline void set_subject(
const std::vector<uint8_t>& subject) { add_binary(AttributeType::Subject, subject); }
349 inline void set_sensitive(
bool value) { add_bool(AttributeType::Sensitive, value); }
352 inline void set_decrypt(
bool value) { add_bool(AttributeType::Decrypt, value); }
355 inline void set_sign(
bool value) { add_bool(AttributeType::Sign, value); }
361 inline void set_unwrap(
bool value) { add_bool(AttributeType::Unwrap, value); }
364 inline void set_extractable(
bool value) { add_bool(AttributeType::Extractable, value); }
386 add_binary(AttributeType::PublicKeyInfo, pubkey_info);
397 inline void set_sensitive(
bool value) { add_bool(AttributeType::Sensitive, value); }
400 inline void set_encrypt(
bool value) { add_bool(AttributeType::Encrypt, value); }
403 inline void set_decrypt(
bool value) { add_bool(AttributeType::Decrypt, value); }
406 inline void set_sign(
bool value) { add_bool(AttributeType::Sign, value); }
409 inline void set_verify(
bool value) { add_bool(AttributeType::Verify, value); }
412 inline void set_unwrap(
bool value) { add_bool(AttributeType::Unwrap, value); }
415 inline void set_extractable(
bool value) { add_bool(AttributeType::Extractable, value); }
424 inline void set_wrap(
bool value) { add_bool(AttributeType::Wrap, value); }
430 inline void set_trusted(
bool value) { add_bool(AttributeType::Trusted, value); }
434 add_binary(AttributeType::CheckValue, checksum);
503 template <
typename T>
504 static std::vector<T> search(
Session& session,
const std::vector<Attribute>& search_template);
507 template <
typename T>
508 static std::vector<T> search(
Session& session, std::string_view label);
511 template <
typename T>
512 static std::vector<T> search(
Session& session,
const std::vector<uint8_t>&
id);
515 template <
typename T>
516 static std::vector<T> search(
Session& session, std::string_view label,
const std::vector<uint8_t>&
id);
519 template <
typename T>
520 static std::vector<T> search(
Session& session);
529 void destroy()
const;
551 throw Invalid_Argument(
"Cannot reset handle on already valid PKCS11 object");
557 const std::reference_wrapper<Session> m_session;
564 std::vector<ObjectHandle> handles = finder.
find();
565 std::vector<T> result;
566 result.reserve(handles.size());
567 for(
const auto&
handle : handles) {
#define BOTAN_PUBLIC_API(maj, min)
#define BOTAN_FUTURE_EXPLICIT
Helper class to build the Attribute / CK_ATTRIBUTE structures.
AttributeContainer & operator=(const AttributeContainer &other)=delete
AttributeContainer & operator=(AttributeContainer &&other)=default
virtual ~AttributeContainer()=default
AttributeContainer()=default
void add_numeric(AttributeType attribute, T value)
AttributeContainer(AttributeContainer &&other)=default
const std::vector< Attribute > & attributes() const
void add_binary(AttributeType attribute, const std::vector< uint8_t, TAlloc > &binary)
void add_string(AttributeType attribute, std::string_view value)
void add_binary(AttributeType attribute, const uint8_t *value, size_t length)
AttributeContainer(const AttributeContainer &other)=delete
Common attributes of all certificate objects.
void set_public_key_info(const std::vector< uint8_t > &pubkey_info)
void set_check_value(const std::vector< uint8_t > &checksum)
void set_start_date(Date date)
void set_end_date(Date date)
void set_trusted(bool value)
CertificateType cert_type() const
void set_category(CertificateCategory category)
Common attributes of all data objects.
void set_application(std::string_view value)
void set_value(const secure_vector< uint8_t > &value)
void set_object_id(const std::vector< uint8_t > &object_id)
Common attributes of domain parameter.
Common attributes of all key objects.
void set_derive(bool value)
void set_id(const std::vector< uint8_t > &id)
void set_start_date(Date date)
void set_end_date(Date date)
void set_allowed_mechanisms(const std::vector< MechanismType > &)
Manages calls to C_FindObjects* functions (C_FindObjectsInit -> C_FindObjects -> C_FindObjectsFinal)
ObjectFinder(const ObjectFinder &other)=default
std::vector< ObjectHandle > find(std::uint32_t max_count=100) const
ObjectFinder & operator=(ObjectFinder &&other)=delete
ObjectFinder & operator=(const ObjectFinder &other)=delete
ObjectFinder(ObjectFinder &&other)=default
Common attributes of all objects.
ObjectClass object_class() const
void reset_handle(ObjectHandle handle)
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
Object(Object &&)=default
Object & operator=(const Object &)=delete
ObjectHandle handle() const
virtual ~Object()=default
Session & session() const
Object & operator=(Object &&)=delete
Object(const Object &)=default
Common attributes of all private keys.
void set_decrypt(bool value)
void set_unwrap(bool value)
void set_extractable(bool value)
void set_sign_recover(bool value)
void set_subject(const std::vector< uint8_t > &subject)
void set_always_authenticate(bool value)
void set_wrap_with_trusted(bool value)
void set_sign(bool value)
void set_unwrap_template(const AttributeContainer &)
void set_public_key_info(const std::vector< uint8_t > &pubkey_info)
void set_sensitive(bool value)
Common attributes of all public key objects.
void set_public_key_info(const std::vector< uint8_t > &pubkey_info)
void set_verify(bool value)
void set_wrap(bool value)
void set_subject(const std::vector< uint8_t > &subject)
void set_trusted(bool value)
void set_verify_recover(bool value)
void set_wrap_template(const AttributeContainer &)
void set_encrypt(bool value)
Common attributes of all secret (symmetric) keys.
void set_check_value(const std::vector< uint8_t > &checksum)
void set_sensitive(bool value)
void set_encrypt(bool value)
void set_unwrap_template(const AttributeContainer &)
void set_decrypt(bool value)
void set_wrap_template(const AttributeContainer &)
void set_wrap_with_trusted(bool value)
void set_sign(bool value)
void set_wrap(bool value)
void set_trusted(bool value)
void set_extractable(bool value)
void set_unwrap(bool value)
void set_verify(bool value)
void set_always_authenticate(bool value)
Represents a PKCS#11 session.
Common attributes of all storage objects.
void set_modifiable(bool value)
void set_private(bool value)
void set_copyable(bool value)
void set_token(bool value)
void set_destroyable(bool value)
void set_label(std::string_view label)
int(* final)(unsigned char *, CTX *)
CK_OBJECT_HANDLE ObjectHandle
std::vector< T, secure_allocator< T > > secure_vector
#define CK_INVALID_HANDLE
CK_ULONG CK_CERTIFICATE_CATEGORY