blob: 9fe2e895dfb65375948b83a893629959d5c576b1 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _BER_DECODER_H_
6#define _BER_DECODER_H_
7
vlmd1579582004-09-24 21:00:50 +00008#include <asn_application.h>
vlmfa67ddc2004-06-03 03:38:44 +00009
vlm3a417582005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
vlm574b0812004-09-29 13:24:10 +000014struct asn_TYPE_descriptor_s; /* Forward declaration */
15struct asn_codec_ctx_s; /* Forward declaration */
vlmfa67ddc2004-06-03 03:38:44 +000016
17/*
vlmfa67ddc2004-06-03 03:38:44 +000018 * The BER decoder of any type.
19 * This function may be invoked directly from the application.
vlmb8bdf5f2007-05-30 17:42:00 +000020 * The der_encode() function (der_encoder.h) is an opposite to ber_decode().
vlmfa67ddc2004-06-03 03:38:44 +000021 */
vlm9de248e2004-10-20 15:50:55 +000022asn_dec_rval_t ber_decode(struct asn_codec_ctx_s *opt_codec_ctx,
vlm574b0812004-09-29 13:24:10 +000023 struct asn_TYPE_descriptor_s *type_descriptor,
vlmfa67ddc2004-06-03 03:38:44 +000024 void **struct_ptr, /* Pointer to a target structure's pointer */
vlmb02dcc62005-03-10 18:52:02 +000025 const void *buffer, /* Data to be decoded */
vlmfa67ddc2004-06-03 03:38:44 +000026 size_t size /* Size of that buffer */
27 );
28
29/*
30 * Type of generic function which decodes the byte stream into the structure.
31 */
vlm9de248e2004-10-20 15:50:55 +000032typedef asn_dec_rval_t (ber_type_decoder_f)(
vlm574b0812004-09-29 13:24:10 +000033 struct asn_codec_ctx_s *opt_codec_ctx,
34 struct asn_TYPE_descriptor_s *type_descriptor,
vlmb02dcc62005-03-10 18:52:02 +000035 void **struct_ptr, const void *buf_ptr, size_t size,
vlmfa67ddc2004-06-03 03:38:44 +000036 int tag_mode);
37
38/*******************************
39 * INTERNALLY USEFUL FUNCTIONS *
40 *******************************/
41
42/*
43 * Check that all tags correspond to the type definition (as given in head).
44 * On return, last_length would contain either a non-negative length of the
45 * value part of the last TLV, or the negative number of expected
46 * "end of content" sequences. The number may only be negative if the
47 * head->last_tag_form is non-zero.
48 */
vlm9de248e2004-10-20 15:50:55 +000049asn_dec_rval_t ber_check_tags(
vlm4d2ca122005-12-07 05:46:03 +000050 struct asn_codec_ctx_s *opt_codec_ctx, /* codec options */
51 struct asn_TYPE_descriptor_s *type_descriptor,
vlm574b0812004-09-29 13:24:10 +000052 asn_struct_ctx_t *opt_ctx, /* saved decoding context */
vlmb02dcc62005-03-10 18:52:02 +000053 const void *ptr, size_t size,
vlmfa67ddc2004-06-03 03:38:44 +000054 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
vlm6678cb12004-09-26 13:10:40 +000055 int last_tag_form, /* {-1,0:1}: any, primitive, constr */
vlmfa67ddc2004-06-03 03:38:44 +000056 ber_tlv_len_t *last_length,
vlm574b0812004-09-29 13:24:10 +000057 int *opt_tlv_form /* optional tag form */
58 );
vlmfa67ddc2004-06-03 03:38:44 +000059
vlm3a417582005-07-24 09:03:44 +000060#ifdef __cplusplus
61}
62#endif
63
vlmfa67ddc2004-06-03 03:38:44 +000064#endif /* _BER_DECODER_H_ */