2 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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 int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info)
19 TS_STATUS_INFO *new_status_info;
21 if (a->status_info == status_info)
23 new_status_info = TS_STATUS_INFO_dup(status_info);
24 if (new_status_info == NULL) {
25 TSerr(TS_F_TS_RESP_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE);
28 TS_STATUS_INFO_free(a->status_info);
29 a->status_info = new_status_info;
34 TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a)
36 return a->status_info;
39 /* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */
40 void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info)
44 TS_TST_INFO_free(a->tst_info);
45 a->tst_info = tst_info;
48 PKCS7 *TS_RESP_get_token(TS_RESP *a)
53 TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a)
58 int TS_TST_INFO_set_version(TS_TST_INFO *a, long version)
60 return ASN1_INTEGER_set(a->version, version);
63 long TS_TST_INFO_get_version(const TS_TST_INFO *a)
65 return ASN1_INTEGER_get(a->version);
68 int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy)
70 ASN1_OBJECT *new_policy;
72 if (a->policy_id == policy)
74 new_policy = OBJ_dup(policy);
75 if (new_policy == NULL) {
76 TSerr(TS_F_TS_TST_INFO_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
79 ASN1_OBJECT_free(a->policy_id);
80 a->policy_id = new_policy;
84 ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a)
89 int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint)
91 TS_MSG_IMPRINT *new_msg_imprint;
93 if (a->msg_imprint == msg_imprint)
95 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
96 if (new_msg_imprint == NULL) {
97 TSerr(TS_F_TS_TST_INFO_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
100 TS_MSG_IMPRINT_free(a->msg_imprint);
101 a->msg_imprint = new_msg_imprint;
105 TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a)
107 return a->msg_imprint;
110 int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial)
112 ASN1_INTEGER *new_serial;
114 if (a->serial == serial)
116 new_serial = ASN1_INTEGER_dup(serial);
117 if (new_serial == NULL) {
118 TSerr(TS_F_TS_TST_INFO_SET_SERIAL, ERR_R_MALLOC_FAILURE);
121 ASN1_INTEGER_free(a->serial);
122 a->serial = new_serial;
126 const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a)
131 int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime)
133 ASN1_GENERALIZEDTIME *new_time;
135 if (a->time == gtime)
137 new_time = ASN1_STRING_dup(gtime);
138 if (new_time == NULL) {
139 TSerr(TS_F_TS_TST_INFO_SET_TIME, ERR_R_MALLOC_FAILURE);
142 ASN1_GENERALIZEDTIME_free(a->time);
147 const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a)
152 int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy)
154 TS_ACCURACY *new_accuracy;
156 if (a->accuracy == accuracy)
158 new_accuracy = TS_ACCURACY_dup(accuracy);
159 if (new_accuracy == NULL) {
160 TSerr(TS_F_TS_TST_INFO_SET_ACCURACY, ERR_R_MALLOC_FAILURE);
163 TS_ACCURACY_free(a->accuracy);
164 a->accuracy = new_accuracy;
168 TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a)
173 int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds)
175 ASN1_INTEGER *new_seconds;
177 if (a->seconds == seconds)
179 new_seconds = ASN1_INTEGER_dup(seconds);
180 if (new_seconds == NULL) {
181 TSerr(TS_F_TS_ACCURACY_SET_SECONDS, ERR_R_MALLOC_FAILURE);
184 ASN1_INTEGER_free(a->seconds);
185 a->seconds = new_seconds;
189 const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a)
194 int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis)
196 ASN1_INTEGER *new_millis = NULL;
198 if (a->millis == millis)
200 if (millis != NULL) {
201 new_millis = ASN1_INTEGER_dup(millis);
202 if (new_millis == NULL) {
203 TSerr(TS_F_TS_ACCURACY_SET_MILLIS, ERR_R_MALLOC_FAILURE);
207 ASN1_INTEGER_free(a->millis);
208 a->millis = new_millis;
212 const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a)
217 int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros)
219 ASN1_INTEGER *new_micros = NULL;
221 if (a->micros == micros)
223 if (micros != NULL) {
224 new_micros = ASN1_INTEGER_dup(micros);
225 if (new_micros == NULL) {
226 TSerr(TS_F_TS_ACCURACY_SET_MICROS, ERR_R_MALLOC_FAILURE);
230 ASN1_INTEGER_free(a->micros);
231 a->micros = new_micros;
235 const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a)
240 int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering)
242 a->ordering = ordering ? 0xFF : 0x00;
246 int TS_TST_INFO_get_ordering(const TS_TST_INFO *a)
248 return a->ordering ? 1 : 0;
251 int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce)
253 ASN1_INTEGER *new_nonce;
255 if (a->nonce == nonce)
257 new_nonce = ASN1_INTEGER_dup(nonce);
258 if (new_nonce == NULL) {
259 TSerr(TS_F_TS_TST_INFO_SET_NONCE, ERR_R_MALLOC_FAILURE);
262 ASN1_INTEGER_free(a->nonce);
263 a->nonce = new_nonce;
267 const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a)
272 int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa)
274 GENERAL_NAME *new_tsa;
278 new_tsa = GENERAL_NAME_dup(tsa);
279 if (new_tsa == NULL) {
280 TSerr(TS_F_TS_TST_INFO_SET_TSA, ERR_R_MALLOC_FAILURE);
283 GENERAL_NAME_free(a->tsa);
288 GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a)
293 STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a)
295 return a->extensions;
298 void TS_TST_INFO_ext_free(TS_TST_INFO *a)
302 sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
303 a->extensions = NULL;
306 int TS_TST_INFO_get_ext_count(TS_TST_INFO *a)
308 return X509v3_get_ext_count(a->extensions);
311 int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos)
313 return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
316 int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, const ASN1_OBJECT *obj, int lastpos)
318 return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
321 int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos)
323 return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
326 X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc)
328 return X509v3_get_ext(a->extensions, loc);
331 X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc)
333 return X509v3_delete_ext(a->extensions, loc);
336 int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc)
338 return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
341 void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx)
343 return X509V3_get_d2i(a->extensions, nid, crit, idx);
346 int TS_STATUS_INFO_set_status(TS_STATUS_INFO *a, int i)
348 return ASN1_INTEGER_set(a->status, i);
351 ASN1_INTEGER *TS_STATUS_INFO_get0_status(TS_STATUS_INFO *a)
356 STACK_OF(ASN1_UTF8STRING) *TS_STATUS_INFO_get0_text(TS_STATUS_INFO *a)
361 ASN1_BIT_STRING *TS_STATUS_INFO_get0_failure_info(TS_STATUS_INFO *a)
363 return a->failure_info;