/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 | | using namespace bssl; |
24 | | |
25 | | BSSL_NAMESPACE_BEGIN |
26 | | |
27 | | ASN1_SEQUENCE(X509_ATTRIBUTE) = { |
28 | | ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT), |
29 | | ASN1_SET_OF(X509_ATTRIBUTE, set, ASN1_ANY), |
30 | | } ASN1_SEQUENCE_END(X509_ATTRIBUTE) |
31 | | |
32 | | BSSL_NAMESPACE_END |
33 | | |
34 | | IMPLEMENT_ASN1_FUNCTIONS_const(X509_ATTRIBUTE) |
35 | | IMPLEMENT_ASN1_DUP_FUNCTION_const(X509_ATTRIBUTE) |
36 | | |
37 | 0 | X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int attrtype, void *value) { |
38 | 0 | ASN1_OBJECT *obj = OBJ_nid2obj(nid); |
39 | 0 | if (obj == nullptr) { |
40 | 0 | return nullptr; |
41 | 0 | } |
42 | | |
43 | 0 | X509_ATTRIBUTE *ret = X509_ATTRIBUTE_new(); |
44 | 0 | ASN1_TYPE *val = ASN1_TYPE_new(); |
45 | 0 | if (ret == nullptr || val == nullptr) { |
46 | 0 | goto err; |
47 | 0 | } |
48 | | |
49 | 0 | ret->object = obj; |
50 | 0 | if (!sk_ASN1_TYPE_push(ret->set, val)) { |
51 | 0 | goto err; |
52 | 0 | } |
53 | | |
54 | 0 | ASN1_TYPE_set(val, attrtype, value); |
55 | 0 | return ret; |
56 | | |
57 | 0 | err: |
58 | 0 | X509_ATTRIBUTE_free(ret); |
59 | 0 | ASN1_TYPE_free(val); |
60 | 0 | return nullptr; |
61 | 0 | } |