Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 5 | #ifndef OER_DECODER_H |
| 6 | #define OER_DECODER_H |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 7 | |
| 8 | #include <asn_application.h> |
Lev Walkin | e7b73c4 | 2017-07-07 10:06:17 -0700 | [diff] [blame] | 9 | #include <oer_support.h> |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
| 16 | struct 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 Walkin | 2864774 | 2017-09-12 11:07:06 -0700 | [diff] [blame] | 21 | * Parses CANONICAL-OER and BASIC-OER. |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 22 | */ |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 23 | asn_dec_rval_t oer_decode(const struct asn_codec_ctx_s *opt_codec_ctx, |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 24 | const struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 25 | 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 Walkin | e7b73c4 | 2017-07-07 10:06:17 -0700 | [diff] [blame] | 33 | typedef asn_dec_rval_t(oer_type_decoder_f)( |
Lev Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 34 | const struct asn_codec_ctx_s *opt_codec_ctx, |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 35 | const struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 36 | const asn_oer_constraints_t *constraints, |
Lev Walkin | e7b73c4 | 2017-07-07 10:06:17 -0700 | [diff] [blame] | 37 | void **struct_ptr, |
| 38 | const void *buf_ptr, |
| 39 | size_t size); |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 40 | |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 41 | /* |
| 42 | * Swallow the Open Type (X.696 (08/2015), #30) into /dev/null. |
| 43 | * RETURN VALUES: |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 44 | * -1: Fatal error deciphering length. |
Lev Walkin | 312795a | 2017-10-17 15:48:34 -0700 | [diff] [blame] | 45 | * 0: More data expected than bufptr contains. |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 46 | * >0: Number of bytes used from bufptr. |
| 47 | */ |
Lev Walkin | 20ea852 | 2017-07-20 14:52:02 +0300 | [diff] [blame] | 48 | ssize_t oer_open_type_skip(const void *bufptr, size_t size); |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 49 | |
| 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 Walkin | afbf2a9 | 2017-09-12 23:30:27 -0700 | [diff] [blame] | 57 | ssize_t oer_open_type_get(const asn_codec_ctx_t *opt_codec_ctx, |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 58 | const struct asn_TYPE_descriptor_s *td, |
Lev Walkin | a5972be | 2017-09-29 23:15:58 -0700 | [diff] [blame] | 59 | const asn_oer_constraints_t *constraints, |
| 60 | void **struct_ptr, const void *bufptr, size_t size); |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 61 | |
Lev Walkin | b5b524b | 2017-10-13 03:14:03 -0700 | [diff] [blame] | 62 | /* |
| 63 | * Length-prefixed buffer decoding for primitive types. |
| 64 | */ |
| 65 | oer_type_decoder_f oer_decode_primitive; |
| 66 | |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 67 | |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 68 | #ifdef __cplusplus |
| 69 | } |
| 70 | #endif |
| 71 | |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 72 | #endif /* OER_DECODER_H */ |