Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 2 | * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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 | 2864774 | 2017-09-12 11:07:06 -0700 | [diff] [blame] | 18 | * 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 Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 22 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 23 | asn_enc_rval_t der_encode(const struct asn_TYPE_descriptor_s *type_descriptor, |
| 24 | const void *struct_ptr, /* Structure to be encoded */ |
| 25 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 26 | void *app_key /* Arbitrary callback argument */ |
| 27 | ); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 28 | |
Lev Walkin | c4676a8 | 2004-11-16 09:46:00 +0000 | [diff] [blame] | 29 | /* A variant of der_encode() which encodes data into the pre-allocated buffer */ |
| 30 | asn_enc_rval_t der_encode_to_buffer( |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 31 | const struct asn_TYPE_descriptor_s *type_descriptor, |
| 32 | const void *struct_ptr, /* Structure to be encoded */ |
| 33 | void *buffer, /* Pre-allocated buffer */ |
| 34 | size_t buffer_size /* Initial buffer size (maximum) */ |
| 35 | ); |
Lev Walkin | c4676a8 | 2004-11-16 09:46:00 +0000 | [diff] [blame] | 36 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 37 | /* |
| 38 | * Type of the generic DER encoder. |
| 39 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 40 | typedef asn_enc_rval_t(der_type_encoder_f)( |
| 41 | const struct asn_TYPE_descriptor_s *type_descriptor, |
| 42 | const void *struct_ptr, /* Structure to be encoded */ |
| 43 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
| 44 | ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ |
| 45 | void *app_key /* Arbitrary callback argument */ |
| 46 | ); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | /******************************* |
| 50 | * INTERNALLY USEFUL FUNCTIONS * |
| 51 | *******************************/ |
| 52 | |
| 53 | /* |
| 54 | * Write out leading TL[v] sequence according to the type definition. |
| 55 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 56 | ssize_t der_write_tags(const struct asn_TYPE_descriptor_s *type_descriptor, |
| 57 | size_t struct_length, |
| 58 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
| 59 | int last_tag_form, /* {0,!0}: prim, constructed */ |
| 60 | ber_tlv_tag_t tag, |
| 61 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 62 | void *app_key); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 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_ */ |