| 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 |
/* accessor functions */ |
| 17 |
|
| 18 |
/* X509_POLICY_TREE stuff */ |
| 19 |
|
| 20 |
int X509_policy_tree_level_count(const X509_POLICY_TREE *tree) |
| 21 |
{ |
| 22 |
if (!tree) |
| 23 |
return 0; |
| 24 |
return tree->nlevel; |
| 25 |
} |
| 26 |
|
| 27 |
X509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, |
| 28 |
int i) |
| 29 |
{ |
| 30 |
if (!tree || (i < 0) || (i >= tree->nlevel)) |
| 31 |
return NULL; |
| 32 |
return tree->levels + i; |
| 33 |
} |
| 34 |
|
| 35 |
STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(const X509_POLICY_TREE |
| 36 |
*tree) |
| 37 |
{ |
| 38 |
if (!tree) |
| 39 |
return NULL; |
| 40 |
return tree->auth_policies; |
| 41 |
} |
| 42 |
|
| 43 |
STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(const X509_POLICY_TREE |
| 44 |
*tree) |
| 45 |
{ |
| 46 |
if (!tree) |
| 47 |
return NULL; |
| 48 |
if (tree->flags & POLICY_FLAG_ANY_POLICY) |
| 49 |
return tree->auth_policies; |
| 50 |
else |
| 51 |
return tree->user_policies; |
| 52 |
} |
| 53 |
|
| 54 |
/* X509_POLICY_LEVEL stuff */ |
| 55 |
|
| 56 |
int X509_policy_level_node_count(X509_POLICY_LEVEL *level) |
| 57 |
{ |
| 58 |
int n; |
| 59 |
if (!level) |
| 60 |
return 0; |
| 61 |
if (level->anyPolicy) |
| 62 |
n = 1; |
| 63 |
else |
| 64 |
n = 0; |
| 65 |
if (level->nodes) |
| 66 |
n += sk_X509_POLICY_NODE_num(level->nodes); |
| 67 |
return n; |
| 68 |
} |
| 69 |
|
| 70 |
X509_POLICY_NODE *X509_policy_level_get0_node(const X509_POLICY_LEVEL *level, int i) |
| 71 |
{ |
| 72 |
if (!level) |
| 73 |
return NULL; |
| 74 |
if (level->anyPolicy) { |
| 75 |
if (i == 0) |
| 76 |
return level->anyPolicy; |
| 77 |
i--; |
| 78 |
} |
| 79 |
return sk_X509_POLICY_NODE_value(level->nodes, i); |
| 80 |
} |
| 81 |
|
| 82 |
/* X509_POLICY_NODE stuff */ |
| 83 |
|
| 84 |
const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node) |
| 85 |
{ |
| 86 |
if (!node) |
| 87 |
return NULL; |
| 88 |
return node->data->valid_policy; |
| 89 |
} |
| 90 |
|
| 91 |
STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(const X509_POLICY_NODE |
| 92 |
*node) |
| 93 |
{ |
| 94 |
if (!node) |
| 95 |
return NULL; |
| 96 |
return node->data->qualifier_set; |
| 97 |
} |
| 98 |
|
| 99 |
const X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE |
| 100 |
*node) |
| 101 |
{ |
| 102 |
if (!node) |
| 103 |
return NULL; |
| 104 |
return node->parent; |
| 105 |
} |