/src/boringssl/crypto/x509/x_attrib.cc
Line | Count | Source |
1 | | // Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // https://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include <openssl/asn1.h> |
16 | | #include <openssl/asn1t.h> |
17 | | #include <openssl/obj.h> |
18 | | #include <openssl/x509.h> |
19 | | |
20 | | #include "internal.h" |
21 | | |
22 | | |
23 | | ASN1_SEQUENCE(X509_ATTRIBUTE) = { |
24 | | ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT), |
25 | | ASN1_SET_OF(X509_ATTRIBUTE, set, ASN1_ANY), |
26 | | } ASN1_SEQUENCE_END(X509_ATTRIBUTE) |
27 | | |
28 | | IMPLEMENT_ASN1_FUNCTIONS_const(X509_ATTRIBUTE) |
29 | | IMPLEMENT_ASN1_DUP_FUNCTION_const(X509_ATTRIBUTE) |
30 | | |
31 | 0 | X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int attrtype, void *value) { |
32 | 0 | ASN1_OBJECT *obj = OBJ_nid2obj(nid); |
33 | 0 | if (obj == nullptr) { |
34 | 0 | return nullptr; |
35 | 0 | } |
36 | | |
37 | 0 | X509_ATTRIBUTE *ret = X509_ATTRIBUTE_new(); |
38 | 0 | ASN1_TYPE *val = ASN1_TYPE_new(); |
39 | 0 | if (ret == nullptr || val == nullptr) { |
40 | 0 | goto err; |
41 | 0 | } |
42 | | |
43 | 0 | ret->object = obj; |
44 | 0 | if (!sk_ASN1_TYPE_push(ret->set, val)) { |
45 | 0 | goto err; |
46 | 0 | } |
47 | | |
48 | 0 | ASN1_TYPE_set(val, attrtype, value); |
49 | 0 | return ret; |
50 | | |
51 | 0 | err: |
52 | 0 | X509_ATTRIBUTE_free(ret); |
53 | 0 | ASN1_TYPE_free(val); |
54 | 0 | return nullptr; |
55 | 0 | } |