2 * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "internal/cryptlib.h"
12 #include <openssl/asn1.h>
13 #include <openssl/asn1t.h>
14 #include <openssl/conf.h>
15 #include <openssl/x509v3.h>
18 DEFINE_STACK_OF(CONF_VALUE)
20 static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
21 BASIC_CONSTRAINTS *bcons,
24 static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
26 STACK_OF(CONF_VALUE) *values);
28 const X509V3_EXT_METHOD v3_bcons = {
29 NID_basic_constraints, 0,
30 ASN1_ITEM_ref(BASIC_CONSTRAINTS),
33 (X509V3_EXT_I2V) i2v_BASIC_CONSTRAINTS,
34 (X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,
39 ASN1_SEQUENCE(BASIC_CONSTRAINTS) = {
40 ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN),
41 ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER)
42 } ASN1_SEQUENCE_END(BASIC_CONSTRAINTS)
44 IMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)
46 static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
47 BASIC_CONSTRAINTS *bcons,
51 X509V3_add_value_bool("CA", bcons->ca, &extlist);
52 X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
56 static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
58 STACK_OF(CONF_VALUE) *values)
60 BASIC_CONSTRAINTS *bcons = NULL;
64 if ((bcons = BASIC_CONSTRAINTS_new()) == NULL) {
65 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE);
68 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
69 val = sk_CONF_VALUE_value(values, i);
70 if (strcmp(val->name, "CA") == 0) {
71 if (!X509V3_get_value_bool(val, &bcons->ca))
73 } else if (strcmp(val->name, "pathlen") == 0) {
74 if (!X509V3_get_value_int(val, &bcons->pathlen))
77 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME);
84 BASIC_CONSTRAINTS_free(bcons);