]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/ts/ts_req_utils.c
In OpenSSL builds, declare STACK for datatypes ...
[thirdparty/openssl.git] / crypto / ts / ts_req_utils.c
CommitLineData
0f113f3e 1/*
4f22f405 2 * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
c7235be6 3 *
a1b4409d 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
4f22f405
RS
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
c7235be6
UM
8 */
9
10#include <stdio.h>
b39fc560 11#include "internal/cryptlib.h"
c7235be6
UM
12#include <openssl/objects.h>
13#include <openssl/x509v3.h>
14#include <openssl/ts.h>
706457b7 15#include "ts_local.h"
c7235be6 16
852c2ed2
RS
17DEFINE_STACK_OF(X509_EXTENSION)
18
c7235be6 19int TS_REQ_set_version(TS_REQ *a, long version)
0f113f3e
MC
20{
21 return ASN1_INTEGER_set(a->version, version);
22}
c7235be6 23
6c73d011 24long TS_REQ_get_version(const TS_REQ *a)
0f113f3e
MC
25{
26 return ASN1_INTEGER_get(a->version);
27}
c7235be6
UM
28
29int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint)
0f113f3e
MC
30{
31 TS_MSG_IMPRINT *new_msg_imprint;
32
33 if (a->msg_imprint == msg_imprint)
34 return 1;
35 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
36 if (new_msg_imprint == NULL) {
37 TSerr(TS_F_TS_REQ_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
38 return 0;
39 }
40 TS_MSG_IMPRINT_free(a->msg_imprint);
41 a->msg_imprint = new_msg_imprint;
42 return 1;
43}
c7235be6
UM
44
45TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a)
0f113f3e
MC
46{
47 return a->msg_imprint;
48}
c7235be6
UM
49
50int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg)
0f113f3e
MC
51{
52 X509_ALGOR *new_alg;
53
54 if (a->hash_algo == alg)
55 return 1;
56 new_alg = X509_ALGOR_dup(alg);
57 if (new_alg == NULL) {
58 TSerr(TS_F_TS_MSG_IMPRINT_SET_ALGO, ERR_R_MALLOC_FAILURE);
59 return 0;
60 }
61 X509_ALGOR_free(a->hash_algo);
62 a->hash_algo = new_alg;
63 return 1;
64}
c7235be6
UM
65
66X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a)
0f113f3e
MC
67{
68 return a->hash_algo;
69}
c7235be6
UM
70
71int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len)
0f113f3e
MC
72{
73 return ASN1_OCTET_STRING_set(a->hashed_msg, d, len);
74}
c7235be6
UM
75
76ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a)
0f113f3e
MC
77{
78 return a->hashed_msg;
79}
c7235be6 80
c47ba4e9 81int TS_REQ_set_policy_id(TS_REQ *a, const ASN1_OBJECT *policy)
0f113f3e
MC
82{
83 ASN1_OBJECT *new_policy;
84
85 if (a->policy_id == policy)
86 return 1;
87 new_policy = OBJ_dup(policy);
88 if (new_policy == NULL) {
89 TSerr(TS_F_TS_REQ_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
90 return 0;
91 }
92 ASN1_OBJECT_free(a->policy_id);
93 a->policy_id = new_policy;
94 return 1;
95}
c7235be6
UM
96
97ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a)
0f113f3e
MC
98{
99 return a->policy_id;
100}
c7235be6 101
6c73d011 102int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce)
0f113f3e
MC
103{
104 ASN1_INTEGER *new_nonce;
105
106 if (a->nonce == nonce)
107 return 1;
108 new_nonce = ASN1_INTEGER_dup(nonce);
109 if (new_nonce == NULL) {
110 TSerr(TS_F_TS_REQ_SET_NONCE, ERR_R_MALLOC_FAILURE);
111 return 0;
112 }
113 ASN1_INTEGER_free(a->nonce);
114 a->nonce = new_nonce;
115 return 1;
116}
c7235be6 117
6c73d011 118const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a)
0f113f3e
MC
119{
120 return a->nonce;
121}
c7235be6
UM
122
123int TS_REQ_set_cert_req(TS_REQ *a, int cert_req)
0f113f3e
MC
124{
125 a->cert_req = cert_req ? 0xFF : 0x00;
126 return 1;
127}
c7235be6 128
6c73d011 129int TS_REQ_get_cert_req(const TS_REQ *a)
0f113f3e
MC
130{
131 return a->cert_req ? 1 : 0;
132}
c7235be6
UM
133
134STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a)
0f113f3e
MC
135{
136 return a->extensions;
137}
c7235be6
UM
138
139void TS_REQ_ext_free(TS_REQ *a)
0f113f3e
MC
140{
141 if (!a)
142 return;
143 sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
144 a->extensions = NULL;
145}
c7235be6
UM
146
147int TS_REQ_get_ext_count(TS_REQ *a)
0f113f3e
MC
148{
149 return X509v3_get_ext_count(a->extensions);
150}
c7235be6
UM
151
152int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos)
0f113f3e
MC
153{
154 return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
155}
c7235be6 156
c47ba4e9 157int TS_REQ_get_ext_by_OBJ(TS_REQ *a, const ASN1_OBJECT *obj, int lastpos)
0f113f3e
MC
158{
159 return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
160}
c7235be6
UM
161
162int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos)
0f113f3e
MC
163{
164 return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
165}
c7235be6
UM
166
167X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc)
0f113f3e
MC
168{
169 return X509v3_get_ext(a->extensions, loc);
170}
c7235be6
UM
171
172X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc)
0f113f3e
MC
173{
174 return X509v3_delete_ext(a->extensions, loc);
175}
c7235be6
UM
176
177int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc)
0f113f3e
MC
178{
179 return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
180}
c7235be6
UM
181
182void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx)
0f113f3e
MC
183{
184 return X509V3_get_d2i(a->extensions, nid, crit, idx);
185}