ber_decoder.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 _BER_DECODER_H_
  6. #define _BER_DECODER_H_
  7. #include <asn_application.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. struct asn_TYPE_descriptor_s; /* Forward declaration */
  12. struct asn_codec_ctx_s; /* Forward declaration */
  13. /*
  14. * The BER decoder of any type.
  15. * This function may be invoked directly from the application.
  16. * Decodes BER, DER and CER data (DER and CER are different subsets of BER).
  17. *
  18. * NOTE: Use the der_encode() function (der_encoder.h) to produce encoding
  19. * which is compliant with ber_decode().
  20. */
  21. asn_dec_rval_t ber_decode(
  22. const struct asn_codec_ctx_s *opt_codec_ctx,
  23. const struct asn_TYPE_descriptor_s *type_descriptor,
  24. void **struct_ptr, /* Pointer to a target structure's pointer */
  25. const void *buffer, /* Data to be decoded */
  26. size_t size /* Size of that buffer */
  27. );
  28. /*
  29. * Type of generic function which decodes the byte stream into the structure.
  30. */
  31. typedef asn_dec_rval_t(ber_type_decoder_f)(
  32. const struct asn_codec_ctx_s *opt_codec_ctx,
  33. const struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr,
  34. const void *buf_ptr, size_t size, int tag_mode);
  35. /*******************************
  36. * INTERNALLY USEFUL FUNCTIONS *
  37. *******************************/
  38. /*
  39. * Check that all tags correspond to the type definition (as given in head).
  40. * On return, last_length would contain either a non-negative length of the
  41. * value part of the last TLV, or the negative number of expected
  42. * "end of content" sequences. The number may only be negative if the
  43. * head->last_tag_form is non-zero.
  44. */
  45. asn_dec_rval_t ber_check_tags(
  46. const struct asn_codec_ctx_s *opt_codec_ctx, /* codec options */
  47. const struct asn_TYPE_descriptor_s *type_descriptor,
  48. asn_struct_ctx_t *opt_ctx, /* saved decoding context */
  49. const void *ptr, size_t size,
  50. int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */
  51. int last_tag_form, /* {-1,0:1}: any, primitive, constr */
  52. ber_tlv_len_t *last_length, int *opt_tlv_form /* optional tag form */
  53. );
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif /* _BER_DECODER_H_ */