vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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 | |
vlm | d157958 | 2004-09-24 21:00:50 +0000 | [diff] [blame] | 8 | #include <asn_application.h> |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 14 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 15 | |
| 16 | /* |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | * The DER encoder of any type. May be invoked by the application. |
| 18 | */ |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 19 | asn_enc_rval_t der_encode(struct asn_TYPE_descriptor_s *type_descriptor, |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | void *struct_ptr, /* Structure to be encoded */ |
| 21 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 22 | void *app_key /* Arbitrary callback argument */ |
| 23 | ); |
| 24 | |
vlm | cd05d3d | 2004-11-16 09:46:00 +0000 | [diff] [blame] | 25 | /* A variant of der_encode() which encodes data into the pre-allocated buffer */ |
| 26 | asn_enc_rval_t der_encode_to_buffer( |
| 27 | struct asn_TYPE_descriptor_s *type_descriptor, |
| 28 | void *struct_ptr, /* Structure to be encoded */ |
| 29 | void *buffer, /* Pre-allocated buffer */ |
vlm | 18dd82c | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 30 | size_t buffer_size /* Initial buffer size (maximum) */ |
vlm | cd05d3d | 2004-11-16 09:46:00 +0000 | [diff] [blame] | 31 | ); |
| 32 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 33 | /* |
| 34 | * Type of the generic DER encoder. |
| 35 | */ |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 36 | typedef asn_enc_rval_t (der_type_encoder_f)( |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 37 | struct asn_TYPE_descriptor_s *type_descriptor, |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 38 | void *struct_ptr, /* Structure to be encoded */ |
| 39 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
| 40 | ber_tlv_tag_t tag, |
| 41 | asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ |
| 42 | void *app_key /* Arbitrary callback argument */ |
| 43 | ); |
| 44 | |
| 45 | |
| 46 | /******************************* |
| 47 | * INTERNALLY USEFUL FUNCTIONS * |
| 48 | *******************************/ |
| 49 | |
| 50 | /* |
| 51 | * Write out leading TL[v] sequence according to the type definition. |
| 52 | */ |
| 53 | ssize_t der_write_tags( |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 54 | struct asn_TYPE_descriptor_s *type_descriptor, |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 55 | size_t struct_length, |
| 56 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
vlm | 6678cb1 | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 57 | int last_tag_form, /* {0,!0}: prim, constructed */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 58 | ber_tlv_tag_t tag, |
| 59 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 60 | void *app_key |
| 61 | ); |
| 62 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 63 | #ifdef __cplusplus |
| 64 | } |
| 65 | #endif |
| 66 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 67 | #endif /* _DER_ENCODER_H_ */ |