1 /*
2  *
3  *  Copyright (C) 2019, OFFIS e.V.
4  *  All rights reserved.  See COPYRIGHT file for details.
5  *
6  *  This software and supporting documentation were developed by
7  *
8  *    OFFIS e.V.
9  *    R&D Division Health
10  *    Escherweg 2
11  *    D-26121 Oldenburg, Germany
12  *
13  *
14  *  Module: dcmsign
15  *
16  *  Author: Marco Eichelberg
17  *
18  *  Purpose:
19  *    classes: SiSignaturePurpose
20  *
21  */
22 
23 #ifndef SIPURPOS_H
24 #define SIPURPOS_H
25 
26 #include "dcmtk/config/osconfig.h"
27 
28 #ifdef WITH_OPENSSL
29 
30 #include "dcmtk/dcmsign/sidefine.h"
31 #include "dcmtk/ofstd/ofstream.h"
32 
33 class DcmItem;
34 class OFCondition;
35 
36 /** Helper class for the Digital Signature Purpose Code Sequence.
37  *  @remark this class is only available if DCMTK is compiled with
38  *  OpenSSL support enabled.
39  */
40 class DCMTK_DCMSIGN_EXPORT SiSignaturePurpose
41 {
42 public:
43 
44     /** purpose of digital signature as defined in DICOM BCID 7007.
45      *  @remark this enum is only available if DCMTK is compiled with
46      *  OpenSSL support enabled.
47      */
48     enum E_SignaturePurposeType
49     {
50       /// no signature purpose specified
51       ESP_none = 0,
52 
53       /// Author's Signature
54       ESP_AuthorsSignature = 1,
55 
56       /// Coauthor's Signature
57       ESP_CoauthorsSignature = 2,
58 
59       /// Co-participant's Signature
60       ESP_CoparticipantsSignature = 3,
61 
62       /// Transcriptionist/Recorder Signature
63       ESP_TranscriptionistSignature = 4,
64 
65       /// Verification Signature
66       ESP_VerificationSignature = 5,
67 
68       /// Validation Signature
69       ESP_ValidationSignature = 6,
70 
71       /// Consent Signature
72       ESP_ConsentSignature = 7,
73 
74       /// Signature Witness Signature
75       ESP_SignatureWitnessSignature = 8,
76 
77       /// Event Witness Signature
78       ESP_EventWitnessSignature = 9,
79 
80       /// Identity Witness Signature
81       ESP_IdentityWitnessSignature = 10,
82 
83       /// Consent Witness Signature
84       ESP_ConsentWitnessSignature = 11,
85 
86       /// Interpreter Signature
87       ESP_InterpreterSignature = 12,
88 
89       /// Review Signature
90       ESP_ReviewSignature = 13,
91 
92       /// Source Signature
93       ESP_SourceSignature = 14,
94 
95       /// Addendum Signature
96       ESP_AddendumSignature = 15,
97 
98       /// Modification Signature
99       ESP_ModificationSignature = 16,
100 
101       /// Administrative (Error/Edit) Signature
102       ESP_AdministrativeSignature = 17,
103 
104       /// Timestamp Signature
105       ESP_TimestampSignature = 18
106 
107     };
108 
109     /** return the code value for the given signature purpose
110      *  @return code value for the given signature purpose, NULL for ESP_none
111      */
112     static const char *getCodeValue(E_SignaturePurposeType purpose);
113 
114     /** return the code meaning for the given signature purpose
115      *  @return code meaning for the given signature purpose, NULL for ESP_none
116      */
117     static const char *getCodeMeaning(E_SignaturePurposeType purpose);
118 
119     /** return the coding scheme designator for the given signature purpose
120      *  @return coding scheme designator for the given signature purpose
121      */
122     static const char *getCodingSchemeDesignator(E_SignaturePurposeType purpose);
123 
124     /** insert a digital signature purpose code sequence into the given DICOM item
125      *  @param seqItem item into which the sequence is inserted. This should be an item
126      *    of the DigitalSignaturesSequence.
127      *  @param sigPurpose signature purpose. If the purpose is ESP_none, nothing will be
128      *    inserted and this method will immediately return with EC_Normal
129      *  @return EC_Normal if successful, an error code otherwise
130      */
131     static OFCondition insertDigitalSignaturePurposeCodeSQ(DcmItem& seqItem, E_SignaturePurposeType sigPurpose);
132 
133     /** determine the signature purpose to be used, and prints a warning to the logger if
134      *  an override required by the signature profile causes the user selection to be ignored.
135      *  @param currentPurpose signature purpose selected by the user
136      *  @param overridePurpose override signature purpose required by the signature profile
137      *  @return signature purpose to be used for the digital signature purpose code sequence
138      */
139     static E_SignaturePurposeType determineOverridePurpose(E_SignaturePurposeType currentPurpose, E_SignaturePurposeType overridePurpose);
140 
141     /** look-up signature purpose enum by number
142      *  @param num number, 0 for ESP_none, 1 for ESP_AuthorsSignature etc.
143      *  @return signature purpose enum or ESP_none if number too high.
144      */
145     static E_SignaturePurposeType lookup(size_t num);
146 
147     /** print a list of all signature purpose codes supported by this helper class.
148      *  This is used by dcmsign --list-purposes.
149      *  @param out output stream to print to
150      */
151     static void printSignatureCodes(STD_NAMESPACE ostream& out);
152 
153 };
154 
155 #endif
156 #endif
157