blob: 61431c6dbdc87e98de8b7804d438476bca86caa5 [file] [log] [blame]
vlmfa67ddc2004-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
vlmd1579582004-09-24 21:00:50 +00008#include <asn_application.h>
vlmfa67ddc2004-06-03 03:38:44 +00009
vlm3a417582005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
vlmef6355b2004-09-29 13:26:15 +000014struct asn_TYPE_descriptor_s; /* Forward declaration */
vlmfa67ddc2004-06-03 03:38:44 +000015
16/*
vlmfa67ddc2004-06-03 03:38:44 +000017 * The DER encoder of any type. May be invoked by the application.
vlmb8bdf5f2007-05-30 17:42:00 +000018 * The ber_decode() function (ber_decoder.h) is an opposite of der_encode().
vlmfa67ddc2004-06-03 03:38:44 +000019 */
vlmef6355b2004-09-29 13:26:15 +000020asn_enc_rval_t der_encode(struct asn_TYPE_descriptor_s *type_descriptor,
vlmfa67ddc2004-06-03 03:38:44 +000021 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
vlmcd05d3d2004-11-16 09:46:00 +000026/* A variant of der_encode() which encodes data into the pre-allocated buffer */
27asn_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 */
vlm18dd82c2006-08-18 01:34:18 +000031 size_t buffer_size /* Initial buffer size (maximum) */
vlmcd05d3d2004-11-16 09:46:00 +000032 );
33
vlmfa67ddc2004-06-03 03:38:44 +000034/*
35 * Type of the generic DER encoder.
36 */
vlm39ba4c42004-09-22 16:06:28 +000037typedef asn_enc_rval_t (der_type_encoder_f)(
vlmef6355b2004-09-29 13:26:15 +000038 struct asn_TYPE_descriptor_s *type_descriptor,
vlmfa67ddc2004-06-03 03:38:44 +000039 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 */
54ssize_t der_write_tags(
vlmef6355b2004-09-29 13:26:15 +000055 struct asn_TYPE_descriptor_s *type_descriptor,
vlmfa67ddc2004-06-03 03:38:44 +000056 size_t struct_length,
57 int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
vlm6678cb12004-09-26 13:10:40 +000058 int last_tag_form, /* {0,!0}: prim, constructed */
vlmfa67ddc2004-06-03 03:38:44 +000059 ber_tlv_tag_t tag,
60 asn_app_consume_bytes_f *consume_bytes_cb,
61 void *app_key
62 );
63
vlm3a417582005-07-24 09:03:44 +000064#ifdef __cplusplus
65}
66#endif
67
vlmfa67ddc2004-06-03 03:38:44 +000068#endif /* _DER_ENCODER_H_ */