better split up of library files "types.h" & "definitions.h"
[strongswan.git] / src / libstrongswan / crypto / certinfo.c
1 /**
2 * @file certinfo.c
3 *
4 * @brief Implementation of certinfo_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Andreas Steffen
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <time.h>
24
25 #include <library.h>
26
27 #include "certinfo.h"
28
29 typedef struct private_certinfo_t private_certinfo_t;
30
31 /**
32 * Private data of a certinfo_t object.
33 */
34 struct private_certinfo_t {
35 /**
36 * Public interface for this certificate status information object.
37 */
38 certinfo_t public;
39
40 /**
41 * Serial number of the certificate
42 */
43 chunk_t serialNumber;
44
45 /**
46 * Certificate status
47 */
48 cert_status_t status;
49
50 /**
51 * Time when the certificate status info was generated
52 */
53 time_t thisUpdate;
54
55 /**
56 * Time when an updated certifcate status info will be available
57 */
58 time_t nextUpdate;
59
60 /**
61 * Time of certificate revocation
62 */
63 time_t revocationTime;
64
65 /**
66 * Reason of certificate revocation
67 */
68 crl_reason_t revocationReason;
69 };
70
71 ENUM(cert_status_names, CERT_GOOD, CERT_UNTRUSTED,
72 "good",
73 "revoked",
74 "unknown",
75 "unknown",
76 "untrusted",
77 );
78
79 ENUM(crl_reason_names, REASON_UNSPECIFIED, REASON_REMOVE_FROM_CRL,
80 "unspecified",
81 "key compromise",
82 "ca compromise",
83 "affiliation changed",
84 "superseded",
85 "cessation of operation",
86 "certificate hold",
87 "reason #7",
88 "remove from crl",
89 );
90
91 /**
92 * Implements certinfo_t.get_serialNumber
93 */
94 static chunk_t get_serialNumber(const private_certinfo_t *this)
95 {
96 return this->serialNumber;
97 }
98
99 /**
100 * Implements certinfo_t.set_status
101 */
102 static void set_status(private_certinfo_t *this, cert_status_t status)
103 {
104 this->status = status;
105 }
106
107 /**
108 * Implements certinfo_t.get_status
109 */
110 static cert_status_t get_status(const private_certinfo_t *this)
111 {
112 return this->status;
113 }
114
115 /**
116 * Implements certinfo_t.set_nextUpdate
117 */
118 static void set_nextUpdate(private_certinfo_t *this, time_t nextUpdate)
119 {
120 this->nextUpdate = nextUpdate;
121 }
122
123 /**
124 * Implements certinfo_t.get_nextUpdate
125 */
126 static time_t get_nextUpdate(const private_certinfo_t *this)
127 {
128 return this->nextUpdate;
129 }
130
131 /**
132 * Implements certinfo_t.set_revocationTime
133 */
134 static void set_revocationTime(private_certinfo_t *this, time_t revocationTime)
135 {
136 this->revocationTime = revocationTime;
137 }
138
139 /**
140 * Implements certinfo_t.get_revocationTime
141 */
142 static time_t get_revocationTime(const private_certinfo_t *this)
143 {
144 return this->revocationTime;
145 }
146
147 /**
148 * Implements certinfo_t.set_revocationReason
149 */
150 static void set_revocationReason(private_certinfo_t *this, crl_reason_t reason)
151 {
152 this->revocationReason = reason;
153 }
154
155 /**
156 * Implements certinfo_t.get_revocationReason
157 */
158 static crl_reason_t get_revocationReason(const private_certinfo_t *this)
159 {
160 return this->revocationReason;
161 }
162
163 /**
164 * Implements certinfo_t.destroy
165 */
166 static void destroy(private_certinfo_t *this)
167 {
168 free(this->serialNumber.ptr);
169 free(this);
170 }
171
172 /*
173 * Described in header.
174 */
175 certinfo_t *certinfo_create(chunk_t serial)
176 {
177 private_certinfo_t *this = malloc_thing(private_certinfo_t);
178
179 /* initialize */
180 this->serialNumber = chunk_clone(serial);
181 this->status = CERT_UNDEFINED;
182 this->nextUpdate = UNDEFINED_TIME;
183 this->revocationTime = UNDEFINED_TIME;
184 this->revocationReason = REASON_UNSPECIFIED;
185
186 /* public functions */
187 this->public.get_serialNumber = (chunk_t (*) (const certinfo_t*))get_serialNumber;
188 this->public.set_status = (void (*) (certinfo_t*,cert_status_t))set_status;
189 this->public.get_status = (cert_status_t (*) (const certinfo_t*))get_status;
190 this->public.set_nextUpdate = (void (*) (certinfo_t*,time_t))set_nextUpdate;
191 this->public.get_nextUpdate = (time_t (*) (const certinfo_t*))get_nextUpdate;
192 this->public.set_revocationTime = (void (*) (certinfo_t*,time_t))set_revocationTime;
193 this->public.get_revocationTime = (time_t (*) (const certinfo_t*))get_revocationTime;
194 this->public.set_revocationReason = (void (*) (certinfo_t*, crl_reason_t))set_revocationReason;
195 this->public.get_revocationReason = (crl_reason_t(*) (const certinfo_t*))get_revocationReason;
196 this->public.destroy = (void (*) (certinfo_t*))destroy;
197
198 return &this->public;
199 }