der_encoder.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*-
  2. * Copyright (c) 2003-2017 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. #include <asn_application.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. struct asn_TYPE_descriptor_s; /* Forward declaration */
  12. /*
  13. * The DER encoder of any type. May be invoked by the application.
  14. * Produces DER- and BER-compliant encoding. (DER is a subset of BER).
  15. *
  16. * NOTE: Use the ber_decode() function (ber_decoder.h) to decode data
  17. * produced by der_encode().
  18. */
  19. asn_enc_rval_t der_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
  20. const 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. /* A variant of der_encode() which encodes data into the pre-allocated buffer */
  25. asn_enc_rval_t der_encode_to_buffer(
  26. const struct asn_TYPE_descriptor_s *type_descriptor,
  27. const void *struct_ptr, /* Structure to be encoded */
  28. void *buffer, /* Pre-allocated buffer */
  29. size_t buffer_size /* Initial buffer size (maximum) */
  30. );
  31. /*
  32. * Type of the generic DER encoder.
  33. */
  34. typedef asn_enc_rval_t(der_type_encoder_f)(
  35. const struct asn_TYPE_descriptor_s *type_descriptor,
  36. const void *struct_ptr, /* Structure to be encoded */
  37. int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
  38. ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
  39. void *app_key /* Arbitrary callback argument */
  40. );
  41. /*******************************
  42. * INTERNALLY USEFUL FUNCTIONS *
  43. *******************************/
  44. /*
  45. * Write out leading TL[v] sequence according to the type definition.
  46. */
  47. ssize_t der_write_tags(const struct asn_TYPE_descriptor_s *type_descriptor,
  48. size_t struct_length,
  49. int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
  50. int last_tag_form, /* {0,!0}: prim, constructed */
  51. ber_tlv_tag_t tag,
  52. asn_app_consume_bytes_f *consume_bytes_cb,
  53. void *app_key);
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif /* _DER_ENCODER_H_ */