--- /dev/null
+/*-\r
+ * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.\r
+ * Redistribution and modifications are permitted subject to BSD license.\r
+ */\r
+/*\r
+ * Application-level ASN.1 callbacks.\r
+ */\r
+#ifndef ASN_APPLICATION_H\r
+#define ASN_APPLICATION_H\r
+\r
+#include "asn_system.h" /* for platform-dependent types */\r
+#include "asn_codecs.h" /* for ASN.1 codecs specifics */\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*\r
+ * A selection of ASN.1 Transfer Syntaxes to use with generalized\r
+ * encoders and decoders declared further in this .h file.\r
+ */\r
+enum asn_transfer_syntax {\r
+ /* Avoid appearance of a default transfer syntax. */\r
+ ATS_INVALID = 0,\r
+ /* Plaintext output (not conforming to any standard), for debugging. */\r
+ ATS_NONSTANDARD_PLAINTEXT,\r
+ /* Returns a randomly generated structure. */\r
+ ATS_RANDOM,\r
+ /*\r
+ * X.690:\r
+ * BER: Basic Encoding Rules.\r
+ * DER: Distinguished Encoding Rules.\r
+ * CER: Canonical Encoding Rules.\r
+ * DER and CER are more strict variants of BER.\r
+ */\r
+ ATS_BER,\r
+ ATS_DER,\r
+ ATS_CER, /* Only decoding is supported */\r
+ /*\r
+ * X.696:\r
+ * OER: Octet Encoding Rules.\r
+ * CANONICAL-OER is a more strict variant of BASIC-OER.\r
+ */\r
+ ATS_BASIC_OER,\r
+ ATS_CANONICAL_OER,\r
+ /*\r
+ * X.691:\r
+ * PER: Packed Encoding Rules.\r
+ * CANONICAL-PER is a more strict variant of BASIC-PER.\r
+ * NOTE: Produces or consumes a complete encoding (X.691 (08/2015) #11.1).\r
+ */\r
+ ATS_UNALIGNED_BASIC_PER,\r
+ ATS_UNALIGNED_CANONICAL_PER,\r
+ ATS_ALIGNED_BASIC_PER,\r
+ ATS_ALIGNED_CANONICAL_PER,\r
+ /*\r
+ * X.693:\r
+ * XER: XML Encoding Rules.\r
+ * CANONICAL-XER is a more strict variant of BASIC-XER.\r
+ */\r
+ ATS_BASIC_XER,\r
+ ATS_CANONICAL_XER\r
+};\r
+\r
+/*\r
+ * A generic encoder for any supported transfer syntax.\r
+ * RETURN VALUES:\r
+ * The (.encoded) field of the return value is REDEFINED to mean the following:\r
+ * >=0: The computed size of the encoded data. Can exceed the (buffer_size).\r
+ * -1: Error encoding the structure. See the error code in (errno):\r
+ * EINVAL: Incorrect parameters to the function, such as NULLs.\r
+ * ENOENT: Encoding transfer syntax is not defined (for this type).\r
+ * EBADF: The structure has invalid form or content constraint failed.\r
+ * The (.failed_type) and (.structure_ptr) MIGHT be set to the appropriate\r
+ * values at the place of failure, if at all possible.\r
+ * WARNING: The (.encoded) field of the return value can exceed the buffer_size.\r
+ * This is similar to snprintf(3) contract which might return values\r
+ * greater than the buffer size.\r
+ */\r
+asn_enc_rval_t asn_encode_to_buffer(\r
+ const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */\r
+ enum asn_transfer_syntax,\r
+ const struct asn_TYPE_descriptor_s *type_to_encode,\r
+ const void *structure_to_encode, void *buffer, size_t buffer_size);\r
+\r
+/*\r
+ * A variant of asn_encode_to_buffer() with automatically allocated buffer.\r
+ * RETURN VALUES:\r
+ * On success, returns a newly allocated (.buffer) containing the whole message.\r
+ * The message size is returned in (.result.encoded).\r
+ * On failure:\r
+ * (.buffer) is NULL,\r
+ * (.result.encoded) as in asn_encode_to_buffer(),\r
+ * The errno codes as in asn_encode_to_buffer(), plus the following:\r
+ * ENOMEM: Memory allocation failed due to system or internal limits.\r
+ * The user is responsible for freeing the (.buffer).\r
+ */\r
+typedef struct asn_encode_to_new_buffer_result_s {\r
+ void *buffer; /* NULL if failed to encode. */\r
+ asn_enc_rval_t result;\r
+} asn_encode_to_new_buffer_result_t;\r
+asn_encode_to_new_buffer_result_t asn_encode_to_new_buffer(\r
+ const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */\r
+ enum asn_transfer_syntax,\r
+ const struct asn_TYPE_descriptor_s *type_to_encode,\r
+ const void *structure_to_encode);\r
+\r
+\r
+/*\r
+ * Generic type of an application-defined callback to return various\r
+ * types of data to the application.\r
+ * EXPECTED RETURN VALUES:\r
+ * -1: Failed to consume bytes. Abort the mission.\r
+ * Non-negative return values indicate success, and ignored.\r
+ */\r
+typedef int(asn_app_consume_bytes_f)(const void *buffer, size_t size,\r
+ void *application_specific_key);\r
+\r
+\r
+/*\r
+ * A generic encoder for any supported transfer syntax.\r
+ * Returns the comprehensive encoding result descriptor (see asn_codecs.h).\r
+ * RETURN VALUES:\r
+ * The negative (.encoded) field of the return values is accompanied with the\r
+ * following error codes (errno):\r
+ * EINVAL: Incorrect parameters to the function, such as NULLs.\r
+ * ENOENT: Encoding transfer syntax is not defined (for this type).\r
+ * EBADF: The structure has invalid form or content constraint failed.\r
+ * EIO: The (callback) has returned negative value during encoding.\r
+ */\r
+asn_enc_rval_t asn_encode(\r
+ const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */\r
+ enum asn_transfer_syntax,\r
+ const struct asn_TYPE_descriptor_s *type_to_encode,\r
+ const void *structure_to_encode,\r
+ asn_app_consume_bytes_f *callback, void *callback_key);\r
+\r
+\r
+/*\r
+ * A generic decoder for any supported transfer syntax.\r
+ */\r
+asn_dec_rval_t asn_decode(\r
+ const asn_codec_ctx_t *opt_codec_parameters, enum asn_transfer_syntax,\r
+ const struct asn_TYPE_descriptor_s *type_to_decode,\r
+ void **structure_ptr, /* Pointer to a target structure's pointer */\r
+ const void *buffer, /* Data to be decoded */\r
+ size_t size /* Size of that buffer */\r
+);\r
+\r
+\r
+/*\r
+ * A callback of this type is called whenever constraint validation fails\r
+ * on some ASN.1 type. See "constraints.h" for more details on constraint\r
+ * validation.\r
+ * This callback specifies a descriptor of the ASN.1 type which failed\r
+ * the constraint check, as well as human readable message on what\r
+ * particular constraint has failed.\r
+ */\r
+typedef void (asn_app_constraint_failed_f)(void *application_specific_key,\r
+ const struct asn_TYPE_descriptor_s *type_descriptor_which_failed,\r
+ const void *structure_which_failed_ptr,\r
+ const char *error_message_format, ...) CC_PRINTFLIKE(4, 5);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#include "constr_TYPE.h" /* for asn_TYPE_descriptor_t */\r
+\r
+#endif /* ASN_APPLICATION_H */\r