Lev Walkin | f15320b | 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 | |
Lev Walkin | 11c3e17 | 2004-09-24 21:00:50 +0000 | [diff] [blame] | 8 | #include <asn_application.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 14 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 15 | |
| 16 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | * The DER encoder of any type. May be invoked by the application. |
Lev Walkin | c73eea5 | 2007-05-30 17:42:00 +0000 | [diff] [blame] | 18 | * The ber_decode() function (ber_decoder.h) is an opposite of der_encode(). |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 19 | */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 20 | asn_enc_rval_t der_encode(struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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 | |
Lev Walkin | c4676a8 | 2004-11-16 09:46:00 +0000 | [diff] [blame] | 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 */ |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 31 | size_t buffer_size /* Initial buffer size (maximum) */ |
Lev Walkin | c4676a8 | 2004-11-16 09:46:00 +0000 | [diff] [blame] | 32 | ); |
| 33 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 34 | /* |
| 35 | * Type of the generic DER encoder. |
| 36 | */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 37 | typedef asn_enc_rval_t (der_type_encoder_f)( |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 38 | struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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( |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 55 | struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 56 | size_t struct_length, |
| 57 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 58 | int last_tag_form, /* {0,!0}: prim, constructed */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 59 | ber_tlv_tag_t tag, |
| 60 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 61 | void *app_key |
| 62 | ); |
| 63 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 64 | #ifdef __cplusplus |
| 65 | } |
| 66 | #endif |
| 67 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 68 | #endif /* _DER_ENCODER_H_ */ |