]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/v3_bcons.c
In OpenSSL builds, declare STACK for datatypes ...
[thirdparty/openssl.git] / crypto / x509 / v3_bcons.c
CommitLineData
0f113f3e 1/*
d2e9e320 2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
9aeaf1b4 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
9aeaf1b4
DSH
8 */
9
10#include <stdio.h>
b39fc560 11#include "internal/cryptlib.h"
ec577822 12#include <openssl/asn1.h>
9d6b1ce6 13#include <openssl/asn1t.h>
ec577822
BM
14#include <openssl/conf.h>
15#include <openssl/x509v3.h>
df2ee0e2 16#include "ext_dat.h"
9aeaf1b4 17
852c2ed2
RS
18DEFINE_STACK_OF(CONF_VALUE)
19
0f113f3e
MC
20static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
21 BASIC_CONSTRAINTS *bcons,
22 STACK_OF(CONF_VALUE)
23 *extlist);
24static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
25 X509V3_CTX *ctx,
26 STACK_OF(CONF_VALUE) *values);
9aeaf1b4 27
560b79cb 28const X509V3_EXT_METHOD v3_bcons = {
0f113f3e
MC
29 NID_basic_constraints, 0,
30 ASN1_ITEM_ref(BASIC_CONSTRAINTS),
31 0, 0, 0, 0,
32 0, 0,
33 (X509V3_EXT_I2V) i2v_BASIC_CONSTRAINTS,
34 (X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,
35 NULL, NULL,
36 NULL
9aeaf1b4
DSH
37};
38
9d6b1ce6 39ASN1_SEQUENCE(BASIC_CONSTRAINTS) = {
0f113f3e
MC
40 ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN),
41 ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER)
d339187b 42} ASN1_SEQUENCE_END(BASIC_CONSTRAINTS)
9aeaf1b4 43
9d6b1ce6 44IMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)
9aeaf1b4 45
ba404b5e 46static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
0f113f3e
MC
47 BASIC_CONSTRAINTS *bcons,
48 STACK_OF(CONF_VALUE)
49 *extlist)
9aeaf1b4 50{
0f113f3e
MC
51 X509V3_add_value_bool("CA", bcons->ca, &extlist);
52 X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
53 return extlist;
9aeaf1b4
DSH
54}
55
6b691a5c 56static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
0f113f3e
MC
57 X509V3_CTX *ctx,
58 STACK_OF(CONF_VALUE) *values)
9aeaf1b4 59{
0f113f3e
MC
60 BASIC_CONSTRAINTS *bcons = NULL;
61 CONF_VALUE *val;
62 int i;
75ebbd9a
RS
63
64 if ((bcons = BASIC_CONSTRAINTS_new()) == NULL) {
0f113f3e
MC
65 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE);
66 return NULL;
67 }
68 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
69 val = sk_CONF_VALUE_value(values, i);
86885c28 70 if (strcmp(val->name, "CA") == 0) {
0f113f3e
MC
71 if (!X509V3_get_value_bool(val, &bcons->ca))
72 goto err;
86885c28 73 } else if (strcmp(val->name, "pathlen") == 0) {
0f113f3e
MC
74 if (!X509V3_get_value_int(val, &bcons->pathlen))
75 goto err;
76 } else {
77 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME);
78 X509V3_conf_err(val);
79 goto err;
80 }
81 }
82 return bcons;
83 err:
84 BASIC_CONSTRAINTS_free(bcons);
85 return NULL;
9aeaf1b4 86}