blob: 768133b67e75b4eb18e523e1943245e17ce9b3aa [file] [log] [blame]
Lev Walkinf15320b2004-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
Lev Walkin11c3e172004-09-24 21:00:50 +00008#include <asn_application.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00009
Lev Walkin21b41ac2005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
Lev Walkin1cbd2222004-09-29 13:24:10 +000014struct asn_TYPE_descriptor_s; /* Forward declaration */
15struct asn_codec_ctx_s; /* Forward declaration */
Lev Walkinf15320b2004-06-03 03:38:44 +000016
17/*
Lev Walkinf15320b2004-06-03 03:38:44 +000018 * The BER decoder of any type.
19 * This function may be invoked directly from the application.
20 */
Lev Walkindc06f6b2004-10-20 15:50:55 +000021asn_dec_rval_t ber_decode(struct asn_codec_ctx_s *opt_codec_ctx,
Lev Walkin1cbd2222004-09-29 13:24:10 +000022 struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000023 void **struct_ptr, /* Pointer to a target structure's pointer */
Lev Walkin8c3b8542005-03-10 18:52:02 +000024 const void *buffer, /* Data to be decoded */
Lev Walkinf15320b2004-06-03 03:38:44 +000025 size_t size /* Size of that buffer */
26 );
27
28/*
29 * Type of generic function which decodes the byte stream into the structure.
30 */
Lev Walkindc06f6b2004-10-20 15:50:55 +000031typedef asn_dec_rval_t (ber_type_decoder_f)(
Lev Walkin1cbd2222004-09-29 13:24:10 +000032 struct asn_codec_ctx_s *opt_codec_ctx,
33 struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkin8c3b8542005-03-10 18:52:02 +000034 void **struct_ptr, const void *buf_ptr, size_t size,
Lev Walkinf15320b2004-06-03 03:38:44 +000035 int tag_mode);
36
37/*******************************
38 * INTERNALLY USEFUL FUNCTIONS *
39 *******************************/
40
41/*
42 * Check that all tags correspond to the type definition (as given in head).
43 * On return, last_length would contain either a non-negative length of the
44 * value part of the last TLV, or the negative number of expected
45 * "end of content" sequences. The number may only be negative if the
46 * head->last_tag_form is non-zero.
47 */
Lev Walkindc06f6b2004-10-20 15:50:55 +000048asn_dec_rval_t ber_check_tags(
Lev Walkin1d9e8dd2005-12-07 05:46:03 +000049 struct asn_codec_ctx_s *opt_codec_ctx, /* codec options */
50 struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkin1cbd2222004-09-29 13:24:10 +000051 asn_struct_ctx_t *opt_ctx, /* saved decoding context */
Lev Walkin8c3b8542005-03-10 18:52:02 +000052 const void *ptr, size_t size,
Lev Walkinf15320b2004-06-03 03:38:44 +000053 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
Lev Walkin8e8078a2004-09-26 13:10:40 +000054 int last_tag_form, /* {-1,0:1}: any, primitive, constr */
Lev Walkinf15320b2004-06-03 03:38:44 +000055 ber_tlv_len_t *last_length,
Lev Walkin1cbd2222004-09-29 13:24:10 +000056 int *opt_tlv_form /* optional tag form */
57 );
Lev Walkinf15320b2004-06-03 03:38:44 +000058
Lev Walkin21b41ac2005-07-24 09:03:44 +000059#ifdef __cplusplus
60}
61#endif
62
Lev Walkinf15320b2004-06-03 03:38:44 +000063#endif /* _BER_DECODER_H_ */