blob: 708d8454cb08ccf4a53f8522a38a1a0136a840ec [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin4ca03ac2005-02-28 15:20:27 +00002 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _INTEGER_H_
6#define _INTEGER_H_
7
Lev Walkin11c3e172004-09-24 21:00:50 +00008#include <asn_application.h>
Lev Walkind703ff42004-10-21 11:21:25 +00009#include <asn_codecs_prim.h>
Bi-Ruei, Chiue1bf2192017-08-19 00:55:25 +080010#include <NativeInteger.h>
Lev Walkinf15320b2004-06-03 03:38:44 +000011
Lev Walkin21b41ac2005-07-24 09:03:44 +000012#ifdef __cplusplus
13extern "C" {
14#endif
15
Lev Walkin8e8078a2004-09-26 13:10:40 +000016typedef ASN__PRIMITIVE_TYPE_t INTEGER_t;
Lev Walkinf15320b2004-06-03 03:38:44 +000017
Lev Walkin5e033762004-09-29 13:26:15 +000018extern asn_TYPE_descriptor_t asn_DEF_INTEGER;
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080019extern asn_TYPE_operation_t asn_OP_INTEGER;
Lev Walkinf15320b2004-06-03 03:38:44 +000020
Lev Walkine0b56e02005-02-25 12:10:27 +000021/* Map with <tag> to integer value association */
22typedef struct asn_INTEGER_enum_map_s {
23 long nat_value; /* associated native integer value */
24 size_t enum_len; /* strlen("tag") */
25 const char *enum_name; /* "tag" */
26} asn_INTEGER_enum_map_t;
27
28/* This type describes an enumeration for INTEGER and ENUMERATED types */
Lev Walkin36ddfc82017-08-22 09:22:08 +000029typedef struct asn_INTEGER_specifics_s {
Wim Lewisfb6344e2014-07-28 12:16:01 -070030 const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
31 const unsigned int *enum2value; /* "tag" => N; sorted by tag */
Lev Walkine0b56e02005-02-25 12:10:27 +000032 int map_count; /* Elements in either map */
Lev Walkin59b176e2005-11-26 11:25:14 +000033 int extension; /* This map is extensible */
Lev Walkine0b56e02005-02-25 12:10:27 +000034 int strict_enumeration; /* Enumeration set is fixed */
Lev Walkin8bb57a22007-12-03 13:41:36 +000035 int field_width; /* Size of native integer */
36 int field_unsigned; /* Signed=0, unsigned=1 */
Lev Walkine0b56e02005-02-25 12:10:27 +000037} asn_INTEGER_specifics_t;
38
Lev Walkin8077f932017-08-07 17:27:43 -070039#define INTEGER_free ASN__PRIMITIVE_TYPE_free
Bi-Ruei, Chiue1bf2192017-08-19 00:55:25 +080040#define INTEGER_decode_ber ber_decode_primitive
41#define INTEGER_constraint asn_generic_no_constraint
Lev Walkina9cc46e2004-09-22 16:06:28 +000042asn_struct_print_f INTEGER_print;
Lev Walkincd2f48e2017-08-10 02:14:59 -070043asn_struct_compare_f INTEGER_compare;
Lev Walkinf15320b2004-06-03 03:38:44 +000044der_type_encoder_f INTEGER_encode_der;
Lev Walkind703ff42004-10-21 11:21:25 +000045xer_type_decoder_f INTEGER_decode_xer;
Lev Walkina9cc46e2004-09-22 16:06:28 +000046xer_type_encoder_f INTEGER_encode_xer;
Lev Walkin602aacb2017-07-24 01:46:41 +040047oer_type_decoder_f INTEGER_decode_oer;
48oer_type_encoder_f INTEGER_encode_oer;
Lev Walkin59b176e2005-11-26 11:25:14 +000049per_type_decoder_f INTEGER_decode_uper;
Lev Walkin523de9e2006-08-18 01:34:18 +000050per_type_encoder_f INTEGER_encode_uper;
Lev Walkina5972be2017-09-29 23:15:58 -070051asn_random_fill_f INTEGER_random_fill;
Lev Walkinf15320b2004-06-03 03:38:44 +000052
53/***********************************
54 * Some handy conversion routines. *
55 ***********************************/
56
57/*
Lev Walkin72ec9092017-07-05 05:49:12 -070058 * Natiwe size-independent conversion of native integers to/from INTEGER.
59 * (l_size) is in bytes.
Lev Walkinf15320b2004-06-03 03:38:44 +000060 * Returns 0 if it was possible to convert, -1 otherwise.
61 * -1/EINVAL: Mandatory argument missing
62 * -1/ERANGE: Value encoded is out of range for long representation
Lev Walkin72ec9092017-07-05 05:49:12 -070063 * -1/ENOMEM: Memory allocation failed (in asn_*2INTEGER()).
64 */
65int asn_INTEGER2imax(const INTEGER_t *i, intmax_t *l);
66int asn_INTEGER2umax(const INTEGER_t *i, uintmax_t *l);
67int asn_imax2INTEGER(INTEGER_t *i, intmax_t l);
68int asn_umax2INTEGER(INTEGER_t *i, uintmax_t l);
69
70/*
71 * Size-specific conversion helpers.
Lev Walkinf15320b2004-06-03 03:38:44 +000072 */
Lev Walkin5e033762004-09-29 13:26:15 +000073int asn_INTEGER2long(const INTEGER_t *i, long *l);
Lev Walkin5c879db2007-11-06 06:23:31 +000074int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l);
Lev Walkind703ff42004-10-21 11:21:25 +000075int asn_long2INTEGER(INTEGER_t *i, long l);
Lev Walkin5c879db2007-11-06 06:23:31 +000076int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);
Lev Walkinf15320b2004-06-03 03:38:44 +000077
Lev Walkin72ec9092017-07-05 05:49:12 -070078/* A version of strtol/strtoimax(3) with nicer error reporting. */
79enum asn_strtox_result_e {
80 ASN_STRTOX_ERROR_RANGE = -3, /* Input outside of supported numeric range */
81 ASN_STRTOX_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */
82 ASN_STRTOX_EXPECT_MORE = -1, /* More data expected (e.g. "+") */
83 ASN_STRTOX_OK = 0, /* Conversion succeded, number ends at (*end) */
84 ASN_STRTOX_EXTRA_DATA = 1 /* Conversion succeded, but the string has extra stuff */
Lev Walkine09f9f12012-09-02 23:06:35 -070085};
Lev Walkin588bf0f2017-10-13 23:51:16 -070086enum asn_strtox_result_e asn_strtol_lim(const char *str, const char **end,
87 long *l);
88enum asn_strtox_result_e asn_strtoul_lim(const char *str, const char **end,
89 unsigned long *l);
90enum asn_strtox_result_e asn_strtoimax_lim(const char *str, const char **end,
91 intmax_t *l);
92enum asn_strtox_result_e asn_strtoumax_lim(const char *str, const char **end,
93 uintmax_t *l);
Lev Walkinb3751942012-09-02 19:36:47 -070094
Lev Walkinfc776432005-03-29 17:21:14 +000095/*
96 * Convert the integer value into the corresponding enumeration map entry.
97 */
Lev Walkind62a6622017-08-22 02:31:02 -070098const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(
99 const asn_INTEGER_specifics_t *specs, long value);
Lev Walkinfc776432005-03-29 17:21:14 +0000100
Lev Walkin21b41ac2005-07-24 09:03:44 +0000101#ifdef __cplusplus
102}
103#endif
104
Lev Walkinf15320b2004-06-03 03:38:44 +0000105#endif /* _INTEGER_H_ */