Lev Walkin | da997b1 | 2017-08-04 01:38:41 -0700 | [diff] [blame] | 1 | #ifndef ASN1P_INTEGER_H |
| 2 | #define ASN1P_INTEGER_H |
| 3 | |
| 4 | #ifdef HAVE_CONFIG_H |
| 5 | #include "config.h" |
| 6 | #endif /* HAVE_CONFIG_H */ |
| 7 | |
Lev Walkin | 3eb2703 | 2017-11-18 14:37:35 -0800 | [diff] [blame] | 8 | #include <asn1_buffer.h> |
| 9 | |
Lev Walkin | da997b1 | 2017-08-04 01:38:41 -0700 | [diff] [blame] | 10 | #ifdef HAVE_SYS_TYPES_H |
| 11 | #include <sys/types.h> |
| 12 | #endif /* HAVE_SYS_TYPES_H */ |
| 13 | #ifdef HAVE_INTTYPES_H |
| 14 | #include <inttypes.h> /* POSIX 1003.1-2001, C99 */ |
| 15 | #else /* HAVE_INTTYPES_H */ |
| 16 | #ifdef HAVE_STDINT_H |
| 17 | #include <stdint.h> /* SUSv2+ */ |
| 18 | #endif /* HAVE_STDINT_H */ |
| 19 | #endif /* HAVE_INTTYPES_H */ |
| 20 | |
| 21 | /* |
| 22 | * Basic integer type used in numerous places. |
| 23 | * ASN.1 does not define any limits on this number, so it must be sufficiently |
| 24 | * large to accomodate typical inputs. It does not have to be a dynamically |
| 25 | * allocated type with potentially unlimited width: consider the width of |
| 26 | * an integer defined here as one of the "compiler limitations". |
| 27 | * NOTE: this is NOT a type for ASN.1 "INTEGER" type representation, this |
| 28 | * type is used by the compiler itself to handle large integer values |
| 29 | * specified inside ASN.1 grammar. |
| 30 | */ |
| 31 | #ifdef HAVE_128_BIT_INT |
| 32 | typedef __int128 asn1c_integer_t; |
| 33 | #else |
| 34 | typedef intmax_t asn1c_integer_t; |
| 35 | #endif |
| 36 | |
| 37 | int asn1p_atoi(const char *ptr, asn1c_integer_t *r_value); |
| 38 | const char *asn1p_itoa(asn1c_integer_t value); /* Ptr to a static buf */ |
| 39 | /* |
| 40 | * Return values: |
| 41 | * -1: The value did not fit in the buffer. |
| 42 | * >0: The length in bytes of the stringified numeric value. |
| 43 | */ |
| 44 | int asn1p_itoa_s(char *buf, size_t size, |
| 45 | asn1c_integer_t value); /* Return -1 on error, or length. */ |
| 46 | |
Lev Walkin | 3eb2703 | 2017-11-18 14:37:35 -0800 | [diff] [blame] | 47 | /* |
| 48 | * Convert asn1c_integer_t into INTEGER_t structure. |
| 49 | */ |
| 50 | abuf *asn1p_integer_as_INTEGER(asn1c_integer_t value); |
| 51 | |
Lev Walkin | da997b1 | 2017-08-04 01:38:41 -0700 | [diff] [blame] | 52 | #endif /* ASN1P_INTEGER_H */ |