]> git.stg.codes - stg.git/blob - libs/smux/include/stg/der_encoder.h
61431c6dbdc87e98de8b7804d438476bca86caa5
[stg.git] / libs / smux / include / stg / der_encoder.h
1 /*-
2  * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3  * Redistribution and modifications are permitted subject to BSD license.
4  */
5 #ifndef _DER_ENCODER_H_
6 #define _DER_ENCODER_H_
7
8 #include <asn_application.h>
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 struct asn_TYPE_descriptor_s;   /* Forward declaration */
15
16 /*
17  * The DER encoder of any type. May be invoked by the application.
18  * The ber_decode() function (ber_decoder.h) is an opposite of der_encode().
19  */
20 asn_enc_rval_t der_encode(struct asn_TYPE_descriptor_s *type_descriptor,
21                 void *struct_ptr,       /* Structure to be encoded */
22                 asn_app_consume_bytes_f *consume_bytes_cb,
23                 void *app_key           /* Arbitrary callback argument */
24         );
25
26 /* A variant of der_encode() which encodes data into the pre-allocated buffer */
27 asn_enc_rval_t der_encode_to_buffer(
28                 struct asn_TYPE_descriptor_s *type_descriptor,
29                 void *struct_ptr,       /* Structure to be encoded */
30                 void *buffer,           /* Pre-allocated buffer */
31                 size_t buffer_size      /* Initial buffer size (maximum) */
32         );
33
34 /*
35  * Type of the generic DER encoder.
36  */
37 typedef asn_enc_rval_t (der_type_encoder_f)(
38                 struct asn_TYPE_descriptor_s *type_descriptor,
39                 void *struct_ptr,       /* Structure to be encoded */
40                 int tag_mode,           /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
41                 ber_tlv_tag_t tag,
42                 asn_app_consume_bytes_f *consume_bytes_cb,      /* Callback */
43                 void *app_key           /* Arbitrary callback argument */
44         );
45
46
47 /*******************************
48  * INTERNALLY USEFUL FUNCTIONS *
49  *******************************/
50
51 /*
52  * Write out leading TL[v] sequence according to the type definition.
53  */
54 ssize_t der_write_tags(
55                 struct asn_TYPE_descriptor_s *type_descriptor,
56                 size_t struct_length,
57                 int tag_mode,           /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
58                 int last_tag_form,      /* {0,!0}: prim, constructed */
59                 ber_tlv_tag_t tag,
60                 asn_app_consume_bytes_f *consume_bytes_cb,
61                 void *app_key
62         );
63
64 #ifdef __cplusplus
65 }
66 #endif
67
68 #endif  /* _DER_ENCODER_H_ */