blob: 5fea20cea4f1f67af7336ea428a64f7132074b72 [file] [log] [blame]
Lev Walkin52559a22004-09-24 20:58:37 +00001/*-
Lev Walkin1eded352006-07-13 11:19:01 +00002 * Copyright (c) 2004, 2006 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkin52559a22004-09-24 20:58:37 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
5/*
Lev Walkin1eded352006-07-13 11:19:01 +00006 * Application-level ASN.1 callbacks.
Lev Walkin52559a22004-09-24 20:58:37 +00007 */
Lev Walkinc6cac8e2016-03-14 02:57:07 -07008#ifndef ASN_APPLICATION_H
9#define ASN_APPLICATION_H
Lev Walkin52559a22004-09-24 20:58:37 +000010
Lev Walkin1eded352006-07-13 11:19:01 +000011#include "asn_system.h" /* for platform-dependent types */
12#include "asn_codecs.h" /* for ASN.1 codecs specifics */
Lev Walkin52559a22004-09-24 20:58:37 +000013
Lev Walkin21b41ac2005-07-24 09:03:44 +000014#ifdef __cplusplus
15extern "C" {
16#endif
17
Lev Walkin52559a22004-09-24 20:58:37 +000018/*
Lev Walkin6d46bc32017-09-12 21:34:00 -070019 * A selection of ASN.1 Transfer Syntaxes to use with generalized
20 * encoder and decoders declared further in this .h file.
21 */
22enum asn_transfer_syntax {
23 /* Avoid appearance of a default transfer syntax. */
24 ATS_INVALID = 0,
25 /* Plaintext output, useful for debugging. */
26 ATS_NONSTANDARD_PLAINTEXT,
27 /*
28 * X.690:
29 * BER: Basic Encoding Rules.
30 * DER: Distinguished Encoding Rules.
31 * CER: Canonical Encoding Rules.
32 * DER and CER are more strict variants of BER.
33 */
34 ATS_BER,
35 ATS_DER,
36 ATS_CER, /* Only decoding is supported */
37 /*
38 * X.696:
39 * OER: Octet Encoding Rules.
40 * CANONICAL-OER is a more strict variant of BASIC-OER.
41 */
42 ATS_BASIC_OER,
43 ATS_CANONICAL_OER,
44 /*
45 * X.691:
46 * PER: Packed Encoding Rules.
47 * CANONICAL-PER is a more strict variant of BASIC-PER.
48 * NOTE: Produces or consumes a complete encoding (X.691 (08/2015) #11.1).
49 */
50 ATS_UNALIGNED_BASIC_PER,
51 ATS_UNALIGNED_CANONICAL_PER,
52 /*
53 * X.693:
54 * XER: XML Encoding Rules.
55 * CANONICAL-XER is a more strict variant of BASIC-XER.
56 */
57 ATS_BASIC_XER,
58 ATS_CANONICAL_XER,
59};
60
61/*
62 * A generic encoder for any supported transfer syntax.
63 * RETURN VALUES:
64 * The (.encoded) field of the return value is REDEFINED to mean the following:
65 * >=0: The computed size of the encoded data. Can exceed the (buffer_size).
66 * -1: Error encoding the structure. See the error code in (errno):
67 * EINVAL: Incorrect parameters to the function, such as NULLs.
68 * ENOENT: Encoding transfer syntax is not defined (for this type).
69 * EBADF: The structure has invalid form or content constraint failed.
70 * The (.failed_type) and (.structure_ptr) MIGHT be set to the appropriate
71 * values at the place of failure, if at all possible.
72 * WARNING: The (.encoded) field of the return value can exceed the buffer_size.
73 * This is similar to snprintf(3) contract which might return values
74 * greater than the buffer size.
75 */
76asn_enc_rval_t asn_encode_to_buffer(
77 const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */
78 enum asn_transfer_syntax,
79 struct asn_TYPE_descriptor_s *type_to_encode,
80 void *structure_to_encode,
81 void *buffer, size_t buffer_size);
82
83
84/*
Lev Walkin52559a22004-09-24 20:58:37 +000085 * Generic type of an application-defined callback to return various
86 * types of data to the application.
87 * EXPECTED RETURN VALUES:
88 * -1: Failed to consume bytes. Abort the mission.
89 * Non-negative return values indicate success, and ignored.
90 */
Lev Walkin6d46bc32017-09-12 21:34:00 -070091typedef int(asn_app_consume_bytes_f)(const void *buffer, size_t size,
92 void *application_specific_key);
93
94
95/*
96 * A generic encoder for any supported transfer syntax.
97 * Returns the comprehensive encoding result descriptor (see asn_codecs.h).
98 * RETURN VALUES:
99 * The negative (.encoded) field of the return values is accompanied with the
100 * following error codes (errno):
101 * EINVAL: Incorrect parameters to the function, such as NULLs.
102 * ENOENT: Encoding transfer syntax is not defined (for this type).
103 * EBADF: The structure has invalid form or content constraint failed.
104 * EIO: The (callback) has returned negative value during encoding.
105 */
106asn_enc_rval_t asn_encode(
107 const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */
108 enum asn_transfer_syntax,
109 struct asn_TYPE_descriptor_s *type_to_encode,
110 void *structure_to_encode,
111 asn_app_consume_bytes_f *callback, void *callback_key);
112
113
Lev Walkine8bbe932017-09-12 23:06:52 -0700114/*
115 * A generic decoder for any supported transfer syntax.
116 */
117asn_dec_rval_t asn_decode(
118 const asn_codec_ctx_t *opt_codec_parameters, enum asn_transfer_syntax,
119 struct asn_TYPE_descriptor_s *type_to_decode,
120 void **structure_ptr, /* Pointer to a target structure's pointer */
121 const void *buffer, /* Data to be decoded */
122 size_t size /* Size of that buffer */
123 );
124
Lev Walkin52559a22004-09-24 20:58:37 +0000125
Lev Walkin1eded352006-07-13 11:19:01 +0000126/*
127 * A callback of this type is called whenever constraint validation fails
128 * on some ASN.1 type. See "constraints.h" for more details on constraint
129 * validation.
130 * This callback specifies a descriptor of the ASN.1 type which failed
131 * the constraint check, as well as human readable message on what
132 * particular constraint has failed.
133 */
134typedef void (asn_app_constraint_failed_f)(void *application_specific_key,
135 struct asn_TYPE_descriptor_s *type_descriptor_which_failed,
136 const void *structure_which_failed_ptr,
Lev Walkin3f6afc12006-09-15 18:52:36 +0000137 const char *error_message_format, ...) GCC_PRINTFLIKE(4, 5);
Lev Walkin52559a22004-09-24 20:58:37 +0000138
Lev Walkin6d46bc32017-09-12 21:34:00 -0700139
Lev Walkin21b41ac2005-07-24 09:03:44 +0000140#ifdef __cplusplus
141}
142#endif
143
Lev Walkin1eded352006-07-13 11:19:01 +0000144#include "constr_TYPE.h" /* for asn_TYPE_descriptor_t */
145
Lev Walkinc6cac8e2016-03-14 02:57:07 -0700146#endif /* ASN_APPLICATION_H */