blob: e8b36c7926faeda81c9a5ebbccce02103f26bc10 [file] [log] [blame]
Harald Welte92c45f32010-06-12 18:59:38 +02001/*-
2 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _INTEGER_H_
6#define _INTEGER_H_
7
8#include <asn_application.h>
9#include <asn_codecs_prim.h>
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15typedef ASN__PRIMITIVE_TYPE_t INTEGER_t;
16
17extern asn_TYPE_descriptor_t asn_DEF_INTEGER;
18
19/* Map with <tag> to integer value association */
20typedef struct asn_INTEGER_enum_map_s {
Harald Welte41b85d52015-08-31 08:56:53 +020021 int64_t nat_value; /* associated native integer value */
Harald Welte92c45f32010-06-12 18:59:38 +020022 size_t enum_len; /* strlen("tag") */
23 const char *enum_name; /* "tag" */
24} asn_INTEGER_enum_map_t;
25
26/* This type describes an enumeration for INTEGER and ENUMERATED types */
Harald Welte41b85d52015-08-31 08:56:53 +020027typedef const struct asn_INTEGER_specifics_s {
28 const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
29 const unsigned int *enum2value; /* "tag" => N; sorted by tag */
Harald Welte92c45f32010-06-12 18:59:38 +020030 int map_count; /* Elements in either map */
31 int extension; /* This map is extensible */
32 int strict_enumeration; /* Enumeration set is fixed */
Harald Welteec0e2172010-07-20 00:03:44 +020033 int field_width; /* Size of native integer */
34 int field_unsigned; /* Signed=0, unsigned=1 */
Harald Welte92c45f32010-06-12 18:59:38 +020035} asn_INTEGER_specifics_t;
36
37asn_struct_print_f INTEGER_print;
38ber_type_decoder_f INTEGER_decode_ber;
39der_type_encoder_f INTEGER_encode_der;
40xer_type_decoder_f INTEGER_decode_xer;
41xer_type_encoder_f INTEGER_encode_xer;
42per_type_decoder_f INTEGER_decode_uper;
43per_type_encoder_f INTEGER_encode_uper;
Harald Welte41b85d52015-08-31 08:56:53 +020044per_type_decoder_f INTEGER_decode_aper;
45per_type_encoder_f INTEGER_encode_aper;
Harald Welte92c45f32010-06-12 18:59:38 +020046
47/***********************************
48 * Some handy conversion routines. *
49 ***********************************/
50
51/*
52 * Returns 0 if it was possible to convert, -1 otherwise.
53 * -1/EINVAL: Mandatory argument missing
54 * -1/ERANGE: Value encoded is out of range for long representation
55 * -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()).
56 */
Harald Welte41b85d52015-08-31 08:56:53 +020057int asn_INTEGER2int64(const INTEGER_t *i, int64_t *l);
58int asn_INTEGER2uint64(const INTEGER_t *i, uint64_t *l);
Harald Welte92c45f32010-06-12 18:59:38 +020059int asn_INTEGER2long(const INTEGER_t *i, long *l);
Harald Welteec0e2172010-07-20 00:03:44 +020060int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l);
Harald Welte41b85d52015-08-31 08:56:53 +020061int asn_int642INTEGER(INTEGER_t *i, int64_t l);
62int asn_uint642INTEGER(INTEGER_t *i, uint64_t l);
Harald Welte92c45f32010-06-12 18:59:38 +020063int asn_long2INTEGER(INTEGER_t *i, long l);
Harald Welteec0e2172010-07-20 00:03:44 +020064int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);
Harald Welte92c45f32010-06-12 18:59:38 +020065
Harald Welte41b85d52015-08-31 08:56:53 +020066/* A a reified version of strtol(3) with nicer error reporting. */
67enum asn_strtol_result_e {
68 ASN_STRTOL_ERROR_RANGE = -3, /* Input outside of numeric range for long type */
69 ASN_STRTOL_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */
70 ASN_STRTOL_EXPECT_MORE = -1, /* More data expected (e.g. "+") */
71 ASN_STRTOL_OK = 0, /* Conversion succeded, number ends at (*end) */
72 ASN_STRTOL_EXTRA_DATA = 1, /* Conversion succeded, but the string has extra stuff */
73};
74enum asn_strtol_result_e asn_strtol_lim(const char *str, const char **end, long *l);
75
76/* The asn_strtol is going to be DEPRECATED soon */
77enum asn_strtol_result_e asn_strtol(const char *str, const char *end, long *l);
78
Harald Welte92c45f32010-06-12 18:59:38 +020079/*
80 * Convert the integer value into the corresponding enumeration map entry.
81 */
82const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value);
83
84#ifdef __cplusplus
85}
86#endif
87
88#endif /* _INTEGER_H_ */