PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::security::private_key Class Reference

#include <certificate.h>

Collaboration diagram for kcenon::pacs::security::private_key:
Collaboration graph

Public Member Functions

 private_key ()
 Default constructor - creates an empty key.
 
 private_key (const private_key &)=delete
 Copy constructor (deleted - private keys should not be copied)
 
 private_key (private_key &&other) noexcept
 Move constructor.
 
auto operator= (const private_key &) -> private_key &=delete
 Copy assignment (deleted)
 
auto operator= (private_key &&other) noexcept -> private_key &
 Move assignment.
 
 ~private_key ()
 Destructor - securely erases key material.
 
auto algorithm_name () const -> std::string
 Get the algorithm name.
 
auto key_size () const -> int
 Get the key size in bits.
 
auto is_loaded () const noexcept -> bool
 Check if key is loaded.
 
auto impl () const noexcept -> const private_key_impl *
 Get internal implementation (for internal use only)
 
auto impl () noexcept -> private_key_impl *
 

Static Public Member Functions

static auto load_from_pem (std::string_view path, std::string_view password="") -> kcenon::common::Result< private_key >
 Load private key from PEM file.
 
static auto load_from_pem_string (std::string_view pem_data, std::string_view password="") -> kcenon::common::Result< private_key >
 Load private key from PEM string.
 

Private Attributes

std::unique_ptr< private_key_implimpl_
 

Detailed Description

Definition at line 239 of file certificate.h.

Constructor & Destructor Documentation

◆ private_key() [1/3]

kcenon::pacs::security::private_key::private_key ( )

Default constructor - creates an empty key.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 520 of file certificate.cpp.

520: impl_(std::make_unique<private_key_impl>()) {}
std::unique_ptr< private_key_impl > impl_

◆ private_key() [2/3]

kcenon::pacs::security::private_key::private_key ( const private_key & )
delete

Copy constructor (deleted - private keys should not be copied)

◆ private_key() [3/3]

kcenon::pacs::security::private_key::private_key ( private_key && other)
defaultnoexcept

Move constructor.

◆ ~private_key()

kcenon::pacs::security::private_key::~private_key ( )
default

Member Function Documentation

◆ algorithm_name()

auto kcenon::pacs::security::private_key::algorithm_name ( ) const -> std::string
nodiscard

Get the algorithm name.

Returns
Algorithm name (e.g., "RSA", "EC")
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 568 of file certificate.cpp.

568 {
569 if (!impl_->is_loaded()) {
570 return "";
571 }
572
573 int type = EVP_PKEY_base_id(impl_->pkey());
574 switch (type) {
575 case EVP_PKEY_RSA:
576 case EVP_PKEY_RSA2:
577 return "RSA";
578 case EVP_PKEY_EC:
579 return "EC";
580 case EVP_PKEY_DSA:
581 return "DSA";
582 case EVP_PKEY_ED25519:
583 return "ED25519";
584 case EVP_PKEY_ED448:
585 return "ED448";
586 default:
587 return "Unknown";
588 }
589}

References impl_.

◆ impl() [1/2]

auto kcenon::pacs::security::private_key::impl ( ) const -> const private_key_impl*
nodiscardnoexcept

Get internal implementation (for internal use only)

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 603 of file certificate.cpp.

603 {
604 return impl_.get();
605}

References impl_.

◆ impl() [2/2]

auto kcenon::pacs::security::private_key::impl ( ) -> private_key_impl*
nodiscardnoexcept

Definition at line 607 of file certificate.cpp.

607 {
608 return impl_.get();
609}

References impl_.

◆ is_loaded()

auto kcenon::pacs::security::private_key::is_loaded ( ) const -> bool
nodiscardnoexcept

Check if key is loaded.

Returns
true if key data is loaded
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 599 of file certificate.cpp.

599 {
600 return impl_ && impl_->is_loaded();
601}

References impl_.

◆ key_size()

auto kcenon::pacs::security::private_key::key_size ( ) const -> int
nodiscard

Get the key size in bits.

Returns
Key size (e.g., 2048, 4096 for RSA; 256, 384 for EC)
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 591 of file certificate.cpp.

591 {
592 if (!impl_->is_loaded()) {
593 return 0;
594 }
595
596 return EVP_PKEY_bits(impl_->pkey());
597}

References impl_.

◆ load_from_pem()

auto kcenon::pacs::security::private_key::load_from_pem ( std::string_view path,
std::string_view password = "" ) -> kcenon::common::Result<private_key>
staticnodiscard

Load private key from PEM file.

Parameters
pathPath to PEM-encoded private key file
passwordOptional password for encrypted keys (empty for unencrypted)
Returns
Result containing private key or error
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 528 of file certificate.cpp.

529 {
530 auto content_result = read_file(path);
531 if (content_result.is_err()) {
532 return kcenon::common::make_error<private_key>(
533 content_result.error().code,
534 content_result.error().message,
535 "private_key");
536 }
537
538 return load_from_pem_string(content_result.value(), password);
539}
static auto load_from_pem_string(std::string_view pem_data, std::string_view password="") -> kcenon::common::Result< private_key >
Load private key from PEM string.

◆ load_from_pem_string()

auto kcenon::pacs::security::private_key::load_from_pem_string ( std::string_view pem_data,
std::string_view password = "" ) -> kcenon::common::Result<private_key>
staticnodiscard

Load private key from PEM string.

Parameters
pem_dataPEM-encoded private key data
passwordOptional password for encrypted keys
Returns
Result containing private key or error
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 541 of file certificate.cpp.

542 {
543 bio_ptr bio(BIO_new_mem_buf(pem_data.data(), static_cast<int>(pem_data.size())));
544 if (!bio) {
545 return kcenon::common::make_error<private_key>(
546 2, "Failed to create BIO: " + get_openssl_error(), "private_key");
547 }
548
549 EVP_PKEY* pkey = nullptr;
550 if (password.empty()) {
551 pkey = PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr);
552 } else {
553 pkey = PEM_read_bio_PrivateKey(
554 bio.get(), nullptr, nullptr,
555 const_cast<char*>(std::string(password).c_str()));
556 }
557
558 if (!pkey) {
559 return kcenon::common::make_error<private_key>(
560 3, "Failed to parse PEM private key: " + get_openssl_error(), "private_key");
561 }
562
563 private_key key;
564 key.impl_ = std::make_unique<private_key_impl>(pkey);
565 return key;
566}
private_key()
Default constructor - creates an empty key.

References impl_.

◆ operator=() [1/2]

auto kcenon::pacs::security::private_key::operator= ( const private_key & ) -> private_key &=delete
delete

◆ operator=() [2/2]

auto kcenon::pacs::security::private_key::operator= ( private_key && other) -> private_key &
defaultnoexcept

Move assignment.

Member Data Documentation

◆ impl_

std::unique_ptr<private_key_impl> kcenon::pacs::security::private_key::impl_
private

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