NativeInteger.c
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2004, 2005, 2006 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 /*
7  * Read the NativeInteger.h for the explanation wrt. differences between
8  * INTEGER and NativeInteger.
9  * Basically, both are decoders and encoders of ASN.1 INTEGER type, but this
10  * implementation deals with the standard (machine-specific) representation
11  * of them instead of using the platform-independent buffer.
12  */
15 
16 /*
17  * NativeInteger basic type description.
18  */
20  (ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
21 };
24 #if !defined(ASN_DISABLE_PRINT_SUPPORT)
26 #else
27  0,
28 #endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
31 #if !defined(ASN_DISABLE_BER_SUPPORT)
34 #else
35  0,
36  0,
37 #endif /* !defined(ASN_DISABLE_BER_SUPPORT) */
38 #if !defined(ASN_DISABLE_XER_SUPPORT)
41 #else
42  0,
43  0,
44 #endif /* !defined(ASN_DISABLE_XER_SUPPORT) */
45 #if !defined(ASN_DISABLE_JER_SUPPORT)
48 #else
49  0,
50  0,
51 #endif /* !defined(ASN_DISABLE_JER_SUPPORT) */
52 #if !defined(ASN_DISABLE_OER_SUPPORT)
53  NativeInteger_decode_oer, /* OER decoder */
54  NativeInteger_encode_oer, /* Canonical OER encoder */
55 #else
56  0,
57  0,
58 #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */
59 #if !defined(ASN_DISABLE_UPER_SUPPORT)
60  NativeInteger_decode_uper, /* Unaligned PER decoder */
61  NativeInteger_encode_uper, /* Unaligned PER encoder */
62 #else
63  0,
64  0,
65 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */
66 #if !defined(ASN_DISABLE_APER_SUPPORT)
67  NativeInteger_decode_aper, /* Aligned PER decoder */
68  NativeInteger_encode_aper, /* Aligned PER encoder */
69 #else
70  0,
71  0,
72 #endif /* !defined(ASN_DISABLE_APER_SUPPORT) */
73 #if !defined(ASN_DISABLE_RFILL_SUPPORT)
75 #else
76  0,
77 #endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
78  0 /* Use generic outmost tag fetcher */
79 };
81  "INTEGER", /* The ASN.1 type is still INTEGER */
82  "INTEGER",
86  asn_DEF_NativeInteger_tags, /* Same as above */
88  {
89 #if !defined(ASN_DISABLE_OER_SUPPORT)
90  0,
91 #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */
92 #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
93  0,
94 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
95 #if !defined(ASN_DISABLE_JER_SUPPORT)
96  0,
97 #endif /* !defined(ASN_DISABLE_JER_SUPPORT) */
99  },
100  0, 0, /* No members */
101  0 /* No specifics */
102 };
103 
104 void
106  enum asn_struct_free_method method) {
107  if(!td || !ptr)
108  return;
109 
110  ASN_DEBUG("Freeing %s as INTEGER (%d, %p, Native)",
111  td->name, method, ptr);
112 
113  switch(method) {
115  FREEMEM(ptr);
116  break;
118  break;
120  memset(ptr, 0, sizeof(long));
121  break;
122  }
123 }
124 
125 int
126 NativeInteger_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr) {
127  (void)td;
128 
129  if(aptr && bptr) {
130  const asn_INTEGER_specifics_t *specs =
131  (const asn_INTEGER_specifics_t *)td->specifics;
132  if(specs && specs->field_unsigned) {
133  const unsigned long *a = aptr;
134  const unsigned long *b = bptr;
135  if(*a < *b) {
136  return -1;
137  } else if(*a > *b) {
138  return 1;
139  } else {
140  return 0;
141  }
142  } else {
143  const long *a = aptr;
144  const long *b = bptr;
145  if(*a < *b) {
146  return -1;
147  } else if(*a > *b) {
148  return 1;
149  } else {
150  return 0;
151  }
152  }
153  } else if(!aptr) {
154  return -1;
155  } else {
156  return 1;
157  }
158 }
159 
160 int
161 NativeInteger_copy(const asn_TYPE_descriptor_t *td, void **aptr, const void *bptr) {
162  unsigned long *a = *aptr;
163  const unsigned long *b = bptr;
164 
165  (void)td;
166 
167  /* Check if source has data */
168  if(!b) {
169  /* Clear destination */
170  if(a) {
171  FREEMEM(a);
172  *aptr = 0;
173  }
174  return 0;
175  }
176 
177  if(!a) {
178  a = *aptr = MALLOC(sizeof(*a));
179  if(!a) return -1;
180  }
181 
182  *a = *b;
183 
184  return 0;
185 }
NativeInteger_decode_oer
oer_type_decoder_f NativeInteger_decode_oer
Definition: NativeInteger.h:52
asn_TYPE_operation_s
Definition: constr_TYPE.h:184
ASFM_FREE_UNDERLYING
@ ASFM_FREE_UNDERLYING
Definition: constr_TYPE.h:92
ber_tlv_tag_t
unsigned ber_tlv_tag_t
Definition: ber_tlv_tag.h:18
NativeInteger_decode_ber
ber_type_decoder_f NativeInteger_decode_ber
Definition: NativeInteger.h:37
ASN_TAG_CLASS_UNIVERSAL
@ ASN_TAG_CLASS_UNIVERSAL
Definition: ber_tlv_tag.h:13
asn_TYPE_descriptor_s::name
const char * name
Definition: constr_TYPE.h:225
asn_DEF_NativeInteger
asn_TYPE_descriptor_t asn_DEF_NativeInteger
Definition: NativeInteger.c:80
ASFM_FREE_UNDERLYING_AND_RESET
@ ASFM_FREE_UNDERLYING_AND_RESET
Definition: constr_TYPE.h:93
ASFM_FREE_EVERYTHING
@ ASFM_FREE_EVERYTHING
Definition: constr_TYPE.h:91
NativeInteger_random_fill
asn_random_fill_f NativeInteger_random_fill
Definition: NativeInteger.h:66
NativeInteger_print
asn_struct_print_f NativeInteger_print
Definition: NativeInteger.h:28
NativeInteger_free
void NativeInteger_free(const asn_TYPE_descriptor_t *td, void *ptr, enum asn_struct_free_method method)
Definition: NativeInteger.c:105
asn_OP_NativeInteger
asn_TYPE_operation_t asn_OP_NativeInteger
Definition: NativeInteger.c:22
NativeInteger_encode_xer
xer_type_encoder_f NativeInteger_encode_xer
Definition: NativeInteger.h:43
FREEMEM
#define FREEMEM(ptr)
Definition: asn_internal.h:40
asn_DEF_NativeInteger_tags
static const ber_tlv_tag_t asn_DEF_NativeInteger_tags[]
Definition: NativeInteger.c:19
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
NativeInteger_copy
int NativeInteger_copy(const asn_TYPE_descriptor_t *td, void **aptr, const void *bptr)
Definition: NativeInteger.c:161
asn_TYPE_descriptor_s::specifics
const void * specifics
Definition: constr_TYPE.h:259
NativeInteger_decode_jer
jer_type_decoder_f NativeInteger_decode_jer
Definition: NativeInteger.h:47
asn_INTEGER_specifics_s
Definition: INTEGER.h:28
asn_generic_no_constraint
asn_constr_check_f asn_generic_no_constraint
Definition: constraints.h:51
asn_struct_free_method
asn_struct_free_method
Definition: constr_TYPE.h:90
NativeInteger_decode_xer
xer_type_decoder_f NativeInteger_decode_xer
Definition: NativeInteger.h:42
NativeInteger_compare
int NativeInteger_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr)
Definition: NativeInteger.c:126
NativeInteger_encode_der
der_type_encoder_f NativeInteger_encode_der
Definition: NativeInteger.h:38
MALLOC
#define MALLOC(size)
Definition: asn_internal.h:38
NativeInteger_encode_jer
jer_type_encoder_f NativeInteger_encode_jer
Definition: NativeInteger.h:48
asn_internal.h
NativeInteger_decode_aper
per_type_decoder_f NativeInteger_decode_aper
Definition: NativeInteger.h:61
NativeInteger_encode_oer
oer_type_encoder_f NativeInteger_encode_oer
Definition: NativeInteger.h:53
NativeInteger_encode_aper
per_type_encoder_f NativeInteger_encode_aper
Definition: NativeInteger.h:62
NativeInteger_encode_uper
per_type_encoder_f NativeInteger_encode_uper
Definition: NativeInteger.h:58
asn_INTEGER_specifics_s::field_unsigned
int field_unsigned
Definition: INTEGER.h:35
NativeInteger.h
NativeInteger_decode_uper
per_type_decoder_f NativeInteger_decode_uper
Definition: NativeInteger.h:57


etsi_its_denm_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:23:48