3 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #ifndef _DER_ENCODER_H_
7 #define _DER_ENCODER_H_
9 #include <asn_application.h>
15 struct asn_TYPE_descriptor_s; /* Forward declaration */
18 * The DER encoder of any type. May be invoked by the application.
19 * Produces DER- and BER-compliant encoding. (DER is a subset of BER).
21 * NOTE: Use the ber_decode() function (ber_decoder.h) to decode data
22 * produced by der_encode().
24 asn_enc_rval_t der_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
25 const void *struct_ptr, /* Structure to be encoded */
26 asn_app_consume_bytes_f *consume_bytes_cb,
27 void *app_key /* Arbitrary callback argument */
30 /* A variant of der_encode() which encodes data into the pre-allocated buffer */
31 asn_enc_rval_t der_encode_to_buffer(
32 const struct asn_TYPE_descriptor_s *type_descriptor,
33 const void *struct_ptr, /* Structure to be encoded */
34 void *buffer, /* Pre-allocated buffer */
35 size_t buffer_size /* Initial buffer size (maximum) */
39 * Type of the generic DER encoder.
41 typedef asn_enc_rval_t(der_type_encoder_f)(
42 const struct asn_TYPE_descriptor_s *type_descriptor,
43 const void *struct_ptr, /* Structure to be encoded */
44 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
45 ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
46 void *app_key /* Arbitrary callback argument */
50 /*******************************
51 * INTERNALLY USEFUL FUNCTIONS *
52 *******************************/
55 * Write out leading TL[v] sequence according to the type definition.
57 ssize_t der_write_tags(const struct asn_TYPE_descriptor_s *type_descriptor,
59 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
60 int last_tag_form, /* {0,!0}: prim, constructed */
62 asn_app_consume_bytes_f *consume_bytes_cb,
69 #endif /* _DER_ENCODER_H_ */