/src/boringssl/crypto/x509/v3_ia5.cc
Line | Count | Source |
1 | | // Copyright 1999-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 <stdio.h> |
16 | | #include <string.h> |
17 | | |
18 | | #include <openssl/asn1.h> |
19 | | #include <openssl/conf.h> |
20 | | #include <openssl/err.h> |
21 | | #include <openssl/mem.h> |
22 | | #include <openssl/obj.h> |
23 | | #include <openssl/x509.h> |
24 | | |
25 | | #include "../internal.h" |
26 | | #include "internal.h" |
27 | | |
28 | | |
29 | 320 | static char *i2s_ASN1_IA5STRING(const X509V3_EXT_METHOD *method, void *ext) { |
30 | 320 | const ASN1_IA5STRING *ia5 = reinterpret_cast<const ASN1_IA5STRING *>(ext); |
31 | 320 | char *tmp; |
32 | 320 | if (!ia5 || !ia5->length) { |
33 | 15 | return nullptr; |
34 | 15 | } |
35 | 305 | if (!(tmp = reinterpret_cast<char *>(OPENSSL_malloc(ia5->length + 1)))) { |
36 | 0 | return nullptr; |
37 | 0 | } |
38 | 305 | OPENSSL_memcpy(tmp, ia5->data, ia5->length); |
39 | 305 | tmp[ia5->length] = 0; |
40 | 305 | return tmp; |
41 | 305 | } |
42 | | |
43 | | static void *s2i_ASN1_IA5STRING(const X509V3_EXT_METHOD *method, |
44 | 74 | const X509V3_CTX *ctx, const char *str) { |
45 | 74 | ASN1_IA5STRING *ia5; |
46 | 74 | if (!str) { |
47 | 0 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_ARGUMENT); |
48 | 0 | return nullptr; |
49 | 0 | } |
50 | 74 | if (!(ia5 = ASN1_IA5STRING_new())) { |
51 | 0 | goto err; |
52 | 0 | } |
53 | 74 | if (!ASN1_STRING_set(ia5, str, strlen(str))) { |
54 | 0 | ASN1_IA5STRING_free(ia5); |
55 | 0 | goto err; |
56 | 0 | } |
57 | 74 | return ia5; |
58 | 0 | err: |
59 | 0 | return nullptr; |
60 | 74 | } |
61 | | |
62 | | #define EXT_IA5STRING(nid) \ |
63 | | { \ |
64 | | nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), 0, 0, 0, 0, i2s_ASN1_IA5STRING, \ |
65 | | s2i_ASN1_IA5STRING, 0, 0, 0, 0, nullptr \ |
66 | | } |
67 | | |
68 | | const X509V3_EXT_METHOD v3_netscape_base_url = |
69 | | EXT_IA5STRING(NID_netscape_base_url); |
70 | | const X509V3_EXT_METHOD v3_netscape_revocation_url = |
71 | | EXT_IA5STRING(NID_netscape_revocation_url); |
72 | | const X509V3_EXT_METHOD v3_netscape_ca_revocation_url = |
73 | | EXT_IA5STRING(NID_netscape_ca_revocation_url); |
74 | | const X509V3_EXT_METHOD v3_netscape_renewal_url = |
75 | | EXT_IA5STRING(NID_netscape_renewal_url); |
76 | | const X509V3_EXT_METHOD v3_netscape_ca_policy_url = |
77 | | EXT_IA5STRING(NID_netscape_ca_policy_url); |
78 | | const X509V3_EXT_METHOD v3_netscape_ssl_server_name = |
79 | | EXT_IA5STRING(NID_netscape_ssl_server_name); |
80 | | const X509V3_EXT_METHOD v3_netscape_comment = |
81 | | EXT_IA5STRING(NID_netscape_comment); |