CTR, HASH and HMAC DRBGs in provider
[openssl.git] / crypto / x509 / pcy_lib.c
1 /*
2  * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #include "internal/cryptlib.h"
11 #include <openssl/x509.h>
12 #include <openssl/x509v3.h>
13
14 #include "pcy_local.h"
15
16 DEFINE_STACK_OF(X509_POLICY_NODE)
17
18 /* accessor functions */
19
20 /* X509_POLICY_TREE stuff */
21
22 int X509_policy_tree_level_count(const X509_POLICY_TREE *tree)
23 {
24     if (!tree)
25         return 0;
26     return tree->nlevel;
27 }
28
29 X509_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
37 STACK_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
46 STACK_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 }
57
58 /* X509_POLICY_LEVEL stuff */
59
60 int X509_policy_level_node_count(X509_POLICY_LEVEL *level)
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 }
73
74 X509_POLICY_NODE *X509_policy_level_get0_node(const X509_POLICY_LEVEL *level, int i)
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 }
85
86 /* X509_POLICY_NODE stuff */
87
88 const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node)
89 {
90     if (!node)
91         return NULL;
92     return node->data->valid_policy;
93 }
94
95 STACK_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
104 const 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 }