blob: 40992e9480ec37b7ffc27cdd2ab74bf4148619f0 [file] [log] [blame]
Lev Walkincc159472017-07-06 08:26:36 -07001/*
2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
Lev Walkind88bea92017-07-20 11:21:30 +03005#ifndef OER_DECODER_H
6#define OER_DECODER_H
Lev Walkincc159472017-07-06 08:26:36 -07007
8#include <asn_application.h>
Lev Walkine7b73c42017-07-07 10:06:17 -07009#include <oer_support.h>
Lev Walkincc159472017-07-06 08:26:36 -070010
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15struct asn_TYPE_descriptor_s; /* Forward declaration */
16struct asn_codec_ctx_s; /* Forward declaration */
17
18/*
19 * The Octet Encoding Rules (OER, X.696 08/2015) decoder for any given type.
20 * This function may be invoked directly by the application.
Lev Walkin28647742017-09-12 11:07:06 -070021 * Parses CANONICAL-OER and BASIC-OER.
Lev Walkincc159472017-07-06 08:26:36 -070022 */
Lev Walkinafbf2a92017-09-12 23:30:27 -070023asn_dec_rval_t oer_decode(const struct asn_codec_ctx_s *opt_codec_ctx,
Lev Walkin20696a42017-10-17 21:27:33 -070024 const struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkincc159472017-07-06 08:26:36 -070025 void **struct_ptr, /* Pointer to a target structure's pointer */
26 const void *buffer, /* Data to be decoded */
27 size_t size /* Size of that buffer */
28 );
29
30/*
31 * Type of generic function which decodes the byte stream into the structure.
32 */
Lev Walkine7b73c42017-07-07 10:06:17 -070033typedef asn_dec_rval_t(oer_type_decoder_f)(
Lev Walkinafbf2a92017-09-12 23:30:27 -070034 const struct asn_codec_ctx_s *opt_codec_ctx,
Lev Walkin20696a42017-10-17 21:27:33 -070035 const struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkin494fb702017-08-07 20:07:00 -070036 const asn_oer_constraints_t *constraints,
Lev Walkine7b73c42017-07-07 10:06:17 -070037 void **struct_ptr,
38 const void *buf_ptr,
39 size_t size);
Lev Walkincc159472017-07-06 08:26:36 -070040
Lev Walkind88bea92017-07-20 11:21:30 +030041/*
42 * Swallow the Open Type (X.696 (08/2015), #30) into /dev/null.
43 * RETURN VALUES:
Lev Walkind88bea92017-07-20 11:21:30 +030044 * -1: Fatal error deciphering length.
Lev Walkin312795a2017-10-17 15:48:34 -070045 * 0: More data expected than bufptr contains.
Lev Walkind88bea92017-07-20 11:21:30 +030046 * >0: Number of bytes used from bufptr.
47 */
Lev Walkin20ea8522017-07-20 14:52:02 +030048ssize_t oer_open_type_skip(const void *bufptr, size_t size);
Lev Walkind88bea92017-07-20 11:21:30 +030049
50/*
51 * Read the Open Type (X.696 (08/2015), #30).
52 * RETURN VALUES:
53 * 0: More data expected than bufptr contains.
54 * -1: Fatal error deciphering length.
55 * >0: Number of bytes used from bufptr.
56 */
Lev Walkinafbf2a92017-09-12 23:30:27 -070057ssize_t oer_open_type_get(const asn_codec_ctx_t *opt_codec_ctx,
Lev Walkin20696a42017-10-17 21:27:33 -070058 const struct asn_TYPE_descriptor_s *td,
Lev Walkina5972be2017-09-29 23:15:58 -070059 const asn_oer_constraints_t *constraints,
60 void **struct_ptr, const void *bufptr, size_t size);
Lev Walkind88bea92017-07-20 11:21:30 +030061
Lev Walkinb5b524b2017-10-13 03:14:03 -070062/*
63 * Length-prefixed buffer decoding for primitive types.
64 */
65oer_type_decoder_f oer_decode_primitive;
66
Lev Walkind88bea92017-07-20 11:21:30 +030067
Lev Walkincc159472017-07-06 08:26:36 -070068#ifdef __cplusplus
69}
70#endif
71
Lev Walkind88bea92017-07-20 11:21:30 +030072#endif /* OER_DECODER_H */