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< certificate > certs_
 

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.

Member Function Documentation

◆ add()

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

Add a certificate to the chain.

Parameters
certCertificate to add

Definition at line 657 of file certificate.cpp.

657 {
658 certs_.push_back(std::move(cert));
659}
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)

Definition at line 668 of file certificate.cpp.

668 {
669 return certs_;
670}

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

Definition at line 672 of file certificate.cpp.

672 {
673 return certs_.empty();
674}

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

Definition at line 661 of file certificate.cpp.

661 {
662 if (certs_.empty()) {
663 return nullptr;
664 }
665 return &certs_.front();
666}

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

Definition at line 680 of file certificate.cpp.

681 {
682 auto content_result = read_file(path);
683 if (content_result.is_err()) {
684 return kcenon::common::make_error<certificate_chain>(
685 content_result.error().code,
686 content_result.error().message,
687 "certificate_chain");
688 }
689
690 const std::string& content = content_result.value();
691 certificate_chain chain;
692
693 // Parse multiple certificates from PEM
694 bio_ptr bio(BIO_new_mem_buf(content.data(), static_cast<int>(content.size())));
695 if (!bio) {
696 return kcenon::common::make_error<certificate_chain>(
697 2, "Failed to create BIO: " + get_openssl_error(), "certificate_chain");
698 }
699
700 while (true) {
701 X509* x509 = PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr);
702 if (!x509) {
703 // Check if it's EOF or an error
704 unsigned long err = ERR_peek_last_error();
705 if (ERR_GET_REASON(err) == PEM_R_NO_START_LINE) {
706 ERR_clear_error();
707 break; // End of file
708 }
709 break; // Error or EOF
710 }
711
712 certificate cert;
713 cert.impl_ = std::make_unique<certificate_impl>(x509);
714 chain.add(std::move(cert));
715 }
716
717 if (chain.empty()) {
718 return kcenon::common::make_error<certificate_chain>(
719 3, "No certificates found in PEM file", "certificate_chain");
720 }
721
722 return chain;
723}
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

Definition at line 676 of file certificate.cpp.

676 {
677 return certs_.size();
678}

References certs_.

Member Data Documentation

◆ certs_

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

Definition at line 389 of file certificate.h.

Referenced by add(), certificates(), empty(), end_entity(), and size().


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