mirror of https://gerrit.osmocom.org/asn1c
ber_dec_ctx_t renamed into asn_struct_ctx_t; added generic codec context
This commit is contained in:
parent
9722a08c79
commit
1cbd222a0b
|
@ -7,7 +7,8 @@
|
|||
|
||||
#include <asn_application.h>
|
||||
|
||||
struct asn1_TYPE_descriptor_s; /* Forward declaration */
|
||||
struct asn_TYPE_descriptor_s; /* Forward declaration */
|
||||
struct asn_codec_ctx_s; /* Forward declaration */
|
||||
|
||||
/*
|
||||
* This structure describes the return value common across the
|
||||
|
@ -18,31 +19,22 @@ struct asn1_TYPE_descriptor_s; /* Forward declaration */
|
|||
* decoded bytes, hence provide a possibility, to fail with more diagnostics
|
||||
* (i.e., print the offending remainder of the buffer).
|
||||
*/
|
||||
enum ber_dec_rval_code_e {
|
||||
enum ber_dec_rval_code_e {
|
||||
RC_OK, /* Decoded successfully */
|
||||
RC_WMORE, /* More data expected, call again */
|
||||
RC_FAIL /* Failure to decode data */
|
||||
};
|
||||
};
|
||||
typedef struct ber_dec_rval_s {
|
||||
enum ber_dec_rval_code_e code; /* Result code */
|
||||
size_t consumed; /* Number of bytes consumed */
|
||||
} ber_dec_rval_t;
|
||||
|
||||
/*
|
||||
* A context for decoding BER across buffer boundaries.
|
||||
*/
|
||||
typedef struct ber_dec_ctx_s {
|
||||
int phase; /* Decoding phase */
|
||||
int step; /* Elementary step of a phase */
|
||||
ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */
|
||||
void *ptr; /* Decoder-specific stuff */
|
||||
} ber_dec_ctx_t;
|
||||
|
||||
/*
|
||||
* The BER decoder of any type.
|
||||
* This function may be invoked directly from the application.
|
||||
*/
|
||||
ber_dec_rval_t ber_decode(struct asn1_TYPE_descriptor_s *type_descriptor,
|
||||
ber_dec_rval_t ber_decode(struct asn_codec_ctx_s *opt_codec_ctx,
|
||||
struct asn_TYPE_descriptor_s *type_descriptor,
|
||||
void **struct_ptr, /* Pointer to a target structure's pointer */
|
||||
void *buffer, /* Data to be decoded */
|
||||
size_t size /* Size of that buffer */
|
||||
|
@ -52,7 +44,8 @@ ber_dec_rval_t ber_decode(struct asn1_TYPE_descriptor_s *type_descriptor,
|
|||
* Type of generic function which decodes the byte stream into the structure.
|
||||
*/
|
||||
typedef ber_dec_rval_t (ber_type_decoder_f)(
|
||||
struct asn1_TYPE_descriptor_s *type_descriptor,
|
||||
struct asn_codec_ctx_s *opt_codec_ctx,
|
||||
struct asn_TYPE_descriptor_s *type_descriptor,
|
||||
void **type_structure, void *buf_ptr, size_t size,
|
||||
int tag_mode);
|
||||
|
||||
|
@ -67,12 +60,15 @@ typedef ber_dec_rval_t (ber_type_decoder_f)(
|
|||
* "end of content" sequences. The number may only be negative if the
|
||||
* head->last_tag_form is non-zero.
|
||||
*/
|
||||
ber_dec_rval_t ber_check_tags(struct asn1_TYPE_descriptor_s *type_dsc,
|
||||
ber_dec_ctx_t *opt_ctx, /* saved context */
|
||||
ber_dec_rval_t ber_check_tags(
|
||||
struct asn_codec_ctx_s *opt_codec_ctx, /* optional context */
|
||||
struct asn_TYPE_descriptor_s *type_dsc,
|
||||
asn_struct_ctx_t *opt_ctx, /* saved decoding context */
|
||||
void *ptr, size_t size,
|
||||
int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
|
||||
int last_tag_form, /* {-1,0:1}: any, primitive, constr */
|
||||
ber_tlv_len_t *last_length,
|
||||
int *opt_tlv_form);
|
||||
int *opt_tlv_form /* optional tag form */
|
||||
);
|
||||
|
||||
#endif /* _BER_DECODER_H_ */
|
||||
|
|
|
@ -11,8 +11,45 @@
|
|||
#ifndef _CONSTR_TYPE_H
|
||||
#define _CONSTR_TYPE_H
|
||||
|
||||
struct asn1_TYPE_descriptor_s; /* Forward declaration */
|
||||
struct asn1_TYPE_member_s; /* Forward declaration */
|
||||
#include <ber_tlv_length.h>
|
||||
#include <ber_tlv_tag.h>
|
||||
|
||||
struct asn_TYPE_descriptor_s; /* Forward declaration */
|
||||
struct asn_TYPE_member_s; /* Forward declaration */
|
||||
|
||||
/*
|
||||
* This type provides the context information for various ASN.1 routines,
|
||||
* primarily ones doing decoding. A member _asn_ctx of this type must be
|
||||
* included into certain target language's structures, such as compound types.
|
||||
*/
|
||||
typedef struct asn_struct_ctx_s {
|
||||
int phase; /* Decoding phase */
|
||||
int step; /* Elementary step of a phase */
|
||||
ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */
|
||||
void *ptr; /* Decoder-specific stuff (stack elements) */
|
||||
} asn_struct_ctx_t;
|
||||
|
||||
/*
|
||||
* This structure defines a context that may be passed to every ASN.1 encoder
|
||||
* or decoder function.
|
||||
* WARNING: if max_stack_size member is set, and you are calling the
|
||||
* function pointers of the asn_TYPE_descriptor_t directly,
|
||||
* this structure must be ALLOCATED ON THE STACK!
|
||||
*/
|
||||
typedef struct asn_codec_ctx_s {
|
||||
/*
|
||||
* Limit the decoder routines to use no (much) more stack than a given
|
||||
* number of bytes. Most of decoders are stack-based, and this
|
||||
* would protect against stack overflows if the number of nested
|
||||
* encodings is high.
|
||||
* The OCTET STRING, BIT STRING and ANY BER decoders are heap-based,
|
||||
* and are safe from this kind of overflow.
|
||||
* A value from getrlimit(RLIMIT_STACK) may be used to initialize
|
||||
* this variable. Be careful in multithreaded environments, as the
|
||||
* stack size is rather limited.
|
||||
*/
|
||||
size_t max_stack_size; /* 0 disables stack bounds checking */
|
||||
} asn_codec_ctx_t;
|
||||
|
||||
/*
|
||||
* Type of the return value of the encoding functions (der_encode, xer_encode).
|
||||
|
@ -30,7 +67,7 @@ typedef struct asn_enc_rval_s {
|
|||
*/
|
||||
|
||||
/* Type which cannot be encoded */
|
||||
struct asn1_TYPE_descriptor_s *failed_type;
|
||||
struct asn_TYPE_descriptor_s *failed_type;
|
||||
|
||||
/* Pointer to the structure of that type */
|
||||
void *structure_ptr;
|
||||
|
@ -40,8 +77,6 @@ typedef struct asn_enc_rval_s {
|
|||
return __er; \
|
||||
} while(0)
|
||||
|
||||
#include <ber_tlv_length.h>
|
||||
#include <ber_tlv_tag.h>
|
||||
#include <ber_decoder.h>
|
||||
#include <der_encoder.h>
|
||||
#include <xer_encoder.h>
|
||||
|
@ -55,14 +90,14 @@ typedef struct asn_enc_rval_s {
|
|||
* dynamically.)
|
||||
*/
|
||||
typedef void (asn_struct_free_f)(
|
||||
struct asn1_TYPE_descriptor_s *type_descriptor,
|
||||
struct asn_TYPE_descriptor_s *type_descriptor,
|
||||
void *struct_ptr, int free_contents_only);
|
||||
|
||||
/*
|
||||
* Print the structure according to its specification.
|
||||
*/
|
||||
typedef int (asn_struct_print_f)(
|
||||
struct asn1_TYPE_descriptor_s *type_descriptor,
|
||||
struct asn_TYPE_descriptor_s *type_descriptor,
|
||||
const void *struct_ptr,
|
||||
int level, /* Indentation level */
|
||||
asn_app_consume_bytes_f *callback, void *app_key);
|
||||
|
@ -74,16 +109,16 @@ typedef int (asn_struct_print_f)(
|
|||
* Do not use it in your application.
|
||||
*/
|
||||
typedef ber_tlv_tag_t (asn_outmost_tag_f)(
|
||||
struct asn1_TYPE_descriptor_s *type_descriptor,
|
||||
struct asn_TYPE_descriptor_s *type_descriptor,
|
||||
const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag);
|
||||
/* The instance of the above function type; used internally. */
|
||||
asn_outmost_tag_f asn1_TYPE_outmost_tag;
|
||||
asn_outmost_tag_f asn_TYPE_outmost_tag;
|
||||
|
||||
|
||||
/*
|
||||
* The definitive description of the destination language's structure.
|
||||
*/
|
||||
typedef struct asn1_TYPE_descriptor_s {
|
||||
typedef struct asn_TYPE_descriptor_s {
|
||||
char *name; /* A name of the ASN.1 type */
|
||||
|
||||
/*
|
||||
|
@ -114,7 +149,7 @@ typedef struct asn1_TYPE_descriptor_s {
|
|||
/*
|
||||
* An ASN.1 production type members (members of SEQUENCE, SET, CHOICE).
|
||||
*/
|
||||
struct asn1_TYPE_member_s *elements;
|
||||
struct asn_TYPE_member_s *elements;
|
||||
int elements_count;
|
||||
|
||||
/*
|
||||
|
@ -122,37 +157,37 @@ typedef struct asn1_TYPE_descriptor_s {
|
|||
* functions above.
|
||||
*/
|
||||
void *specifics;
|
||||
} asn1_TYPE_descriptor_t;
|
||||
} asn_TYPE_descriptor_t;
|
||||
|
||||
/*
|
||||
* An element of the constructed type, i.e. SEQUENCE, SET, CHOICE.
|
||||
* This type describes an element of the constructed type,
|
||||
* i.e. SEQUENCE, SET, CHOICE, etc.
|
||||
*/
|
||||
enum asn1_TYPE_flags_e {
|
||||
enum asn_TYPE_flags_e {
|
||||
ATF_NOFLAGS,
|
||||
ATF_POINTER = 0x01, /* Represented by the pointer */
|
||||
ATF_OPEN_TYPE = 0x02 /* ANY type, without meaningful tag */
|
||||
};
|
||||
typedef struct asn1_TYPE_member_s {
|
||||
enum asn1_TYPE_flags_e flags; /* Element's presentation flags */
|
||||
typedef struct asn_TYPE_member_s {
|
||||
enum asn_TYPE_flags_e flags; /* Element's presentation flags */
|
||||
int optional; /* Following optional members, including current */
|
||||
int memb_offset; /* Offset of the element */
|
||||
ber_tlv_tag_t tag; /* Outmost (most immediate) tag */
|
||||
int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */
|
||||
asn1_TYPE_descriptor_t *type; /* Member type descriptor */
|
||||
asn_TYPE_descriptor_t *type; /* Member type descriptor */
|
||||
asn_constr_check_f *memb_constraints; /* Constraints validator */
|
||||
char *name; /* ASN.1 identifier of the element */
|
||||
} asn1_TYPE_member_t;
|
||||
} asn_TYPE_member_t;
|
||||
|
||||
/*
|
||||
* BER tag to element number mapping.
|
||||
*/
|
||||
typedef struct asn1_TYPE_tag2member_s {
|
||||
typedef struct asn_TYPE_tag2member_s {
|
||||
ber_tlv_tag_t el_tag; /* Outmost tag of the member */
|
||||
int el_no; /* Index of the associated member, base 0 */
|
||||
int toff_first; /* First occurence of the el_tag, relative */
|
||||
int toff_last; /* Last occurence of the el_tag, relatvie */
|
||||
} asn1_TYPE_tag2member_t;
|
||||
|
||||
} asn_TYPE_tag2member_t;
|
||||
|
||||
/*
|
||||
* This function is a wrapper around (td)->print_struct, which prints out
|
||||
|
@ -164,7 +199,7 @@ typedef struct asn1_TYPE_tag2member_s {
|
|||
* (See also xer_fprint() in xer_encoder.h)
|
||||
*/
|
||||
int asn_fprint(FILE *stream, /* Destination stream descriptor */
|
||||
asn1_TYPE_descriptor_t *td, /* ASN.1 type descriptor */
|
||||
asn_TYPE_descriptor_t *td, /* ASN.1 type descriptor */
|
||||
const void *struct_ptr); /* Structure to be printed */
|
||||
|
||||
#endif /* _CONSTR_TYPE_H_ */
|
||||
|
|
Loading…
Reference in New Issue