1/*
2 * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10#include <stdio.h>
11#include <openssl/asn1.h>
12#include <openssl/asn1t.h>
13
14/* Declarations for string types */
15
16#define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
17 IMPLEMENT_ASN1_TYPE(sname) \
18 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(sname, sname, sname) \
19sname *sname##_new(void) \
20{ \
21 return ASN1_STRING_type_new(V_##sname); \
22} \
23void sname##_free(sname *x) \
24{ \
25 ASN1_STRING_free(x); \
26}
27
28IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
29IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
30IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
31IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)
32IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTF8STRING)
33IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_PRINTABLESTRING)
34IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_T61STRING)
35IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_IA5STRING)
36IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALSTRING)
37IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTCTIME)
38IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALIZEDTIME)
39IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_VISIBLESTRING)
40IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING)
41IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING)
42
43IMPLEMENT_ASN1_TYPE(ASN1_NULL)
44IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL)
45
46IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
47
48IMPLEMENT_ASN1_TYPE(ASN1_ANY)
49
50/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
51IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE)
52
53IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
54
55/* Multistring types */
56
57IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE)
58IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
59
60IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
61IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
62
63IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING)
64IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
65
66/* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
67IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1)
68IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1)
69IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
70
71/* Special, OCTET STRING with indefinite length constructed support */
72
73IMPLEMENT_ASN1_TYPE_ex(ASN1_OCTET_STRING_NDEF, ASN1_OCTET_STRING, ASN1_TFLG_NDEF)
74
75ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) =
76 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
77ASN1_ITEM_TEMPLATE_END(ASN1_SEQUENCE_ANY)
78
79ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) =
80 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, ASN1_SET_ANY, ASN1_ANY)
81ASN1_ITEM_TEMPLATE_END(ASN1_SET_ANY)
82
83IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
84IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(ASN1_SEQUENCE_ANY, ASN1_SET_ANY, ASN1_SET_ANY)
85