/src/openssl/crypto/x509v3/pcy_lib.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the OpenSSL license (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_int.h" |
15 | | |
16 | | /* accessor functions */ |
17 | | |
18 | | /* X509_POLICY_TREE stuff */ |
19 | | |
20 | | int X509_policy_tree_level_count(const X509_POLICY_TREE *tree) |
21 | 0 | { |
22 | 0 | if (!tree) |
23 | 0 | return 0; |
24 | 0 | return tree->nlevel; |
25 | 0 | } |
26 | | |
27 | | X509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, |
28 | | int i) |
29 | 0 | { |
30 | 0 | if (!tree || (i < 0) || (i >= tree->nlevel)) |
31 | 0 | return NULL; |
32 | 0 | return tree->levels + i; |
33 | 0 | } |
34 | | |
35 | | STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(const |
36 | | X509_POLICY_TREE |
37 | | *tree) |
38 | 0 | { |
39 | 0 | if (!tree) |
40 | 0 | return NULL; |
41 | 0 | return tree->auth_policies; |
42 | 0 | } |
43 | | |
44 | | STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(const |
45 | | X509_POLICY_TREE |
46 | | *tree) |
47 | 0 | { |
48 | 0 | if (!tree) |
49 | 0 | return NULL; |
50 | 0 | if (tree->flags & POLICY_FLAG_ANY_POLICY) |
51 | 0 | return tree->auth_policies; |
52 | 0 | else |
53 | 0 | return tree->user_policies; |
54 | 0 | } |
55 | | |
56 | | /* X509_POLICY_LEVEL stuff */ |
57 | | |
58 | | int X509_policy_level_node_count(X509_POLICY_LEVEL *level) |
59 | 0 | { |
60 | 0 | int n; |
61 | 0 | if (!level) |
62 | 0 | return 0; |
63 | 0 | if (level->anyPolicy) |
64 | 0 | n = 1; |
65 | 0 | else |
66 | 0 | n = 0; |
67 | 0 | if (level->nodes) |
68 | 0 | n += sk_X509_POLICY_NODE_num(level->nodes); |
69 | 0 | return n; |
70 | 0 | } |
71 | | |
72 | | X509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i) |
73 | 0 | { |
74 | 0 | if (!level) |
75 | 0 | return NULL; |
76 | 0 | if (level->anyPolicy) { |
77 | 0 | if (i == 0) |
78 | 0 | return level->anyPolicy; |
79 | 0 | i--; |
80 | 0 | } |
81 | 0 | return sk_X509_POLICY_NODE_value(level->nodes, i); |
82 | 0 | } |
83 | | |
84 | | /* X509_POLICY_NODE stuff */ |
85 | | |
86 | | const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node) |
87 | 0 | { |
88 | 0 | if (!node) |
89 | 0 | return NULL; |
90 | 0 | return node->data->valid_policy; |
91 | 0 | } |
92 | | |
93 | | STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(const |
94 | | X509_POLICY_NODE |
95 | | *node) |
96 | 0 | { |
97 | 0 | if (!node) |
98 | 0 | return NULL; |
99 | 0 | return node->data->qualifier_set; |
100 | 0 | } |
101 | | |
102 | | const X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE |
103 | | *node) |
104 | 0 | { |
105 | 0 | if (!node) |
106 | 0 | return NULL; |
107 | 0 | return node->parent; |
108 | 0 | } |