]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/pcy_data.c
Reorganize local header files
[thirdparty/openssl.git] / crypto / x509 / pcy_data.c
CommitLineData
0f113f3e 1/*
6ec5fce2 2 * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved.
4acc3e90 3 *
4286ca47 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
d2e9e320
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
4acc3e90
DSH
8 */
9
b39fc560 10#include "internal/cryptlib.h"
4acc3e90
DSH
11#include <openssl/x509.h>
12#include <openssl/x509v3.h>
13
706457b7 14#include "pcy_local.h"
4acc3e90
DSH
15
16/* Policy Node routines */
17
18void policy_data_free(X509_POLICY_DATA *data)
0f113f3e 19{
3f23390b 20 if (data == NULL)
25aaa98a 21 return;
0f113f3e
MC
22 ASN1_OBJECT_free(data->valid_policy);
23 /* Don't free qualifiers if shared */
24 if (!(data->flags & POLICY_DATA_FLAG_SHARED_QUALIFIERS))
25 sk_POLICYQUALINFO_pop_free(data->qualifier_set, POLICYQUALINFO_free);
26 sk_ASN1_OBJECT_pop_free(data->expected_policy_set, ASN1_OBJECT_free);
27 OPENSSL_free(data);
28}
4acc3e90 29
0f113f3e 30/*
0ad69cd6 31 * Create a data based on an existing policy. If 'id' is NULL use the OID in
0f113f3e 32 * the policy, otherwise use 'id'. This behaviour covers the two types of
0ad69cd6 33 * data in RFC3280: data with from a CertificatePolicies extension and
0f113f3e
MC
34 * additional data with just the qualifiers of anyPolicy and ID from another
35 * source.
4acc3e90
DSH
36 */
37
002e66c0 38X509_POLICY_DATA *policy_data_new(POLICYINFO *policy,
0f113f3e
MC
39 const ASN1_OBJECT *cid, int crit)
40{
41 X509_POLICY_DATA *ret;
42 ASN1_OBJECT *id;
7fcdbd83 43
3f23390b 44 if (policy == NULL && cid == NULL)
0f113f3e
MC
45 return NULL;
46 if (cid) {
47 id = OBJ_dup(cid);
3f23390b 48 if (id == NULL)
0f113f3e
MC
49 return NULL;
50 } else
51 id = NULL;
64b25758 52 ret = OPENSSL_zalloc(sizeof(*ret));
7fcdbd83
F
53 if (ret == NULL) {
54 X509V3err(X509V3_F_POLICY_DATA_NEW, ERR_R_MALLOC_FAILURE);
0f113f3e 55 return NULL;
7fcdbd83 56 }
0f113f3e 57 ret->expected_policy_set = sk_ASN1_OBJECT_new_null();
90945fa3 58 if (ret->expected_policy_set == NULL) {
0f113f3e 59 OPENSSL_free(ret);
0dfb9398 60 ASN1_OBJECT_free(id);
7fcdbd83 61 X509V3err(X509V3_F_POLICY_DATA_NEW, ERR_R_MALLOC_FAILURE);
0f113f3e
MC
62 return NULL;
63 }
4acc3e90 64
0f113f3e
MC
65 if (crit)
66 ret->flags = POLICY_DATA_FLAG_CRITICAL;
4acc3e90 67
0f113f3e
MC
68 if (id)
69 ret->valid_policy = id;
70 else {
71 ret->valid_policy = policy->policyid;
72 policy->policyid = NULL;
73 }
4acc3e90 74
0f113f3e
MC
75 if (policy) {
76 ret->qualifier_set = policy->qualifiers;
77 policy->qualifiers = NULL;
64b25758 78 }
4acc3e90 79
0f113f3e
MC
80 return ret;
81}