Moving in e2sim originally from it/test/simulators
[sim/e2-interface.git] / e2sim / ASN1c / der_encoder.h
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 #                                                                            *
5 # Licensed under the Apache License, Version 2.0 (the "License");            *
6 # you may not use this file except in compliance with the License.           *
7 # You may obtain a copy of the License at                                    *
8 #                                                                            *
9 #      http://www.apache.org/licenses/LICENSE-2.0                            *
10 #                                                                            *
11 # Unless required by applicable law or agreed to in writing, software        *
12 # distributed under the License is distributed on an "AS IS" BASIS,          *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
14 # See the License for the specific language governing permissions and        *
15 # limitations under the License.                                             *
16 #                                                                            *
17 ******************************************************************************/
18
19 /*-
20  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21  * Redistribution and modifications are permitted subject to BSD license.
22  */
23 #ifndef _DER_ENCODER_H_
24 #define _DER_ENCODER_H_
25
26 #include <asn_application.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 struct asn_TYPE_descriptor_s;   /* Forward declaration */
33
34 /*
35  * The DER encoder of any type. May be invoked by the application.
36  * Produces DER- and BER-compliant encoding. (DER is a subset of BER).
37  *
38  * NOTE: Use the ber_decode() function (ber_decoder.h) to decode data
39  * produced by der_encode().
40  */
41 asn_enc_rval_t der_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
42                           const void *struct_ptr, /* Structure to be encoded */
43                           asn_app_consume_bytes_f *consume_bytes_cb,
44                           void *app_key /* Arbitrary callback argument */
45 );
46
47 /* A variant of der_encode() which encodes data into the pre-allocated buffer */
48 asn_enc_rval_t der_encode_to_buffer(
49     const struct asn_TYPE_descriptor_s *type_descriptor,
50     const void *struct_ptr, /* Structure to be encoded */
51     void *buffer,           /* Pre-allocated buffer */
52     size_t buffer_size      /* Initial buffer size (maximum) */
53 );
54
55 /*
56  * Type of the generic DER encoder.
57  */
58 typedef asn_enc_rval_t(der_type_encoder_f)(
59     const struct asn_TYPE_descriptor_s *type_descriptor,
60     const void *struct_ptr, /* Structure to be encoded */
61     int tag_mode,           /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
62     ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
63     void *app_key /* Arbitrary callback argument */
64 );
65
66
67 /*******************************
68  * INTERNALLY USEFUL FUNCTIONS *
69  *******************************/
70
71 /*
72  * Write out leading TL[v] sequence according to the type definition.
73  */
74 ssize_t der_write_tags(const struct asn_TYPE_descriptor_s *type_descriptor,
75                        size_t struct_length,
76                        int tag_mode,      /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
77                        int last_tag_form, /* {0,!0}: prim, constructed */
78                        ber_tlv_tag_t tag,
79                        asn_app_consume_bytes_f *consume_bytes_cb,
80                        void *app_key);
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif  /* _DER_ENCODER_H_ */