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/x509v3.h>
14 #include <openssl/ts.h>
17 DEFINE_STACK_OF(X509_EXTENSION)
19 int TS_REQ_set_version(TS_REQ *a, long version)
21 return ASN1_INTEGER_set(a->version, version);
24 long TS_REQ_get_version(const TS_REQ *a)
26 return ASN1_INTEGER_get(a->version);
29 int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint)
31 TS_MSG_IMPRINT *new_msg_imprint;
33 if (a->msg_imprint == msg_imprint)
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);
40 TS_MSG_IMPRINT_free(a->msg_imprint);
41 a->msg_imprint = new_msg_imprint;
45 TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a)
47 return a->msg_imprint;
50 int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg)
54 if (a->hash_algo == alg)
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);
61 X509_ALGOR_free(a->hash_algo);
62 a->hash_algo = new_alg;
66 X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a)
71 int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len)
73 return ASN1_OCTET_STRING_set(a->hashed_msg, d, len);
76 ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a)
81 int TS_REQ_set_policy_id(TS_REQ *a, const ASN1_OBJECT *policy)
83 ASN1_OBJECT *new_policy;
85 if (a->policy_id == policy)
87 new_policy = OBJ_dup(policy);
88 if (new_policy == NULL) {
89 TSerr(TS_F_TS_REQ_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
92 ASN1_OBJECT_free(a->policy_id);
93 a->policy_id = new_policy;
97 ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a)
102 int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce)
104 ASN1_INTEGER *new_nonce;
106 if (a->nonce == nonce)
108 new_nonce = ASN1_INTEGER_dup(nonce);
109 if (new_nonce == NULL) {
110 TSerr(TS_F_TS_REQ_SET_NONCE, ERR_R_MALLOC_FAILURE);
113 ASN1_INTEGER_free(a->nonce);
114 a->nonce = new_nonce;
118 const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a)
123 int TS_REQ_set_cert_req(TS_REQ *a, int cert_req)
125 a->cert_req = cert_req ? 0xFF : 0x00;
129 int TS_REQ_get_cert_req(const TS_REQ *a)
131 return a->cert_req ? 1 : 0;
134 STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a)
136 return a->extensions;
139 void TS_REQ_ext_free(TS_REQ *a)
143 sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
144 a->extensions = NULL;
147 int TS_REQ_get_ext_count(TS_REQ *a)
149 return X509v3_get_ext_count(a->extensions);
152 int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos)
154 return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
157 int TS_REQ_get_ext_by_OBJ(TS_REQ *a, const ASN1_OBJECT *obj, int lastpos)
159 return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
162 int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos)
164 return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
167 X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc)
169 return X509v3_get_ext(a->extensions, loc);
172 X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc)
174 return X509v3_delete_ext(a->extensions, loc);
177 int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc)
179 return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
182 void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx)
184 return X509V3_get_d2i(a->extensions, nid, crit, idx);