blob: 68b9d5cefd76777a177f5dd9971669f0c8767dd2 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
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
Lev Walkin11c3e172004-09-24 21:00:50 +00008#include <asn_application.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00009
Lev Walkin21b41ac2005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
Lev Walkin5e033762004-09-29 13:26:15 +000014struct asn_TYPE_descriptor_s; /* Forward declaration */
Lev Walkinf15320b2004-06-03 03:38:44 +000015
16/*
Lev Walkinf15320b2004-06-03 03:38:44 +000017 * The DER encoder of any type. May be invoked by the application.
Lev Walkin28647742017-09-12 11:07:06 -070018 * Produces DER- and BER-compliant encoding. (DER is a subset of BER).
19 *
20 * NOTE: Use the ber_decode() function (ber_decoder.h) to decode data
21 * produced by der_encode().
Lev Walkinf15320b2004-06-03 03:38:44 +000022 */
Lev Walkin5e033762004-09-29 13:26:15 +000023asn_enc_rval_t der_encode(struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000024 void *struct_ptr, /* Structure to be encoded */
25 asn_app_consume_bytes_f *consume_bytes_cb,
26 void *app_key /* Arbitrary callback argument */
27 );
28
Lev Walkinc4676a82004-11-16 09:46:00 +000029/* A variant of der_encode() which encodes data into the pre-allocated buffer */
30asn_enc_rval_t der_encode_to_buffer(
31 struct asn_TYPE_descriptor_s *type_descriptor,
32 void *struct_ptr, /* Structure to be encoded */
33 void *buffer, /* Pre-allocated buffer */
Lev Walkin523de9e2006-08-18 01:34:18 +000034 size_t buffer_size /* Initial buffer size (maximum) */
Lev Walkinc4676a82004-11-16 09:46:00 +000035 );
36
Lev Walkinf15320b2004-06-03 03:38:44 +000037/*
38 * Type of the generic DER encoder.
39 */
Lev Walkina9cc46e2004-09-22 16:06:28 +000040typedef asn_enc_rval_t (der_type_encoder_f)(
Lev Walkin5e033762004-09-29 13:26:15 +000041 struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000042 void *struct_ptr, /* Structure to be encoded */
43 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
44 ber_tlv_tag_t tag,
45 asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
46 void *app_key /* Arbitrary callback argument */
47 );
48
49
50/*******************************
51 * INTERNALLY USEFUL FUNCTIONS *
52 *******************************/
53
54/*
55 * Write out leading TL[v] sequence according to the type definition.
56 */
57ssize_t der_write_tags(
Lev Walkin5e033762004-09-29 13:26:15 +000058 struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkinf15320b2004-06-03 03:38:44 +000059 size_t struct_length,
60 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
Lev Walkin8e8078a2004-09-26 13:10:40 +000061 int last_tag_form, /* {0,!0}: prim, constructed */
Lev Walkinf15320b2004-06-03 03:38:44 +000062 ber_tlv_tag_t tag,
63 asn_app_consume_bytes_f *consume_bytes_cb,
64 void *app_key
65 );
66
Lev Walkin21b41ac2005-07-24 09:03:44 +000067#ifdef __cplusplus
68}
69#endif
70
Lev Walkinf15320b2004-06-03 03:38:44 +000071#endif /* _DER_ENCODER_H_ */