summaryrefslogtreecommitdiff
path: root/poppler/SignatureInfo.cc
blob: f1ad45e3c153ddc78bb4e540f2fe05d3c6eeb3ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//========================================================================
//
// SignatureInfo.cc
//
// This file is licensed under the GPLv2 or later
//
// Copyright 2015 André Guerreiro <aguerreiro1985@gmail.com>
// Copyright 2015 André Esser <bepandre@hotmail.com>
// Copyright 2017 Hans-Ulrich Jüttner <huj@froreich-bioscientia.de>
// Copyright 2017-2019 Albert Astals Cid <aacid@kde.org>
// Copyright 2018 Chinmoy Ranjan Pradhan <chinmoyrp65@protonmail.com>
// Copyright 2018 Oliver Sander <oliver.sander@tu-dresden.de>
//
//========================================================================

#include <config.h>

#include "SignatureInfo.h"
#include "CertificateInfo.h"
#include "goo/gmem.h"
#include <cstdlib>
#include <cstring>

#ifdef ENABLE_NSS3
    #include <hasht.h>
#else
    static const int HASH_AlgNULL = -1;
#endif

/* Constructor & Destructor */

SignatureInfo::SignatureInfo()
{
  sig_status = SIGNATURE_NOT_VERIFIED;
  cert_status = CERTIFICATE_NOT_VERIFIED;
  cert_info = nullptr;
  signer_name = nullptr;
  subject_dn = nullptr;
  location = nullptr;
  reason = nullptr;
  hash_type = HASH_AlgNULL;
  signing_time = 0;
  sig_subfilter_supported = false;
}

SignatureInfo::SignatureInfo(SignatureValidationStatus sig_val_status, CertificateValidationStatus cert_val_status)
{
  sig_status = sig_val_status;
  cert_status = cert_val_status;
  cert_info = nullptr;
  signer_name = nullptr;
  subject_dn = nullptr;
  location = nullptr;
  reason = nullptr;
  hash_type = HASH_AlgNULL;
  signing_time = 0;
  sig_subfilter_supported = false;
}

SignatureInfo::~SignatureInfo()
{
  free(location);
  free(reason);
  free(signer_name);
  free(subject_dn);
}

/* GETTERS */

SignatureValidationStatus SignatureInfo::getSignatureValStatus()
{
  return sig_status;
}

CertificateValidationStatus SignatureInfo::getCertificateValStatus()
{
  return cert_status;
}

const char *SignatureInfo::getSignerName()
{
  return signer_name;
}

const char *SignatureInfo::getSubjectDN()
{
  return subject_dn;
}

const char *SignatureInfo::getLocation() const
{
  return location;
}

const char *SignatureInfo::getReason() const
{
  return reason;
}

int SignatureInfo::getHashAlgorithm()
{
  return hash_type;
}

time_t SignatureInfo::getSigningTime()
{
  return signing_time;
}

const X509CertificateInfo *SignatureInfo::getCertificateInfo() const
{
  return cert_info.get();
}

/* SETTERS */

void SignatureInfo::setSignatureValStatus(enum SignatureValidationStatus sig_val_status)
{
  sig_status = sig_val_status;
}

void SignatureInfo::setCertificateValStatus(enum CertificateValidationStatus cert_val_status)
{
  cert_status = cert_val_status;
}

void SignatureInfo::setSignerName(char *signerName)
{
  free(signer_name);
  signer_name = signerName;
}

void SignatureInfo::setSubjectDN(const char *subjectDN)
{
  free(subject_dn);
  subject_dn = subjectDN ? strdup(subjectDN) : nullptr;
}

void SignatureInfo::setLocation(const char *loc)
{
  free(location);
  location = strdup(loc);
}

void SignatureInfo::setReason(const char *signingReason)
{
  free(reason);
  reason = strdup(signingReason);
}

void SignatureInfo::setHashAlgorithm(int type)
{
  hash_type = type;
}

void SignatureInfo::setSigningTime(time_t signingTime)
{
  signing_time = signingTime;
}

void SignatureInfo::setCertificateInfo(std::unique_ptr<X509CertificateInfo> certInfo)
{
  cert_info = std::move(certInfo);
}