]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/pcy_lib.c
Update copyright year
[thirdparty/openssl.git] / crypto / x509 / pcy_lib.c
CommitLineData
0f113f3e 1/*
33388b44 2 * Copyright 2004-2020 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 15
852c2ed2
RS
16DEFINE_STACK_OF(X509_POLICY_NODE)
17
4acc3e90
DSH
18/* accessor functions */
19
20/* X509_POLICY_TREE stuff */
21
22int X509_policy_tree_level_count(const X509_POLICY_TREE *tree)
0f113f3e
MC
23{
24 if (!tree)
25 return 0;
26 return tree->nlevel;
27}
28
29X509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree,
30 int i)
31{
32 if (!tree || (i < 0) || (i >= tree->nlevel))
33 return NULL;
34 return tree->levels + i;
35}
36
37STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(const
38 X509_POLICY_TREE
39 *tree)
40{
41 if (!tree)
42 return NULL;
43 return tree->auth_policies;
44}
45
46STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(const
47 X509_POLICY_TREE
48 *tree)
49{
50 if (!tree)
51 return NULL;
52 if (tree->flags & POLICY_FLAG_ANY_POLICY)
53 return tree->auth_policies;
54 else
55 return tree->user_policies;
56}
4acc3e90
DSH
57
58/* X509_POLICY_LEVEL stuff */
59
60int X509_policy_level_node_count(X509_POLICY_LEVEL *level)
0f113f3e
MC
61{
62 int n;
63 if (!level)
64 return 0;
65 if (level->anyPolicy)
66 n = 1;
67 else
68 n = 0;
69 if (level->nodes)
70 n += sk_X509_POLICY_NODE_num(level->nodes);
71 return n;
72}
4acc3e90 73
8cc86b81 74X509_POLICY_NODE *X509_policy_level_get0_node(const X509_POLICY_LEVEL *level, int i)
0f113f3e
MC
75{
76 if (!level)
77 return NULL;
78 if (level->anyPolicy) {
79 if (i == 0)
80 return level->anyPolicy;
81 i--;
82 }
83 return sk_X509_POLICY_NODE_value(level->nodes, i);
84}
4acc3e90
DSH
85
86/* X509_POLICY_NODE stuff */
87
88const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node)
0f113f3e
MC
89{
90 if (!node)
91 return NULL;
92 return node->data->valid_policy;
93}
4acc3e90 94
0f113f3e
MC
95STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(const
96 X509_POLICY_NODE
97 *node)
98{
99 if (!node)
100 return NULL;
101 return node->data->qualifier_set;
102}
103
104const X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE
105 *node)
106{
107 if (!node)
108 return NULL;
109 return node->parent;
110}