| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #include <asn_internal.h> |
| #include <NativeInteger.h> |
|
|
| |
| |
| |
| static const ber_tlv_tag_t asn_DEF_NativeInteger_tags[] = { |
| (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)) |
| }; |
| asn_TYPE_operation_t asn_OP_NativeInteger = { |
| NativeInteger_free, |
| #if !defined(ASN_DISABLE_PRINT_SUPPORT) |
| NativeInteger_print, |
| #else |
| 0, |
| #endif |
| NativeInteger_compare, |
| NativeInteger_copy, |
| #if !defined(ASN_DISABLE_BER_SUPPORT) |
| NativeInteger_decode_ber, |
| NativeInteger_encode_der, |
| #else |
| 0, |
| 0, |
| #endif |
| #if !defined(ASN_DISABLE_XER_SUPPORT) |
| NativeInteger_decode_xer, |
| NativeInteger_encode_xer, |
| #else |
| 0, |
| 0, |
| #endif |
| #if !defined(ASN_DISABLE_JER_SUPPORT) |
| NativeInteger_decode_jer, |
| NativeInteger_encode_jer, |
| #else |
| 0, |
| 0, |
| #endif |
| #if !defined(ASN_DISABLE_OER_SUPPORT) |
| NativeInteger_decode_oer, |
| NativeInteger_encode_oer, |
| #else |
| 0, |
| 0, |
| #endif |
| #if !defined(ASN_DISABLE_UPER_SUPPORT) |
| NativeInteger_decode_uper, |
| NativeInteger_encode_uper, |
| #else |
| 0, |
| 0, |
| #endif |
| #if !defined(ASN_DISABLE_APER_SUPPORT) |
| NativeInteger_decode_aper, |
| NativeInteger_encode_aper, |
| #else |
| 0, |
| 0, |
| #endif |
| #if !defined(ASN_DISABLE_RFILL_SUPPORT) |
| NativeInteger_random_fill, |
| #else |
| 0, |
| #endif |
| 0 |
| }; |
| asn_TYPE_descriptor_t asn_DEF_NativeInteger = { |
| "INTEGER", |
| "INTEGER", |
| &asn_OP_NativeInteger, |
| asn_DEF_NativeInteger_tags, |
| sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]), |
| asn_DEF_NativeInteger_tags, |
| sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]), |
| { |
| #if !defined(ASN_DISABLE_OER_SUPPORT) |
| 0, |
| #endif |
| #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) |
| 0, |
| #endif |
| asn_generic_no_constraint |
| }, |
| 0, 0, |
| 0 |
| }; |
|
|
| void |
| NativeInteger_free(const asn_TYPE_descriptor_t *td, void *ptr, |
| enum asn_struct_free_method method) { |
| if(!td || !ptr) |
| return; |
|
|
| ASN_DEBUG("Freeing %s as INTEGER (%d, %p, Native)", |
| td->name, method, ptr); |
|
|
| switch(method) { |
| case ASFM_FREE_EVERYTHING: |
| FREEMEM(ptr); |
| break; |
| case ASFM_FREE_UNDERLYING: |
| break; |
| case ASFM_FREE_UNDERLYING_AND_RESET: |
| memset(ptr, 0, sizeof(long)); |
| break; |
| } |
| } |
|
|
| int |
| NativeInteger_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr) { |
| (void)td; |
|
|
| if(aptr && bptr) { |
| const asn_INTEGER_specifics_t *specs = |
| (const asn_INTEGER_specifics_t *)td->specifics; |
| if(specs && specs->field_unsigned) { |
| const unsigned long *a = aptr; |
| const unsigned long *b = bptr; |
| if(*a < *b) { |
| return -1; |
| } else if(*a > *b) { |
| return 1; |
| } else { |
| return 0; |
| } |
| } else { |
| const long *a = aptr; |
| const long *b = bptr; |
| if(*a < *b) { |
| return -1; |
| } else if(*a > *b) { |
| return 1; |
| } else { |
| return 0; |
| } |
| } |
| } else if(!aptr) { |
| return -1; |
| } else { |
| return 1; |
| } |
| } |
|
|
| int |
| NativeInteger_copy(const asn_TYPE_descriptor_t *td, void **aptr, const void *bptr) { |
| unsigned long *a = *aptr; |
| const unsigned long *b = bptr; |
|
|
| (void)td; |
|
|
| |
| if(!b) { |
| |
| if(a) { |
| FREEMEM(a); |
| *aptr = 0; |
| } |
| return 0; |
| } |
|
|
| if(!a) { |
| a = *aptr = MALLOC(sizeof(*a)); |
| if(!a) return -1; |
| } |
|
|
| *a = *b; |
|
|
| return 0; |
| } |
|
|