2 * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
12 #include <openssl/objects.h>
13 #include <openssl/ts.h>
14 #include <openssl/pkcs7.h>
17 DEFINE_STACK_OF(X509_EXTENSION)
19 int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info)
21 TS_STATUS_INFO *new_status_info;
23 if (a->status_info == status_info)
25 new_status_info = TS_STATUS_INFO_dup(status_info);
26 if (new_status_info == NULL) {
27 TSerr(TS_F_TS_RESP_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE);
30 TS_STATUS_INFO_free(a->status_info);
31 a->status_info = new_status_info;
36 TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a)
38 return a->status_info;
41 /* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */
42 void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info)
46 TS_TST_INFO_free(a->tst_info);
47 a->tst_info = tst_info;
50 PKCS7 *TS_RESP_get_token(TS_RESP *a)
55 TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a)
60 int TS_TST_INFO_set_version(TS_TST_INFO *a, long version)
62 return ASN1_INTEGER_set(a->version, version);
65 long TS_TST_INFO_get_version(const TS_TST_INFO *a)
67 return ASN1_INTEGER_get(a->version);
70 int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy)
72 ASN1_OBJECT *new_policy;
74 if (a->policy_id == policy)
76 new_policy = OBJ_dup(policy);
77 if (new_policy == NULL) {
78 TSerr(TS_F_TS_TST_INFO_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
81 ASN1_OBJECT_free(a->policy_id);
82 a->policy_id = new_policy;
86 ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a)
91 int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint)
93 TS_MSG_IMPRINT *new_msg_imprint;
95 if (a->msg_imprint == msg_imprint)
97 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
98 if (new_msg_imprint == NULL) {
99 TSerr(TS_F_TS_TST_INFO_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
102 TS_MSG_IMPRINT_free(a->msg_imprint);
103 a->msg_imprint = new_msg_imprint;
107 TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a)
109 return a->msg_imprint;
112 int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial)
114 ASN1_INTEGER *new_serial;
116 if (a->serial == serial)
118 new_serial = ASN1_INTEGER_dup(serial);
119 if (new_serial == NULL) {
120 TSerr(TS_F_TS_TST_INFO_SET_SERIAL, ERR_R_MALLOC_FAILURE);
123 ASN1_INTEGER_free(a->serial);
124 a->serial = new_serial;
128 const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a)
133 int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime)
135 ASN1_GENERALIZEDTIME *new_time;
137 if (a->time == gtime)
139 new_time = ASN1_STRING_dup(gtime);
140 if (new_time == NULL) {
141 TSerr(TS_F_TS_TST_INFO_SET_TIME, ERR_R_MALLOC_FAILURE);
144 ASN1_GENERALIZEDTIME_free(a->time);
149 const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a)
154 int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy)
156 TS_ACCURACY *new_accuracy;
158 if (a->accuracy == accuracy)
160 new_accuracy = TS_ACCURACY_dup(accuracy);
161 if (new_accuracy == NULL) {
162 TSerr(TS_F_TS_TST_INFO_SET_ACCURACY, ERR_R_MALLOC_FAILURE);
165 TS_ACCURACY_free(a->accuracy);
166 a->accuracy = new_accuracy;
170 TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a)
175 int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds)
177 ASN1_INTEGER *new_seconds;
179 if (a->seconds == seconds)
181 new_seconds = ASN1_INTEGER_dup(seconds);
182 if (new_seconds == NULL) {
183 TSerr(TS_F_TS_ACCURACY_SET_SECONDS, ERR_R_MALLOC_FAILURE);
186 ASN1_INTEGER_free(a->seconds);
187 a->seconds = new_seconds;
191 const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a)
196 int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis)
198 ASN1_INTEGER *new_millis = NULL;
200 if (a->millis == millis)
202 if (millis != NULL) {
203 new_millis = ASN1_INTEGER_dup(millis);
204 if (new_millis == NULL) {
205 TSerr(TS_F_TS_ACCURACY_SET_MILLIS, ERR_R_MALLOC_FAILURE);
209 ASN1_INTEGER_free(a->millis);
210 a->millis = new_millis;
214 const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a)
219 int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros)
221 ASN1_INTEGER *new_micros = NULL;
223 if (a->micros == micros)
225 if (micros != NULL) {
226 new_micros = ASN1_INTEGER_dup(micros);
227 if (new_micros == NULL) {
228 TSerr(TS_F_TS_ACCURACY_SET_MICROS, ERR_R_MALLOC_FAILURE);
232 ASN1_INTEGER_free(a->micros);
233 a->micros = new_micros;
237 const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a)
242 int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering)
244 a->ordering = ordering ? 0xFF : 0x00;
248 int TS_TST_INFO_get_ordering(const TS_TST_INFO *a)
250 return a->ordering ? 1 : 0;
253 int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce)
255 ASN1_INTEGER *new_nonce;
257 if (a->nonce == nonce)
259 new_nonce = ASN1_INTEGER_dup(nonce);
260 if (new_nonce == NULL) {
261 TSerr(TS_F_TS_TST_INFO_SET_NONCE, ERR_R_MALLOC_FAILURE);
264 ASN1_INTEGER_free(a->nonce);
265 a->nonce = new_nonce;
269 const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a)
274 int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa)
276 GENERAL_NAME *new_tsa;
280 new_tsa = GENERAL_NAME_dup(tsa);
281 if (new_tsa == NULL) {
282 TSerr(TS_F_TS_TST_INFO_SET_TSA, ERR_R_MALLOC_FAILURE);
285 GENERAL_NAME_free(a->tsa);
290 GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a)
295 STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a)
297 return a->extensions;
300 void TS_TST_INFO_ext_free(TS_TST_INFO *a)
304 sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
305 a->extensions = NULL;
308 int TS_TST_INFO_get_ext_count(TS_TST_INFO *a)
310 return X509v3_get_ext_count(a->extensions);
313 int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos)
315 return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
318 int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, const ASN1_OBJECT *obj, int lastpos)
320 return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
323 int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos)
325 return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
328 X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc)
330 return X509v3_get_ext(a->extensions, loc);
333 X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc)
335 return X509v3_delete_ext(a->extensions, loc);
338 int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc)
340 return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
343 void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx)
345 return X509V3_get_d2i(a->extensions, nid, crit, idx);
348 int TS_STATUS_INFO_set_status(TS_STATUS_INFO *a, int i)
350 return ASN1_INTEGER_set(a->status, i);
353 const ASN1_INTEGER *TS_STATUS_INFO_get0_status(const TS_STATUS_INFO *a)
358 const STACK_OF(ASN1_UTF8STRING) *
359 TS_STATUS_INFO_get0_text(const TS_STATUS_INFO *a)
364 const ASN1_BIT_STRING *TS_STATUS_INFO_get0_failure_info(const TS_STATUS_INFO *a)
366 return a->failure_info;