/src/open5gs/lib/asn1c/common/NativeEnumerated.c
Line | Count | Source |
1 | | /*- |
2 | | * Copyright (c) 2004, 2007 Lev Walkin <vlm@lionet.info>. All rights reserved. |
3 | | * Redistribution and modifications are permitted subject to BSD license. |
4 | | */ |
5 | | /* |
6 | | * Read the NativeInteger.h for the explanation wrt. differences between |
7 | | * INTEGER and NativeInteger. |
8 | | * Basically, both are decoders and encoders of ASN.1 INTEGER type, but this |
9 | | * implementation deals with the standard (machine-specific) representation |
10 | | * of them instead of using the platform-independent buffer. |
11 | | */ |
12 | | #include <asn_internal.h> |
13 | | #include <NativeEnumerated.h> |
14 | | |
15 | | /* |
16 | | * NativeEnumerated basic type description. |
17 | | */ |
18 | | static const ber_tlv_tag_t asn_DEF_NativeEnumerated_tags[] = { |
19 | | (ASN_TAG_CLASS_UNIVERSAL | (10 << 2)) |
20 | | }; |
21 | | asn_TYPE_operation_t asn_OP_NativeEnumerated = { |
22 | | .kind = ASN_KIND_PRIMITIVE, |
23 | | NativeInteger_free, |
24 | | #if !defined(ASN_DISABLE_PRINT_SUPPORT) |
25 | | NativeInteger_print, |
26 | | #else |
27 | | 0, |
28 | | #endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */ |
29 | | NativeInteger_compare, |
30 | | NativeInteger_copy, |
31 | | #if !defined(ASN_DISABLE_BER_SUPPORT) |
32 | | NativeEnumerated_decode_ber, |
33 | | NativeEnumerated_encode_der, |
34 | | #else |
35 | | 0, |
36 | | 0, |
37 | | #endif /* !defined(ASN_DISABLE_BER_SUPPORT) */ |
38 | | #if !defined(ASN_DISABLE_XER_SUPPORT) |
39 | | NativeEnumerated_decode_xer, |
40 | | NativeEnumerated_encode_xer, |
41 | | #else |
42 | | 0, |
43 | | 0, |
44 | | #endif /* !defined(ASN_DISABLE_XER_SUPPORT) */ |
45 | | #if !defined(ASN_DISABLE_JER_SUPPORT) |
46 | | NativeEnumerated_decode_jer, |
47 | | NativeEnumerated_encode_jer, |
48 | | #else |
49 | | 0, |
50 | | 0, |
51 | | #endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ |
52 | | #if !defined(ASN_DISABLE_OER_SUPPORT) |
53 | | NativeEnumerated_decode_oer, |
54 | | NativeEnumerated_encode_oer, |
55 | | #else |
56 | | 0, |
57 | | 0, |
58 | | #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ |
59 | | #if !defined(ASN_DISABLE_UPER_SUPPORT) |
60 | | NativeEnumerated_decode_uper, |
61 | | NativeEnumerated_encode_uper, |
62 | | #else |
63 | | 0, |
64 | | 0, |
65 | | #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */ |
66 | | #if !defined(ASN_DISABLE_APER_SUPPORT) |
67 | | NativeEnumerated_decode_aper, |
68 | | NativeEnumerated_encode_aper, |
69 | | #else |
70 | | 0, |
71 | | 0, |
72 | | #endif /* !defined(ASN_DISABLE_APER_SUPPORT) */ |
73 | | #if !defined(ASN_DISABLE_RFILL_SUPPORT) |
74 | | NativeEnumerated_random_fill, |
75 | | #else |
76 | | 0, |
77 | | #endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */ |
78 | | 0 /* Use generic outmost tag fetcher */, |
79 | | #if !defined(ASN_DISABLE_CBOR_SUPPORT) |
80 | | NativeEnumerated_decode_cbor, |
81 | | NativeEnumerated_encode_cbor, |
82 | | #else |
83 | | 0, |
84 | | 0, |
85 | | #endif /* !defined(ASN_DISABLE_CBOR_SUPPORT) */ |
86 | | }; |
87 | | |
88 | | int |
89 | | NativeEnumerated_constraint(const asn_TYPE_descriptor_t *td, const void *sptr, |
90 | 0 | asn_app_constraint_failed_f *ctfailcb, void *app_key) { |
91 | 0 | const asn_INTEGER_specifics_t *specs = |
92 | 0 | (const asn_INTEGER_specifics_t *)td->specifics; |
93 | 0 | const long *native = (const long *)sptr; |
94 | 0 | const asn_INTEGER_enum_map_t *el; |
95 | 0 | el = INTEGER_map_value2enum(specs, *native); |
96 | 0 | if(el) { |
97 | 0 | return 0; |
98 | 0 | } else { |
99 | 0 | ASN_DEBUG("No element corresponds to the value %ld", *native); |
100 | 0 | return -1; |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | | asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = { |
105 | | "ENUMERATED", /* The ASN.1 type is still ENUMERATED */ |
106 | | "ENUMERATED", |
107 | | &asn_OP_NativeEnumerated, |
108 | | asn_DEF_NativeEnumerated_tags, |
109 | | sizeof(asn_DEF_NativeEnumerated_tags) / sizeof(asn_DEF_NativeEnumerated_tags[0]), |
110 | | asn_DEF_NativeEnumerated_tags, /* Same as above */ |
111 | | sizeof(asn_DEF_NativeEnumerated_tags) / sizeof(asn_DEF_NativeEnumerated_tags[0]), |
112 | | { |
113 | | #if !defined(ASN_DISABLE_OER_SUPPORT) |
114 | | 0, |
115 | | #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */ |
116 | | #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) |
117 | | 0, |
118 | | #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ |
119 | | #if !defined(ASN_DISABLE_JER_SUPPORT) |
120 | | 0, |
121 | | #endif /* !defined(ASN_DISABLE_JER_SUPPORT) */ |
122 | | NativeEnumerated_constraint |
123 | | }, |
124 | | 0, 0, /* No members */ |
125 | | 0 /* No specifics */ |
126 | | }; |
127 | | |
128 | | #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) |
129 | | int |
130 | 0 | NativeEnumerated__compar_value2enum(const void *ap, const void *bp) { |
131 | 0 | const asn_INTEGER_enum_map_t *a = ap; |
132 | 0 | const asn_INTEGER_enum_map_t *b = bp; |
133 | 0 | if(a->nat_value == b->nat_value) |
134 | 0 | return 0; |
135 | 0 | if(a->nat_value < b->nat_value) |
136 | 0 | return -1; |
137 | 0 | return 1; |
138 | 0 | } |
139 | | #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */ |