asn_application.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3  * Redistribution and modifications are permitted subject to BSD license.
4  */
5 /*
6  * Application-level ASN.1 callbacks.
7  */
8 #ifndef ASN_APPLICATION_H
9 #define ASN_APPLICATION_H
10 
11 #include "etsi_its_spatem_ts_coding/asn_system.h" /* for platform-dependent types */
12 #include "etsi_its_spatem_ts_coding/asn_codecs.h" /* for ASN.1 codecs specifics */
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /*
20  * A selection of ASN.1 Transfer Syntaxes to use with generalized
21  * encoders and decoders declared further in this .h file.
22  */
24  /* Avoid appearance of a default transfer syntax. */
26  /* Plaintext output (not conforming to any standard), for debugging. */
28  /* Returns a randomly generated structure. */
30  /*
31  * X.690:
32  * BER: Basic Encoding Rules.
33  * DER: Distinguished Encoding Rules.
34  * CER: Canonical Encoding Rules.
35  * DER and CER are more strict variants of BER.
36  */
39  ATS_CER, /* Only decoding is supported */
40  /*
41  * X.696:
42  * OER: Octet Encoding Rules.
43  * CANONICAL-OER is a more strict variant of BASIC-OER.
44  */
47  /*
48  * X.691:
49  * PER: Packed Encoding Rules.
50  * CANONICAL-PER is a more strict variant of BASIC-PER.
51  * NOTE: Produces or consumes a complete encoding (X.691 (08/2015) #11.1).
52  */
57  /*
58  * X.693:
59  * XER: XML Encoding Rules.
60  * CANONICAL-XER is a more strict variant of BASIC-XER.
61  */
64  /*
65  * X.697:
66  * JER: JSON Encoding Rules.
67  * MINIFIED produces a whitespace-free JSON.
68  */
71 };
72 
73 /*
74  * A generic encoder for any supported transfer syntax.
75  * RETURN VALUES:
76  * The (.encoded) field of the return value is REDEFINED to mean the following:
77  * >=0: The computed size of the encoded data. Can exceed the (buffer_size).
78  * -1: Error encoding the structure. See the error code in (errno):
79  * EINVAL: Incorrect parameters to the function, such as NULLs.
80  * ENOENT: Encoding transfer syntax is not defined (for this type).
81  * EBADF: The structure has invalid form or content constraint failed.
82  * The (.failed_type) and (.structure_ptr) MIGHT be set to the appropriate
83  * values at the place of failure, if at all possible.
84  * WARNING: The (.encoded) field of the return value can exceed the buffer_size.
85  * This is similar to snprintf(3) contract which might return values
86  * greater than the buffer size.
87  */
89  const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */
91  const struct asn_TYPE_descriptor_s *type_to_encode,
92  const void *structure_to_encode, void *buffer, size_t buffer_size);
93 
94 /*
95  * A variant of asn_encode_to_buffer() with automatically allocated buffer.
96  * RETURN VALUES:
97  * On success, returns a newly allocated (.buffer) containing the whole message.
98  * The message size is returned in (.result.encoded).
99  * On failure:
100  * (.buffer) is NULL,
101  * (.result.encoded) as in asn_encode_to_buffer(),
102  * The errno codes as in asn_encode_to_buffer(), plus the following:
103  * ENOMEM: Memory allocation failed due to system or internal limits.
104  * The user is responsible for freeing the (.buffer).
105  */
107  void *buffer; /* NULL if failed to encode. */
111  const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */
112  enum asn_transfer_syntax,
113  const struct asn_TYPE_descriptor_s *type_to_encode,
114  const void *structure_to_encode);
115 
116 
117 /*
118  * Generic type of an application-defined callback to return various
119  * types of data to the application.
120  * EXPECTED RETURN VALUES:
121  * -1: Failed to consume bytes. Abort the mission.
122  * Non-negative return values indicate success, and ignored.
123  */
124 typedef int(asn_app_consume_bytes_f)(const void *buffer, size_t size,
125  void *application_specific_key);
126 
127 
128 /*
129  * A generic encoder for any supported transfer syntax.
130  * Returns the comprehensive encoding result descriptor (see asn_codecs.h).
131  * RETURN VALUES:
132  * The negative (.encoded) field of the return values is accompanied with the
133  * following error codes (errno):
134  * EINVAL: Incorrect parameters to the function, such as NULLs.
135  * ENOENT: Encoding transfer syntax is not defined (for this type).
136  * EBADF: The structure has invalid form or content constraint failed.
137  * EIO: The (callback) has returned negative value during encoding.
138  */
140  const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */
141  enum asn_transfer_syntax,
142  const struct asn_TYPE_descriptor_s *type_to_encode,
143  const void *structure_to_encode,
144  asn_app_consume_bytes_f *callback, void *callback_key);
145 
146 
147 /*
148  * A generic decoder for any supported transfer syntax.
149  */
151  const asn_codec_ctx_t *opt_codec_parameters, enum asn_transfer_syntax,
152  const struct asn_TYPE_descriptor_s *type_to_decode,
153  void **structure_ptr, /* Pointer to a target structure's pointer */
154  const void *buffer, /* Data to be decoded */
155  size_t size /* Size of that buffer */
156 );
157 
158 
159 /*
160  * A callback of this type is called whenever constraint validation fails
161  * on some ASN.1 type. See "constraints.h" for more details on constraint
162  * validation.
163  * This callback specifies a descriptor of the ASN.1 type which failed
164  * the constraint check, as well as human readable message on what
165  * particular constraint has failed.
166  */
167 typedef void (asn_app_constraint_failed_f)(void *application_specific_key,
168  const struct asn_TYPE_descriptor_s *type_descriptor_which_failed,
169  const void *structure_which_failed_ptr,
170  const char *error_message_format, ...) CC_PRINTFLIKE(4, 5);
171 
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #include "etsi_its_spatem_ts_coding/constr_TYPE.h" /* for asn_TYPE_descriptor_t */
178 
179 #endif /* ASN_APPLICATION_H */
ATS_BASIC_XER
@ ATS_BASIC_XER
Definition: asn_application.h:62
asn_app_constraint_failed_f
void() asn_app_constraint_failed_f(void *application_specific_key, const struct asn_TYPE_descriptor_s *type_descriptor_which_failed, const void *structure_which_failed_ptr, const char *error_message_format,...) CC_PRINTFLIKE(4
Definition: asn_application.h:167
asn_enc_rval_s
Definition: asn_codecs.h:41
asn_config.h
ATS_ALIGNED_BASIC_PER
@ ATS_ALIGNED_BASIC_PER
Definition: asn_application.h:55
asn_transfer_syntax
asn_transfer_syntax
Definition: asn_application.h:23
ATS_DER
@ ATS_DER
Definition: asn_application.h:38
asn_codecs.h
ATS_INVALID
@ ATS_INVALID
Definition: asn_application.h:25
constr_TYPE.h
ATS_RANDOM
@ ATS_RANDOM
Definition: asn_application.h:29
asn_encode_to_buffer
asn_enc_rval_t asn_encode_to_buffer(const asn_codec_ctx_t *opt_codec_parameters, enum asn_transfer_syntax, const struct asn_TYPE_descriptor_s *type_to_encode, const void *structure_to_encode, void *buffer, size_t buffer_size)
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
CC_PRINTFLIKE
#define CC_PRINTFLIKE(fmt, var)
Definition: asn_system.h:115
asn_encode_to_new_buffer_result_s
Definition: asn_application.h:106
ATS_NONSTANDARD_PLAINTEXT
@ ATS_NONSTANDARD_PLAINTEXT
Definition: asn_application.h:27
asn_encode_to_new_buffer_result_s::result
asn_enc_rval_t result
Definition: asn_application.h:108
ATS_JER
@ ATS_JER
Definition: asn_application.h:69
asn_system.h
ATS_CER
@ ATS_CER
Definition: asn_application.h:39
asn_app_consume_bytes_f
int() asn_app_consume_bytes_f(const void *buffer, size_t size, void *application_specific_key)
Definition: asn_application.h:124
asn_codec_ctx_s
Definition: asn_codecs.h:23
asn_dec_rval_s
Definition: asn_codecs.h:86
asn_encode
asn_enc_rval_t asn_encode(const asn_codec_ctx_t *opt_codec_parameters, enum asn_transfer_syntax, const struct asn_TYPE_descriptor_s *type_to_encode, const void *structure_to_encode, asn_app_consume_bytes_f *callback, void *callback_key)
ATS_UNALIGNED_BASIC_PER
@ ATS_UNALIGNED_BASIC_PER
Definition: asn_application.h:53
asn_encode_to_new_buffer_result_s::buffer
void * buffer
Definition: asn_application.h:107
ATS_CANONICAL_XER
@ ATS_CANONICAL_XER
Definition: asn_application.h:63
ATS_ALIGNED_CANONICAL_PER
@ ATS_ALIGNED_CANONICAL_PER
Definition: asn_application.h:56
asn_encode_to_new_buffer
asn_encode_to_new_buffer_result_t asn_encode_to_new_buffer(const asn_codec_ctx_t *opt_codec_parameters, enum asn_transfer_syntax, const struct asn_TYPE_descriptor_s *type_to_encode, const void *structure_to_encode)
ATS_CANONICAL_OER
@ ATS_CANONICAL_OER
Definition: asn_application.h:46
asn_encode_to_new_buffer_result_t
struct asn_encode_to_new_buffer_result_s asn_encode_to_new_buffer_result_t
ATS_JER_MINIFIED
@ ATS_JER_MINIFIED
Definition: asn_application.h:70
ATS_BER
@ ATS_BER
Definition: asn_application.h:37
ATS_UNALIGNED_CANONICAL_PER
@ ATS_UNALIGNED_CANONICAL_PER
Definition: asn_application.h:54
ATS_BASIC_OER
@ ATS_BASIC_OER
Definition: asn_application.h:45
asn_decode
asn_dec_rval_t asn_decode(const asn_codec_ctx_t *opt_codec_parameters, enum asn_transfer_syntax, const struct asn_TYPE_descriptor_s *type_to_decode, void **structure_ptr, const void *buffer, size_t size)


etsi_its_spatem_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:29:28