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

Represents a certificate chain for validation. More...

#include <certificate.h>

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

Public Member Functions

 certificate_chain ()=default
 Default constructor - creates an empty chain.
 
void add (certificate cert)
 Add a certificate to the chain.
 
auto end_entity () const -> const certificate *
 Get the end-entity (leaf) certificate.
 
auto certificates () const -> const std::vector< certificate > &
 Get all certificates in the chain.
 
auto empty () const noexcept -> bool
 Check if chain is empty.
 
auto size () const noexcept -> size_t
 Get number of certificates in chain.
 

Static Public Member Functions

static auto load_from_pem (std::string_view path) -> kcenon::common::Result< certificate_chain >
 Load certificate chain from PEM file.
 

Private Attributes

std::vector< certificatecerts_
 

Detailed Description

Represents a certificate chain for validation.

A certificate chain consists of the end-entity certificate, intermediate certificates, and optionally the root certificate.

Definition at line 339 of file certificate.h.

Constructor & Destructor Documentation

◆ certificate_chain()

kcenon::pacs::security::certificate_chain::certificate_chain ( )
default

Default constructor - creates an empty chain.

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

Member Function Documentation

◆ add()

void kcenon::pacs::security::certificate_chain::add ( certificate cert)

Add a certificate to the chain.

Parameters
certCertificate to add
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 615 of file certificate.cpp.

615 {
616 certs_.push_back(std::move(cert));
617}
std::vector< certificate > certs_

References certs_.

Referenced by load_from_pem().

Here is the caller graph for this function:

◆ certificates()

auto kcenon::pacs::security::certificate_chain::certificates ( ) const -> const std::vector<certificate>&
nodiscard

Get all certificates in the chain.

Returns
Vector of certificates (end-entity first, root last)
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 626 of file certificate.cpp.

626 {
627 return certs_;
628}

References certs_.

◆ empty()

auto kcenon::pacs::security::certificate_chain::empty ( ) const -> bool
nodiscardnoexcept

Check if chain is empty.

Returns
true if no certificates in chain
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 630 of file certificate.cpp.

630 {
631 return certs_.empty();
632}

References certs_.

Referenced by load_from_pem().

Here is the caller graph for this function:

◆ end_entity()

auto kcenon::pacs::security::certificate_chain::end_entity ( ) const -> const certificate*
nodiscard

Get the end-entity (leaf) certificate.

Returns
End-entity certificate or nullptr if chain is empty
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 619 of file certificate.cpp.

619 {
620 if (certs_.empty()) {
621 return nullptr;
622 }
623 return &certs_.front();
624}

References certs_.

◆ load_from_pem()

auto kcenon::pacs::security::certificate_chain::load_from_pem ( std::string_view path) -> kcenon::common::Result<certificate_chain>
staticnodiscard

Load certificate chain from PEM file.

PEM file may contain multiple certificates. The first certificate is treated as the end-entity certificate.

Parameters
pathPath to PEM file containing certificate chain
Returns
Result containing certificate chain or error
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/security/certificate.h.

Definition at line 638 of file certificate.cpp.

639 {
640 auto content_result = read_file(path);
641 if (content_result.is_err()) {
642 return kcenon::common::make_error<certificate_chain>(
643 content_result.error().code,
644 content_result.error().message,
645 "certificate_chain");
646 }
647
648 const std::string& content = content_result.value();
649 certificate_chain chain;
650
651 // Parse multiple certificates from PEM
652 bio_ptr bio(BIO_new_mem_buf(content.data(), static_cast<int>(content.size())));
653 if (!bio) {
654 return kcenon::common::make_error<certificate_chain>(
655 2, "Failed to create BIO: " + get_openssl_error(), "certificate_chain");
656 }
657
658 while (true) {
659 X509* x509 = PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr);
660 if (!x509) {
661 // Check if it's EOF or an error
662 unsigned long err = ERR_peek_last_error();
663 if (ERR_GET_REASON(err) == PEM_R_NO_START_LINE) {
664 ERR_clear_error();
665 break; // End of file
666 }
667 break; // Error or EOF
668 }
669
670 certificate cert;
671 cert.impl_ = std::make_unique<certificate_impl>(x509);
672 chain.add(std::move(cert));
673 }
674
675 if (chain.empty()) {
676 return kcenon::common::make_error<certificate_chain>(
677 3, "No certificates found in PEM file", "certificate_chain");
678 }
679
680 return chain;
681}
certificate_chain()=default
Default constructor - creates an empty chain.

References add(), empty(), and kcenon::pacs::security::certificate::impl_.

Here is the call graph for this function:

◆ size()

auto kcenon::pacs::security::certificate_chain::size ( ) const -> size_t
nodiscardnoexcept

Get number of certificates in chain.

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

Definition at line 634 of file certificate.cpp.

634 {
635 return certs_.size();
636}

References certs_.

Member Data Documentation

◆ certs_

std::vector<certificate> kcenon::pacs::security::certificate_chain::certs_
private

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