Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/x509/v3_bitst.c

raw
1 // Written by Dr Stephen N Henson ([email protected]) for the OpenSSL project 1999.
2 // Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
4
5 #include <stdio.h>
6 #include <string.h>
7
8 #include <openssl/conf.h>
9 #include <openssl/err.h>
10 #include <openssl/obj.h>
11 #include <openssl/x509.h>
12
13 #include "internal.h"
14
15
16 static const BIT_STRING_BITNAME ns_cert_type_table[] = {
17 {0, "SSL Client", "client"},
18 {1, "SSL Server", "server"},
19 {2, "S/MIME", "email"},
20 {3, "Object Signing", "objsign"},
21 {4, "Unused", "reserved"},
22 {5, "SSL CA", "sslCA"},
23 {6, "S/MIME CA", "emailCA"},
24 {7, "Object Signing CA", "objCA"},
25 {-1, NULL, NULL}};
26
27 static const BIT_STRING_BITNAME key_usage_type_table[] = {
28 {0, "Digital Signature", "digitalSignature"},
29 {1, "Non Repudiation", "nonRepudiation"},
30 {2, "Key Encipherment", "keyEncipherment"},
31 {3, "Data Encipherment", "dataEncipherment"},
32 {4, "Key Agreement", "keyAgreement"},
33 {5, "Certificate Sign", "keyCertSign"},
34 {6, "CRL Sign", "cRLSign"},
35 {7, "Encipher Only", "encipherOnly"},
36 {8, "Decipher Only", "decipherOnly"},
37 {-1, NULL, NULL}};
38
39 static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(
40 const X509V3_EXT_METHOD *method, void *ext, STACK_OF(CONF_VALUE) *ret) {
41 const ASN1_BIT_STRING *bits = ext;
42 const BIT_STRING_BITNAME *bnam;
43 for (bnam = method->usr_data; bnam->lname; bnam++) {
44 if (ASN1_BIT_STRING_get_bit(bits, bnam->bitnum)) {
45 X509V3_add_value(bnam->lname, NULL, &ret);
46 }
47 }
48 return ret;
49 }
50
51 static void *v2i_ASN1_BIT_STRING(const X509V3_EXT_METHOD *method,
52 const X509V3_CTX *ctx,
53 const STACK_OF(CONF_VALUE) *nval) {
54 ASN1_BIT_STRING *bs;
55 if (!(bs = ASN1_BIT_STRING_new())) {
56 return NULL;
57 }
58 for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
59 const CONF_VALUE *val = sk_CONF_VALUE_value(nval, i);
60 const BIT_STRING_BITNAME *bnam;
61 for (bnam = method->usr_data; bnam->lname; bnam++) {
62 if (!strcmp(bnam->sname, val->name) || !strcmp(bnam->lname, val->name)) {
63 if (!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) {
64 ASN1_BIT_STRING_free(bs);
65 return NULL;
66 }
67 break;
68 }
69 }
70 if (!bnam->lname) {
71 OPENSSL_PUT_ERROR(X509V3, X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
72 X509V3_conf_err(val);
73 ASN1_BIT_STRING_free(bs);
74 return NULL;
75 }
76 }
77 return bs;
78 }
79
80 #define EXT_BITSTRING(nid, table) \
81 { \
82 nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), 0, 0, 0, 0, 0, 0, \
83 i2v_ASN1_BIT_STRING, v2i_ASN1_BIT_STRING, NULL, NULL, (void *)(table) \
84 }
85
86 const X509V3_EXT_METHOD v3_nscert =
87 EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
88 const X509V3_EXT_METHOD v3_key_usage =
89 EXT_BITSTRING(NID_key_usage, key_usage_type_table);