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 | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 10 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 11 | |
| 12 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 13 | * The DER encoder of any type. May be invoked by the application. |
| 14 | */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 15 | 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] | 16 | void *struct_ptr, /* Structure to be encoded */ |
| 17 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 18 | void *app_key /* Arbitrary callback argument */ |
| 19 | ); |
| 20 | |
Lev Walkin | c4676a8 | 2004-11-16 09:46:00 +0000 | [diff] [blame] | 21 | /* A variant of der_encode() which encodes data into the pre-allocated buffer */ |
| 22 | asn_enc_rval_t der_encode_to_buffer( |
| 23 | struct asn_TYPE_descriptor_s *type_descriptor, |
| 24 | void *struct_ptr, /* Structure to be encoded */ |
| 25 | void *buffer, /* Pre-allocated buffer */ |
| 26 | size_t *buffer_size /* Initial buffer size (max) */ |
| 27 | ); |
| 28 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 29 | /* |
| 30 | * Type of the generic DER encoder. |
| 31 | */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 32 | typedef asn_enc_rval_t (der_type_encoder_f)( |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 33 | struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 34 | void *struct_ptr, /* Structure to be encoded */ |
| 35 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
| 36 | ber_tlv_tag_t tag, |
| 37 | asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ |
| 38 | void *app_key /* Arbitrary callback argument */ |
| 39 | ); |
| 40 | |
| 41 | |
| 42 | /******************************* |
| 43 | * INTERNALLY USEFUL FUNCTIONS * |
| 44 | *******************************/ |
| 45 | |
| 46 | /* |
| 47 | * Write out leading TL[v] sequence according to the type definition. |
| 48 | */ |
| 49 | ssize_t der_write_tags( |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 50 | struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 51 | size_t struct_length, |
| 52 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 53 | int last_tag_form, /* {0,!0}: prim, constructed */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 54 | ber_tlv_tag_t tag, |
| 55 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 56 | void *app_key |
| 57 | ); |
| 58 | |
| 59 | #endif /* _DER_ENCODER_H_ */ |