SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / PrintableString.c
1 /*-
2  * Copyright (c) 2003, 2004, 2006 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #include <asn_internal.h>
7 #include <PrintableString.h>
8
9 /*
10  * ASN.1:1984 (X.409)
11  */
12 static const int _PrintableString_alphabet[256] = {
13  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        /*                  */
14  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        /*                  */
15  1, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 5, 6, 7, 8, 9,        /* .      '() +,-./ */
16 10,11,12,13,14,15,16,17,18,19,20, 0, 0,21, 0,22,        /* 0123456789:  = ? */
17  0,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,        /*  ABCDEFGHIJKLMNO */
18 38,39,40,41,42,43,44,45,46,47,48, 0, 0, 0, 0, 0,        /* PQRSTUVWXYZ      */
19  0,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,        /*  abcdefghijklmno */
20 64,65,66,67,68,69,70,71,72,73,74, 0, 0, 0, 0, 0,        /* pqrstuvwxyz      */
21 };
22 static const int _PrintableString_code2value[74] = {
23 32,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54,
24 55,56,57,58,61,63,65,66,67,68,69,70,71,72,73,74,
25 75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
26 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,
27 113,114,115,116,117,118,119,120,121,122};
28
29 /*
30  * PrintableString basic type description.
31  */
32 static const ber_tlv_tag_t asn_DEF_PrintableString_tags[] = {
33     (ASN_TAG_CLASS_UNIVERSAL | (19 << 2)),  /* [UNIVERSAL 19] IMPLICIT ...*/
34     (ASN_TAG_CLASS_UNIVERSAL | (4 << 2))    /* ... OCTET STRING */
35 };
36 #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
37 static int asn_DEF_PrintableString_v2c(unsigned int value) {
38     return _PrintableString_alphabet[value > 255 ? 0 : value] - 1;
39 }
40 static int asn_DEF_PrintableString_c2v(unsigned int code) {
41     if(code < 74)
42         return _PrintableString_code2value[code];
43     return -1;
44 }
45 static asn_per_constraints_t asn_DEF_PrintableString_per_constraints = {
46     { APC_CONSTRAINED, 4, 4, 0x20, 0x39 },   /* Value */
47     { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 },  /* Size */
48     asn_DEF_PrintableString_v2c,
49     asn_DEF_PrintableString_c2v
50 };
51 #endif  /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
52 asn_TYPE_operation_t asn_OP_PrintableString = {
53     OCTET_STRING_free,
54 #if !defined(ASN_DISABLE_PRINT_SUPPORT)
55     OCTET_STRING_print_utf8,  /* ASCII subset */
56 #else
57     0,
58 #endif  /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
59     OCTET_STRING_compare,
60 #if !defined(ASN_DISABLE_BER_SUPPORT)
61     OCTET_STRING_decode_ber,  /* Implemented in terms of OCTET STRING */
62     OCTET_STRING_encode_der,
63 #else
64     0,
65     0,
66 #endif  /* !defined(ASN_DISABLE_BER_SUPPORT) */
67 #if !defined(ASN_DISABLE_XER_SUPPORT)
68     OCTET_STRING_decode_xer_utf8,
69     OCTET_STRING_encode_xer_utf8,
70 #else
71     0,
72     0,
73 #endif  /* !defined(ASN_DISABLE_XER_SUPPORT) */
74 #if !defined(ASN_DISABLE_JER_SUPPORT)
75     OCTET_STRING_encode_jer_utf8,
76 #else
77     0,
78 #endif  /* !defined(ASN_DISABLE_JER_SUPPORT) */
79 #if !defined(ASN_DISABLE_OER_SUPPORT)
80     OCTET_STRING_decode_oer,
81     OCTET_STRING_encode_oer,
82 #else
83     0,
84     0,
85 #endif  /* !defined(ASN_DISABLE_OER_SUPPORT) */
86 #if !defined(ASN_DISABLE_UPER_SUPPORT)
87     OCTET_STRING_decode_uper,
88     OCTET_STRING_encode_uper,
89 #else
90     0,
91     0,
92 #endif  /* !defined(ASN_DISABLE_UPER_SUPPORT) */
93 #if !defined(ASN_DISABLE_APER_SUPPORT)
94     OCTET_STRING_decode_aper,
95     OCTET_STRING_encode_aper,
96 #else
97     0,
98     0,
99 #endif  /* !defined(ASN_DISABLE_APER_SUPPORT) */
100 #if !defined(ASN_DISABLE_RFILL_SUPPORT)
101     OCTET_STRING_random_fill,
102 #else
103     0,
104 #endif  /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
105     0  /* Use generic outmost tag fetcher */
106 };
107 asn_TYPE_descriptor_t asn_DEF_PrintableString = {
108     "PrintableString",
109     "PrintableString",
110     &asn_OP_PrintableString,
111     asn_DEF_PrintableString_tags,
112     sizeof(asn_DEF_PrintableString_tags)
113       / sizeof(asn_DEF_PrintableString_tags[0]) - 1,
114     asn_DEF_PrintableString_tags,
115     sizeof(asn_DEF_PrintableString_tags)
116       / sizeof(asn_DEF_PrintableString_tags[0]),
117     {
118 #if !defined(ASN_DISABLE_OER_SUPPORT)
119         0,
120 #endif  /* !defined(ASN_DISABLE_OER_SUPPORT) */
121 #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
122         &asn_DEF_PrintableString_per_constraints,
123 #endif  /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
124         PrintableString_constraint
125     },
126     0, 0,  /* No members */
127     0  /* No specifics */
128 };
129
130 int
131 PrintableString_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
132                            asn_app_constraint_failed_f *ctfailcb,
133                            void *app_key) {
134     const PrintableString_t *st = (const PrintableString_t *)sptr;
135
136         if(st && st->buf) {
137                 uint8_t *buf = st->buf;
138                 uint8_t *end = buf + st->size;
139
140                 /*
141                  * Check the alphabet of the PrintableString.
142                  * ASN.1:1984 (X.409)
143                  */
144                 for(; buf < end; buf++) {
145                         if(!_PrintableString_alphabet[*buf]) {
146                                 ASN__CTFAIL(app_key, td, sptr,
147                                         "%s: value byte %ld (%d) "
148                                         "not in PrintableString alphabet "
149                                         "(%s:%d)",
150                                         td->name,
151                                         (long)((buf - st->buf) + 1),
152                                         *buf,
153                                         __FILE__, __LINE__);
154                                 return -1;
155                         }
156                 }
157         } else {
158                 ASN__CTFAIL(app_key, td, sptr,
159                         "%s: value not given (%s:%d)",
160                         td->name, __FILE__, __LINE__);
161                 return -1;
162         }
163
164         return 0;
165 }