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 | |
| 8 | #include <constr_TYPE.h> |
| 9 | |
| 10 | struct asn1_TYPE_descriptor_s; /* Forward declaration */ |
| 11 | |
| 12 | /* |
| 13 | * Type of the return value of the der_encode function. |
| 14 | */ |
| 15 | typedef struct der_enc_rval_s { |
| 16 | /* |
| 17 | * Number of bytes encoded. |
| 18 | * -1 indicates failure to encode the structure. |
| 19 | * In this case, the members below this one are meaningful. |
| 20 | */ |
| 21 | ssize_t encoded; |
| 22 | |
| 23 | /* |
| 24 | * Members meaningful when (encoded == -1), for post-mortem analysis. |
| 25 | */ |
| 26 | |
| 27 | /* Type which cannot be encoded */ |
| 28 | struct asn1_TYPE_descriptor_s *failed_type; |
| 29 | |
| 30 | /* Pointer to the structure of that type */ |
| 31 | void *structure_ptr; |
| 32 | } der_enc_rval_t; |
| 33 | |
| 34 | |
| 35 | /* |
| 36 | * The DER encoder of any type. May be invoked by the application. |
| 37 | */ |
| 38 | der_enc_rval_t der_encode(struct asn1_TYPE_descriptor_s *type_descriptor, |
| 39 | void *struct_ptr, /* Structure to be encoded */ |
| 40 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 41 | void *app_key /* Arbitrary callback argument */ |
| 42 | ); |
| 43 | |
| 44 | /* |
| 45 | * Type of the generic DER encoder. |
| 46 | */ |
| 47 | typedef der_enc_rval_t (der_type_encoder_f)( |
| 48 | struct asn1_TYPE_descriptor_s *type_descriptor, |
| 49 | void *struct_ptr, /* Structure to be encoded */ |
| 50 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
| 51 | ber_tlv_tag_t tag, |
| 52 | asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ |
| 53 | void *app_key /* Arbitrary callback argument */ |
| 54 | ); |
| 55 | |
| 56 | |
| 57 | /******************************* |
| 58 | * INTERNALLY USEFUL FUNCTIONS * |
| 59 | *******************************/ |
| 60 | |
| 61 | /* |
| 62 | * Write out leading TL[v] sequence according to the type definition. |
| 63 | */ |
| 64 | ssize_t der_write_tags( |
| 65 | struct asn1_TYPE_descriptor_s *type_descriptor, |
| 66 | size_t struct_length, |
| 67 | int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ |
| 68 | ber_tlv_tag_t tag, |
| 69 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 70 | void *app_key |
| 71 | ); |
| 72 | |
| 73 | #endif /* _DER_ENCODER_H_ */ |