PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
signature_types.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
19#pragma once
20
21#include <chrono>
22#include <cstdint>
23#include <optional>
24#include <string>
25#include <string_view>
26#include <vector>
27
28namespace kcenon::pacs::security {
29
47
53constexpr std::string_view to_string(signature_algorithm algo) {
54 switch (algo) {
55 case signature_algorithm::rsa_sha256: return "RSA-SHA256";
56 case signature_algorithm::rsa_sha384: return "RSA-SHA384";
57 case signature_algorithm::rsa_sha512: return "RSA-SHA512";
58 case signature_algorithm::ecdsa_sha256: return "ECDSA-SHA256";
59 case signature_algorithm::ecdsa_sha384: return "ECDSA-SHA384";
60 }
61 return "Unknown";
62}
63
69inline std::optional<signature_algorithm> parse_signature_algorithm(std::string_view str) {
70 if (str == "RSA-SHA256") return signature_algorithm::rsa_sha256;
71 if (str == "RSA-SHA384") return signature_algorithm::rsa_sha384;
72 if (str == "RSA-SHA512") return signature_algorithm::rsa_sha512;
73 if (str == "ECDSA-SHA256") return signature_algorithm::ecdsa_sha256;
74 if (str == "ECDSA-SHA384") return signature_algorithm::ecdsa_sha384;
75 return std::nullopt;
76}
77
89
95constexpr std::string_view to_string(signature_status status) {
96 switch (status) {
97 case signature_status::valid: return "Valid";
98 case signature_status::invalid: return "Invalid";
99 case signature_status::expired: return "Expired";
100 case signature_status::untrusted_signer: return "UntrustedSigner";
101 case signature_status::revoked: return "Revoked";
102 case signature_status::no_signature: return "NoSignature";
103 }
104 return "Unknown";
105}
106
114 std::string signature_uid;
115 std::string signer_name;
117 std::chrono::system_clock::time_point timestamp;
119 std::vector<std::uint32_t> signed_tags;
121
122 bool operator==(const signature_info&) const = default;
123};
124
130enum class mac_algorithm {
131 sha256,
132 sha384,
133 sha512
134};
135
141constexpr std::string_view to_dicom_uid(mac_algorithm algo) {
142 switch (algo) {
143 case mac_algorithm::sha256: return "2.16.840.1.101.3.4.2.1";
144 case mac_algorithm::sha384: return "2.16.840.1.101.3.4.2.2";
145 case mac_algorithm::sha512: return "2.16.840.1.101.3.4.2.3";
146 }
147 return "";
148}
149
159
165constexpr std::string_view to_dicom_term(certificate_type type) {
166 switch (type) {
167 case certificate_type::x509_certificate: return "X509_1993_SIG";
168 case certificate_type::x509_certificate_chain: return "X509_1993_SIG_CHAIN";
169 }
170 return "";
171}
172
173} // namespace kcenon::pacs::security
constexpr std::string_view to_dicom_uid(mac_algorithm algo)
Convert mac_algorithm to DICOM UID string.
std::optional< signature_algorithm > parse_signature_algorithm(std::string_view str)
Parse signature_algorithm from string.
mac_algorithm
MAC algorithm identifiers per DICOM PS3.15.
constexpr auto to_string(anonymization_profile profile) noexcept -> std::string_view
Convert profile enum to string representation.
signature_status
Status of signature verification.
@ untrusted_signer
Signer certificate is not trusted.
@ no_signature
No signature present in dataset.
@ revoked
Signer certificate has been revoked.
@ valid
Signature is valid and trusted.
@ expired
Signer certificate has expired.
@ invalid
Signature verification failed (tampered data)
signature_algorithm
Signature algorithms supported for DICOM digital signatures.
@ rsa_sha512
RSA with SHA-512 (highest security)
@ ecdsa_sha256
ECDSA with SHA-256 (compact signatures)
@ rsa_sha256
RSA with SHA-256 (recommended for most use cases)
certificate_type
Certificate type for DICOM signatures.
@ x509_certificate
X.509 certificate (most common)
@ x509_certificate_chain
Full X.509 certificate chain.
constexpr std::string_view to_dicom_term(certificate_type type)
Convert certificate_type to DICOM defined term.
Information about a digital signature.
std::chrono::system_clock::time_point timestamp
Digital Signature DateTime (0400,0105)
std::string signature_uid
Digital Signature UID (0400,0100)
std::string certificate_thumbprint
SHA-256 thumbprint of signer certificate.
std::string signer_name
Name of the signer (extracted from certificate)
std::vector< std::uint32_t > signed_tags
List of tags that were signed.
signature_algorithm algorithm
Algorithm used for signing.
std::string signer_organization
Organization of the signer.
bool operator==(const signature_info &) const =default