Lev Walkin | 52559a2 | 2004-09-24 20:58:37 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | 07906c7 | 2017-09-13 01:36:33 -0700 | [diff] [blame] | 2 | * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved. |
Lev Walkin | 52559a2 | 2004-09-24 20:58:37 +0000 | [diff] [blame] | 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | /* |
Lev Walkin | 1eded35 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 6 | * Application-level ASN.1 callbacks. |
Lev Walkin | 52559a2 | 2004-09-24 20:58:37 +0000 | [diff] [blame] | 7 | */ |
Lev Walkin | c6cac8e | 2016-03-14 02:57:07 -0700 | [diff] [blame] | 8 | #ifndef ASN_APPLICATION_H |
| 9 | #define ASN_APPLICATION_H |
Lev Walkin | 52559a2 | 2004-09-24 20:58:37 +0000 | [diff] [blame] | 10 | |
Lev Walkin | 1eded35 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 11 | #include "asn_system.h" /* for platform-dependent types */ |
| 12 | #include "asn_codecs.h" /* for ASN.1 codecs specifics */ |
Lev Walkin | 52559a2 | 2004-09-24 20:58:37 +0000 | [diff] [blame] | 13 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
Lev Walkin | 52559a2 | 2004-09-24 20:58:37 +0000 | [diff] [blame] | 18 | /* |
Lev Walkin | 6d46bc3 | 2017-09-12 21:34:00 -0700 | [diff] [blame] | 19 | * A selection of ASN.1 Transfer Syntaxes to use with generalized |
Lev Walkin | 07906c7 | 2017-09-13 01:36:33 -0700 | [diff] [blame] | 20 | * encoders and decoders declared further in this .h file. |
Lev Walkin | 6d46bc3 | 2017-09-12 21:34:00 -0700 | [diff] [blame] | 21 | */ |
| 22 | enum 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, |
Lev Walkin | dfbff61 | 2017-09-13 21:07:00 +0000 | [diff] [blame] | 58 | ATS_CANONICAL_XER |
Lev Walkin | 6d46bc3 | 2017-09-12 21:34:00 -0700 | [diff] [blame] | 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 | */ |
| 76 | asn_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 Walkin | 52559a2 | 2004-09-24 20:58:37 +0000 | [diff] [blame] | 85 | * 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 Walkin | 6d46bc3 | 2017-09-12 21:34:00 -0700 | [diff] [blame] | 91 | typedef 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 | */ |
| 106 | asn_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 Walkin | e8bbe93 | 2017-09-12 23:06:52 -0700 | [diff] [blame] | 114 | /* |
| 115 | * A generic decoder for any supported transfer syntax. |
| 116 | */ |
| 117 | asn_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 Walkin | 52559a2 | 2004-09-24 20:58:37 +0000 | [diff] [blame] | 125 | |
Lev Walkin | 1eded35 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 126 | /* |
| 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 | */ |
| 134 | typedef 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 Walkin | 3f6afc1 | 2006-09-15 18:52:36 +0000 | [diff] [blame] | 137 | const char *error_message_format, ...) GCC_PRINTFLIKE(4, 5); |
Lev Walkin | 52559a2 | 2004-09-24 20:58:37 +0000 | [diff] [blame] | 138 | |
Lev Walkin | 6d46bc3 | 2017-09-12 21:34:00 -0700 | [diff] [blame] | 139 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 140 | #ifdef __cplusplus |
| 141 | } |
| 142 | #endif |
| 143 | |
Lev Walkin | 1eded35 | 2006-07-13 11:19:01 +0000 | [diff] [blame] | 144 | #include "constr_TYPE.h" /* for asn_TYPE_descriptor_t */ |
| 145 | |
Lev Walkin | c6cac8e | 2016-03-14 02:57:07 -0700 | [diff] [blame] | 146 | #endif /* ASN_APPLICATION_H */ |