1160814Ssimon/* pcy_lib.c */
2296341Sdelphij/*
3296341Sdelphij * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
4296341Sdelphij * 2004.
5160814Ssimon */
6160814Ssimon/* ====================================================================
7160814Ssimon * Copyright (c) 2004 The OpenSSL Project.  All rights reserved.
8160814Ssimon *
9160814Ssimon * Redistribution and use in source and binary forms, with or without
10160814Ssimon * modification, are permitted provided that the following conditions
11160814Ssimon * are met:
12160814Ssimon *
13160814Ssimon * 1. Redistributions of source code must retain the above copyright
14296341Sdelphij *    notice, this list of conditions and the following disclaimer.
15160814Ssimon *
16160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright
17160814Ssimon *    notice, this list of conditions and the following disclaimer in
18160814Ssimon *    the documentation and/or other materials provided with the
19160814Ssimon *    distribution.
20160814Ssimon *
21160814Ssimon * 3. All advertising materials mentioning features or use of this
22160814Ssimon *    software must display the following acknowledgment:
23160814Ssimon *    "This product includes software developed by the OpenSSL Project
24160814Ssimon *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25160814Ssimon *
26160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27160814Ssimon *    endorse or promote products derived from this software without
28160814Ssimon *    prior written permission. For written permission, please contact
29160814Ssimon *    licensing@OpenSSL.org.
30160814Ssimon *
31160814Ssimon * 5. Products derived from this software may not be called "OpenSSL"
32160814Ssimon *    nor may "OpenSSL" appear in their names without prior written
33160814Ssimon *    permission of the OpenSSL Project.
34160814Ssimon *
35160814Ssimon * 6. Redistributions of any form whatsoever must retain the following
36160814Ssimon *    acknowledgment:
37160814Ssimon *    "This product includes software developed by the OpenSSL Project
38160814Ssimon *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39160814Ssimon *
40160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43160814Ssimon * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE.
52160814Ssimon * ====================================================================
53160814Ssimon *
54160814Ssimon * This product includes cryptographic software written by Eric Young
55160814Ssimon * (eay@cryptsoft.com).  This product includes software written by Tim
56160814Ssimon * Hudson (tjh@cryptsoft.com).
57160814Ssimon *
58160814Ssimon */
59160814Ssimon
60160814Ssimon#include "cryptlib.h"
61160814Ssimon#include <openssl/x509.h>
62160814Ssimon#include <openssl/x509v3.h>
63160814Ssimon
64160814Ssimon#include "pcy_int.h"
65160814Ssimon
66160814Ssimon/* accessor functions */
67160814Ssimon
68160814Ssimon/* X509_POLICY_TREE stuff */
69160814Ssimon
70160814Ssimonint X509_policy_tree_level_count(const X509_POLICY_TREE *tree)
71296341Sdelphij{
72296341Sdelphij    if (!tree)
73296341Sdelphij        return 0;
74296341Sdelphij    return tree->nlevel;
75296341Sdelphij}
76160814Ssimon
77296341SdelphijX509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree,
78296341Sdelphij                                               int i)
79296341Sdelphij{
80296341Sdelphij    if (!tree || (i < 0) || (i >= tree->nlevel))
81296341Sdelphij        return NULL;
82296341Sdelphij    return tree->levels + i;
83296341Sdelphij}
84160814Ssimon
85296341SdelphijSTACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(const
86296341Sdelphij                                                           X509_POLICY_TREE
87296341Sdelphij                                                           *tree)
88296341Sdelphij{
89296341Sdelphij    if (!tree)
90296341Sdelphij        return NULL;
91296341Sdelphij    return tree->auth_policies;
92296341Sdelphij}
93160814Ssimon
94296341SdelphijSTACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(const
95296341Sdelphij                                                                X509_POLICY_TREE
96296341Sdelphij                                                                *tree)
97296341Sdelphij{
98296341Sdelphij    if (!tree)
99296341Sdelphij        return NULL;
100296341Sdelphij    if (tree->flags & POLICY_FLAG_ANY_POLICY)
101296341Sdelphij        return tree->auth_policies;
102296341Sdelphij    else
103296341Sdelphij        return tree->user_policies;
104296341Sdelphij}
105160814Ssimon
106160814Ssimon/* X509_POLICY_LEVEL stuff */
107160814Ssimon
108160814Ssimonint X509_policy_level_node_count(X509_POLICY_LEVEL *level)
109296341Sdelphij{
110296341Sdelphij    int n;
111296341Sdelphij    if (!level)
112296341Sdelphij        return 0;
113296341Sdelphij    if (level->anyPolicy)
114296341Sdelphij        n = 1;
115296341Sdelphij    else
116296341Sdelphij        n = 0;
117296341Sdelphij    if (level->nodes)
118296341Sdelphij        n += sk_X509_POLICY_NODE_num(level->nodes);
119296341Sdelphij    return n;
120296341Sdelphij}
121160814Ssimon
122160814SsimonX509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i)
123296341Sdelphij{
124296341Sdelphij    if (!level)
125296341Sdelphij        return NULL;
126296341Sdelphij    if (level->anyPolicy) {
127296341Sdelphij        if (i == 0)
128296341Sdelphij            return level->anyPolicy;
129296341Sdelphij        i--;
130296341Sdelphij    }
131296341Sdelphij    return sk_X509_POLICY_NODE_value(level->nodes, i);
132296341Sdelphij}
133160814Ssimon
134160814Ssimon/* X509_POLICY_NODE stuff */
135160814Ssimon
136160814Ssimonconst ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node)
137296341Sdelphij{
138296341Sdelphij    if (!node)
139296341Sdelphij        return NULL;
140296341Sdelphij    return node->data->valid_policy;
141296341Sdelphij}
142160814Ssimon
143160814Ssimon#if 0
144160814Ssimonint X509_policy_node_get_critical(const X509_POLICY_NODE *node)
145296341Sdelphij{
146296341Sdelphij    if (node_critical(node))
147296341Sdelphij        return 1;
148296341Sdelphij    return 0;
149296341Sdelphij}
150160814Ssimon#endif
151160814Ssimon
152296341SdelphijSTACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(const
153296341Sdelphij                                                           X509_POLICY_NODE
154296341Sdelphij                                                           *node)
155296341Sdelphij{
156296341Sdelphij    if (!node)
157296341Sdelphij        return NULL;
158296341Sdelphij    return node->data->qualifier_set;
159296341Sdelphij}
160160814Ssimon
161296341Sdelphijconst X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE
162296341Sdelphij                                                     *node)
163296341Sdelphij{
164296341Sdelphij    if (!node)
165296341Sdelphij        return NULL;
166296341Sdelphij    return node->parent;
167296341Sdelphij}
168