2 * Copyright (c) 2004, 2005, 2006 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
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.
13 #include <asn_internal.h>
14 #include <NativeInteger.h>
17 * NativeInteger basic type description.
19 static const ber_tlv_tag_t asn_DEF_NativeInteger_tags[] = {
20 (ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
22 asn_TYPE_operation_t asn_OP_NativeInteger = {
24 #if !defined(ASN_DISABLE_PRINT_SUPPORT)
28 #endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
29 NativeInteger_compare,
30 #if !defined(ASN_DISABLE_BER_SUPPORT)
31 NativeInteger_decode_ber,
32 NativeInteger_encode_der,
36 #endif /* !defined(ASN_DISABLE_BER_SUPPORT) */
37 #if !defined(ASN_DISABLE_XER_SUPPORT)
38 NativeInteger_decode_xer,
39 NativeInteger_encode_xer,
43 #endif /* !defined(ASN_DISABLE_XER_SUPPORT) */
44 #if !defined(ASN_DISABLE_JER_SUPPORT)
45 NativeInteger_encode_jer,
48 #endif /* !defined(ASN_DISABLE_JER_SUPPORT) */
49 #if !defined(ASN_DISABLE_OER_SUPPORT)
50 NativeInteger_decode_oer, /* OER decoder */
51 NativeInteger_encode_oer, /* Canonical OER encoder */
55 #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */
56 #if !defined(ASN_DISABLE_UPER_SUPPORT)
57 NativeInteger_decode_uper, /* Unaligned PER decoder */
58 NativeInteger_encode_uper, /* Unaligned PER encoder */
62 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */
63 #if !defined(ASN_DISABLE_APER_SUPPORT)
64 NativeInteger_decode_aper, /* Aligned PER decoder */
65 NativeInteger_encode_aper, /* Aligned PER encoder */
69 #endif /* !defined(ASN_DISABLE_APER_SUPPORT) */
70 #if !defined(ASN_DISABLE_RFILL_SUPPORT)
71 NativeInteger_random_fill,
74 #endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
75 0 /* Use generic outmost tag fetcher */
77 asn_TYPE_descriptor_t asn_DEF_NativeInteger = {
78 "INTEGER", /* The ASN.1 type is still INTEGER */
80 &asn_OP_NativeInteger,
81 asn_DEF_NativeInteger_tags,
82 sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]),
83 asn_DEF_NativeInteger_tags, /* Same as above */
84 sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]),
86 #if !defined(ASN_DISABLE_OER_SUPPORT)
88 #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */
89 #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
91 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
92 asn_generic_no_constraint
94 0, 0, /* No members */
99 NativeInteger_free(const asn_TYPE_descriptor_t *td, void *ptr,
100 enum asn_struct_free_method method) {
104 ASN_DEBUG("Freeing %s as INTEGER (%d, %p, Native)",
105 td->name, method, ptr);
108 case ASFM_FREE_EVERYTHING:
111 case ASFM_FREE_UNDERLYING:
113 case ASFM_FREE_UNDERLYING_AND_RESET:
114 memset(ptr, 0, sizeof(long));
120 NativeInteger_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr) {
124 const asn_INTEGER_specifics_t *specs =
125 (const asn_INTEGER_specifics_t *)td->specifics;
126 if(specs && specs->field_unsigned) {
127 const unsigned long *a = aptr;
128 const unsigned long *b = bptr;
137 const long *a = aptr;
138 const long *b = bptr;