📄 asn1r.h
字号:
/************************************************************************//* CONCLUDE ERROR REJECT DEFINITIONS *//************************************************************************/#define CONERR_UNSPECIFIED 0x70B0#define CONERR_INVAL_SERV 0x70B1#define CONERR_BAD_VALUE 0x70B2/************************************************************************//* General variables and pointers used by the ASN1 system. *//************************************************************************/#define ASN1_TAG_METHOD 0 /* decode by tag method */#define ASN1_CLASS_METHOD 1 /* decode by class method */#define ASN1_TABLE_METHOD 2 /* decode by table method */#define CSTR_DONE_FUN ac->asn1r_c_done_fun[ac->asn1r_msg_level]/************************************************************************//* This define is the maximum tag + length for a MMS-EASE encoded data *//* element (actually probably is 9), and is used in fin_constr and *//* fin_prim to prevent encode buffer overrun */#define ASN1_MAX_ELEMENT_OVERHEAD 10struct asn1_dec_ctxt; /* Forward reference *//************************************************************************//************************************************************************//* TAG METHOD STRUCTURES AND DEFINES */#define ASN1R_TAG_VAL(class,code) (((ST_UINT16)(class) << 8) | (code))typedef struct { ST_UINT16 _asn1r_tag; ST_VOID (*_asn1r_tag_fun)(struct asn1_dec_ctxt *ac); } ASN1R_TAG_PAIR;/* Decode users: Select the structure that has sufficient tag capacity */typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[1]; } ASN1R_TAG_CTRL_1;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[2]; } ASN1R_TAG_CTRL_2;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[3]; } ASN1R_TAG_CTRL_3;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[4]; } ASN1R_TAG_CTRL_4;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[5]; } ASN1R_TAG_CTRL_5;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[6]; } ASN1R_TAG_CTRL_6;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[7]; } ASN1R_TAG_CTRL_7;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[8]; } ASN1R_TAG_CTRL_8;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[9]; } ASN1R_TAG_CTRL_9;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[10];} ASN1R_TAG_CTRL_10;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[11];} ASN1R_TAG_CTRL_11;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[12];} ASN1R_TAG_CTRL_12;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[13];} ASN1R_TAG_CTRL_13;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[14];} ASN1R_TAG_CTRL_14;typedef struct {ST_INT num_tags; ASN1R_TAG_PAIR tags[15];} ASN1R_TAG_CTRL_15;/************************************************************************//* ASN.1 Context *//* This data structure is used to store all ASN.1 encode/decode context *//* information. If an application provides thread safe storage for this *//* data structure the ASN.1 tools become thread safe. */#define ASN1_MAX_USR_INFO 5#define MAX_TAG_FUN 16typedef struct asn1_dec_ctxt {/****** User and Internal Use ******//* User State */ ST_VOID *usr_info[ASN1_MAX_USR_INFO];/* General variables and pointers */ ST_BOOLEAN asn1r_decode_done; ST_UCHAR *asn1r_field_ptr; ST_UCHAR *asn1r_field_start; ST_UCHAR asn1r_constr_elmnt; ST_UCHAR asn1r_elmnt_class; ST_UINT16 asn1r_elmnt_id; ST_INT asn1r_elmnt_len; ST_INT asn1r_msg_level; ST_BOOLEAN asn1r_indef_flag; /* flag for indef cstr */ ST_RET asn1r_pdu_dec_err; ST_INT asn1r_decode_method; ST_INT asn1r_save_method; ST_INT asn1r_max_bits; ST_INT asn1r_bitcount; ST_INT asn1r_octetcount;/* For ASN1 decode table mode */ ST_VOID *asn1r_tag_table;/* Function pointers used by decoder users */ ST_VOID (*asn1r_decode_done_fun)(struct asn1_dec_ctxt *ac); ST_VOID (*asn1r_err_fun)(struct asn1_dec_ctxt *ac, ST_RET err_code); ST_VOID (*asn1r_c_done_fun[ASN1_MAX_LEVEL])(struct asn1_dec_ctxt *ac); ST_VOID (*asn1r_u_id_fun)(struct asn1_dec_ctxt *ac, ST_UINT16 id); ST_VOID (*asn1r_a_id_fun)(struct asn1_dec_ctxt *ac, ST_UINT16 id); ST_VOID (*asn1r_c_id_fun)(struct asn1_dec_ctxt *ac, ST_UINT16 id); ST_VOID (*asn1r_p_id_fun)(struct asn1_dec_ctxt *ac, ST_UINT16 id);/****** Internal Use Only ******//* Decode variables */ ST_INT _asn1_maxoctets; ST_UCHAR *_asn1_octetptr; ST_UCHAR *_ad_bitptr;/* Function pointers used internally by the ASN.1 tools */ ST_VOID (*_asn1r_cstr_done_save)(struct asn1_dec_ctxt *ac); ST_VOID (*_asn1r_fun_save)(struct asn1_dec_ctxt *ac); ST_INT _asn1r_ntag; ST_UINT16 _asn1r_valid_tags[MAX_TAG_FUN]; ST_VOID (*_asn1r_tag_fun[MAX_TAG_FUN])(struct asn1_dec_ctxt *ac); ST_INT _asn1r_old_ntag; ST_BOOLEAN _asn1_indef_track[ASN1_MAX_LEVEL]; ST_UCHAR *_asn1_constr_start[ASN1_MAX_LEVEL]; ST_INT _asn1_byte_count[ASN1_MAX_LEVEL]; ST_INT _ad_parse_method_save; ST_VOID (*_ad_parse_asn1r_fun_save)(struct asn1_dec_ctxt *ac); ST_UCHAR *_contents_done; /* will be here when done parsing cstr contents */ ST_UCHAR *_parse_begin_ptr; /* pointer to beginning of element being skipped*/ } ASN1_DEC_CTXT;typedef struct asn1_enc_ctxt {/* General variables and pointers */ ST_UCHAR *asn1r_field_ptr; ST_UCHAR *asn1r_field_end; ST_INT asn1r_msg_level; ST_UCHAR *asn1r_buf_start; /* ptr to first byte of buffer */ ST_UCHAR *asn1r_buf_end; /* ptr to last byte of buffer */ ST_BOOLEAN asn1r_encode_overrun; ST_UCHAR *asn1r_constr_end[ASN1_MAX_LEVEL]; } ASN1_ENC_CTXT;/************************************************************************/ASN1_DEC_CTXT *asn1r_get_ctxt (ST_VOID);ST_VOID asn1r_decode_asn1 (ASN1_DEC_CTXT *ac, ST_UCHAR *ptr, ST_INT len);ST_VOID asn1r_decode_asn1_seq (ASN1_DEC_CTXT *ac, ST_UCHAR *ptr, ST_INT len);ST_VOID asn1r_head_decode (ASN1_DEC_CTXT *ac);ST_VOID asn1r_set_dec_err (ASN1_DEC_CTXT *ac, ST_RET err_code);ST_VOID asn1r_done_err (ASN1_DEC_CTXT *ac);ST_VOID asn1r_cstr_done_err (ASN1_DEC_CTXT *ac);ST_VOID asn1r_set_all_cstr_done (ASN1_DEC_CTXT *ac);ST_VOID asn1r_class_err (ASN1_DEC_CTXT *ac, ST_UINT16 id);ST_VOID asn1r_chk_getcstr_done (ASN1_DEC_CTXT *ac);#if !defined(ASN1R_FAST_TAG_ADD)#define ASN1R_TAG_ADD(ac, class, code, fcn_ptr)\ asn1r_tag_add (ac, (((ST_UINT16)(class) << 8) | (code)), (fcn_ptr))#else#define ASN1R_TAG_ADD(ac, class, code, fcn_ptr)\ {\ ac->_asn1r_valid_tags[ac->_asn1r_ntag] = \ (((ST_UINT16)(class) << 8) | (code));\ ac->_asn1r_tag_fun[ac->_asn1r_ntag] = (ST_VOID (*)(ASN1_DEC_CTXT *)) fcn_ptr;\ ac->_asn1r_ntag++;\ }#endif#define ASN1R_TAG_DEL(ac, class, code)\ asn1r_tag_del (ac, (((ST_UINT16)(class) << 8) | (code)))ST_VOID asn1r_tag_add (ASN1_DEC_CTXT *ac, ST_UINT16 tag_class, ST_VOID (*fcn_ptr)(ASN1_DEC_CTXT *ac));ST_VOID asn1r_tag_del (ASN1_DEC_CTXT *ac, ST_UINT16 tag);ST_VOID asn1r_tag_restore (ASN1_DEC_CTXT *ac);ST_VOID asn1r_strt_asn1_bld (ASN1_ENC_CTXT *ac, ST_UCHAR *bufptr, ST_INT buflen);ST_VOID asn1r_fin_prim (ASN1_ENC_CTXT *ac, ST_UINT16 id_code, ST_UINT16 tag);ST_VOID asn1r_fin_constr (ASN1_ENC_CTXT *ac, ST_UINT16 id_code, ST_UINT16 el_tag, ST_BOOLEAN indef);ST_VOID asn1r_strt_constr (ASN1_ENC_CTXT *ac);ST_VOID asn1r_wr_u8 (ASN1_ENC_CTXT *ac, ST_UINT8 data);ST_VOID asn1r_wr_u16 (ASN1_ENC_CTXT *ac, ST_UINT16 data);ST_VOID asn1r_wr_u32 (ASN1_ENC_CTXT *ac, ST_UINT32 data);ST_VOID asn1r_wr_i8 (ASN1_ENC_CTXT *ac, ST_INT8 data);ST_VOID asn1r_wr_bool (ASN1_ENC_CTXT *ac, ST_BOOLEAN data);ST_VOID asn1r_wr_i16 (ASN1_ENC_CTXT *ac, ST_INT16 data);ST_VOID asn1r_wr_i32 (ASN1_ENC_CTXT *ac, ST_INT32 data);ST_VOID asn1r_wr_vstr (ASN1_ENC_CTXT *ac, ST_CHAR *data);ST_VOID asn1r_wr_delmnt (ASN1_ENC_CTXT *ac, ST_UCHAR *bufptr, ST_INT buflen);ST_VOID asn1r_wr_btod (ASN1_ENC_CTXT *ac, MMS_BTOD *data);ST_VOID asn1r_wr_time (ASN1_ENC_CTXT *ac, time_t data);ST_VOID asn1r_wr_objid (ASN1_ENC_CTXT *ac, ST_INT16 *data, ST_INT num_el);ST_VOID asn1r_wr_bitstr (ASN1_ENC_CTXT *ac, ST_UCHAR *bitptr, ST_INT numbits);ST_VOID asn1r_wr_octstr (ASN1_ENC_CTXT *ac, ST_UCHAR *octptr, ST_INT numoctets);ST_VOID asn1r_wr_float (ASN1_ENC_CTXT *ac, ST_FLOAT data);ST_VOID asn1r_wr_double (ASN1_ENC_CTXT *ac, ST_DOUBLE data);ST_VOID asn1r_wr_utc_time (ASN1_ENC_CTXT *ac, MMS_UTC_TIME *data);ST_RET asn1r_get_identifier (ASN1_DEC_CTXT *ac, ST_CHAR *dest);ST_RET asn1r_get_objid (ASN1_DEC_CTXT *ac, ST_INT16 component_list[], ST_INT *num_components);ST_RET asn1r_get_bool (ASN1_DEC_CTXT *ac, ST_BOOLEAN *dest);ST_VOID asn1r_get_strn (ASN1_DEC_CTXT *ac, ST_CHAR *dest);ST_RET asn1r_get_nstr (ASN1_DEC_CTXT *ac, ST_CHAR *dest);ST_RET asn1r_get_pstr (ASN1_DEC_CTXT *ac, ST_CHAR *dest);ST_RET asn1r_get_vstr (ASN1_DEC_CTXT *ac, ST_CHAR *dest);ST_RET asn1r_get_i8 (ASN1_DEC_CTXT *ac, ST_INT8 *dest);ST_RET asn1r_get_i16 (ASN1_DEC_CTXT *ac, ST_INT16 *dest);ST_RET asn1r_get_i32 (ASN1_DEC_CTXT *ac, ST_INT32 *dest);ST_RET asn1r_get_u8 (ASN1_DEC_CTXT *ac, ST_UCHAR *dest);ST_RET asn1r_get_u16 (ASN1_DEC_CTXT *ac, ST_UINT16 *dest);ST_RET asn1r_get_u32 (ASN1_DEC_CTXT *ac, ST_UINT32 *dest);ST_RET asn1r_get_btod (ASN1_DEC_CTXT *ac, MMS_BTOD *dest);ST_RET asn1r_get_time (ASN1_DEC_CTXT *ac, time_t *dest);ST_RET asn1r_get_bitstr (ASN1_DEC_CTXT *ac, ST_UCHAR *dest);ST_VOID asn1r_get_bitstr_cstr (ASN1_DEC_CTXT *ac, ST_INT bits, ST_UCHAR *ptr);ST_RET asn1r_get_octstr (ASN1_DEC_CTXT *ac, ST_UCHAR *dest);ST_VOID asn1r_get_octstr_cstr (ASN1_DEC_CTXT *ac, ST_INT numoctets, ST_UCHAR *octptr);ST_VOID asn1r_get_delmnt (ASN1_DEC_CTXT *ac, ST_INT buflen, ST_UCHAR *bufptr, ST_VOID (*done_fun)(ASN1_DEC_CTXT *ac));ST_RET asn1r_get_float (ASN1_DEC_CTXT *ac, ST_FLOAT *dest);ST_RET asn1r_get_double (ASN1_DEC_CTXT *ac, ST_DOUBLE *dest);ST_RET asn1r_get_utc_time (ASN1_DEC_CTXT *ac, MMS_UTC_TIME *dest);#ifdef INT64_SUPPORTST_VOID asn1r_wr_i64 (ASN1_ENC_CTXT *ac, ST_INT64 data);ST_VOID asn1r_wr_u64 (ASN1_ENC_CTXT *ac, ST_UINT64 data);ST_RET asn1r_get_i64 (ASN1_DEC_CTXT *ac, ST_INT64 *dest);ST_RET asn1r_get_u64 (ASN1_DEC_CTXT *ac, ST_UINT64 *dest);#endif /* INT64_SUPPORT */ST_VOID asn1r_parse_next (ASN1_DEC_CTXT *ac, ST_VOID (*done_fun)(ASN1_DEC_CTXT *ac));ST_VOID asn1r_parse_cstr_contents (ASN1_DEC_CTXT *ac, ST_VOID (*done_fun)(ASN1_DEC_CTXT *ac));/************************************************************************//* OBJECT IDENTIFIER *//************************************************************************/#define MAX_OBJID_COMPONENTS 16struct mms_obj_id { ST_INT num_comps; /* number of objid components */ ST_INT16 comps[MAX_OBJID_COMPONENTS]; /* identifier components */ SD_END_STRUCT };typedef struct mms_obj_id MMS_OBJ_ID;ST_BOOLEAN asn1_objidcmp (MMS_OBJ_ID *obj1, MMS_OBJ_ID *obj2);#ifdef __cplusplus}#endif/************************************************************************/#endif /* File not already included *//************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -