2004-06-03 03:38:44 +00:00
|
|
|
/*-
|
2005-02-28 15:20:27 +00:00
|
|
|
* Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
|
2004-06-03 03:38:44 +00:00
|
|
|
* Redistribution and modifications are permitted subject to BSD license.
|
|
|
|
*/
|
|
|
|
#ifndef _INTEGER_H_
|
|
|
|
#define _INTEGER_H_
|
|
|
|
|
2004-09-24 21:00:50 +00:00
|
|
|
#include <asn_application.h>
|
2004-10-21 11:21:25 +00:00
|
|
|
#include <asn_codecs_prim.h>
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-07-24 09:03:44 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2004-09-26 13:10:40 +00:00
|
|
|
typedef ASN__PRIMITIVE_TYPE_t INTEGER_t;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2004-09-29 13:26:15 +00:00
|
|
|
extern asn_TYPE_descriptor_t asn_DEF_INTEGER;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2005-02-25 12:10:27 +00:00
|
|
|
/* Map with <tag> to integer value association */
|
|
|
|
typedef struct asn_INTEGER_enum_map_s {
|
|
|
|
long nat_value; /* associated native integer value */
|
|
|
|
size_t enum_len; /* strlen("tag") */
|
|
|
|
const char *enum_name; /* "tag" */
|
|
|
|
} asn_INTEGER_enum_map_t;
|
|
|
|
|
|
|
|
/* This type describes an enumeration for INTEGER and ENUMERATED types */
|
2017-08-22 09:22:08 +00:00
|
|
|
typedef struct asn_INTEGER_specifics_s {
|
2014-07-28 19:16:01 +00:00
|
|
|
const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
|
|
|
|
const unsigned int *enum2value; /* "tag" => N; sorted by tag */
|
2005-02-25 12:10:27 +00:00
|
|
|
int map_count; /* Elements in either map */
|
2005-11-26 11:25:14 +00:00
|
|
|
int extension; /* This map is extensible */
|
2005-02-25 12:10:27 +00:00
|
|
|
int strict_enumeration; /* Enumeration set is fixed */
|
2007-12-03 13:41:36 +00:00
|
|
|
int field_width; /* Size of native integer */
|
|
|
|
int field_unsigned; /* Signed=0, unsigned=1 */
|
2005-02-25 12:10:27 +00:00
|
|
|
} asn_INTEGER_specifics_t;
|
|
|
|
|
2017-08-08 00:27:43 +00:00
|
|
|
#define INTEGER_free ASN__PRIMITIVE_TYPE_free
|
2004-09-22 16:06:28 +00:00
|
|
|
asn_struct_print_f INTEGER_print;
|
2017-08-10 09:14:59 +00:00
|
|
|
asn_struct_compare_f INTEGER_compare;
|
2004-06-03 03:38:44 +00:00
|
|
|
ber_type_decoder_f INTEGER_decode_ber;
|
|
|
|
der_type_encoder_f INTEGER_encode_der;
|
2004-10-21 11:21:25 +00:00
|
|
|
xer_type_decoder_f INTEGER_decode_xer;
|
2004-09-22 16:06:28 +00:00
|
|
|
xer_type_encoder_f INTEGER_encode_xer;
|
2017-07-23 21:46:41 +00:00
|
|
|
oer_type_decoder_f INTEGER_decode_oer;
|
|
|
|
oer_type_encoder_f INTEGER_encode_oer;
|
2005-11-26 11:25:14 +00:00
|
|
|
per_type_decoder_f INTEGER_decode_uper;
|
2006-08-18 01:34:18 +00:00
|
|
|
per_type_encoder_f INTEGER_encode_uper;
|
2004-06-03 03:38:44 +00:00
|
|
|
|
|
|
|
/***********************************
|
|
|
|
* Some handy conversion routines. *
|
|
|
|
***********************************/
|
|
|
|
|
|
|
|
/*
|
2017-07-05 12:49:12 +00:00
|
|
|
* Natiwe size-independent conversion of native integers to/from INTEGER.
|
|
|
|
* (l_size) is in bytes.
|
2004-06-03 03:38:44 +00:00
|
|
|
* Returns 0 if it was possible to convert, -1 otherwise.
|
|
|
|
* -1/EINVAL: Mandatory argument missing
|
|
|
|
* -1/ERANGE: Value encoded is out of range for long representation
|
2017-07-05 12:49:12 +00:00
|
|
|
* -1/ENOMEM: Memory allocation failed (in asn_*2INTEGER()).
|
|
|
|
*/
|
|
|
|
int asn_INTEGER2imax(const INTEGER_t *i, intmax_t *l);
|
|
|
|
int asn_INTEGER2umax(const INTEGER_t *i, uintmax_t *l);
|
|
|
|
int asn_imax2INTEGER(INTEGER_t *i, intmax_t l);
|
|
|
|
int asn_umax2INTEGER(INTEGER_t *i, uintmax_t l);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Size-specific conversion helpers.
|
2004-06-03 03:38:44 +00:00
|
|
|
*/
|
2004-09-29 13:26:15 +00:00
|
|
|
int asn_INTEGER2long(const INTEGER_t *i, long *l);
|
2007-11-06 06:23:31 +00:00
|
|
|
int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l);
|
2004-10-21 11:21:25 +00:00
|
|
|
int asn_long2INTEGER(INTEGER_t *i, long l);
|
2007-11-06 06:23:31 +00:00
|
|
|
int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);
|
2004-06-03 03:38:44 +00:00
|
|
|
|
2017-07-05 12:49:12 +00:00
|
|
|
/* A version of strtol/strtoimax(3) with nicer error reporting. */
|
|
|
|
enum asn_strtox_result_e {
|
|
|
|
ASN_STRTOX_ERROR_RANGE = -3, /* Input outside of supported numeric range */
|
|
|
|
ASN_STRTOX_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */
|
|
|
|
ASN_STRTOX_EXPECT_MORE = -1, /* More data expected (e.g. "+") */
|
|
|
|
ASN_STRTOX_OK = 0, /* Conversion succeded, number ends at (*end) */
|
|
|
|
ASN_STRTOX_EXTRA_DATA = 1 /* Conversion succeded, but the string has extra stuff */
|
2012-09-03 06:06:35 +00:00
|
|
|
};
|
2017-07-05 12:49:12 +00:00
|
|
|
enum asn_strtox_result_e asn_strtol_lim(const char *str, const char **end, long *l);
|
|
|
|
enum asn_strtox_result_e asn_strtoimax_lim(const char *str, const char **end, intmax_t *l);
|
2012-09-03 02:36:47 +00:00
|
|
|
|
2005-03-29 17:21:14 +00:00
|
|
|
/*
|
|
|
|
* Convert the integer value into the corresponding enumeration map entry.
|
|
|
|
*/
|
|
|
|
const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value);
|
|
|
|
|
2005-07-24 09:03:44 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-06-03 03:38:44 +00:00
|
|
|
#endif /* _INTEGER_H_ */
|