ber_tlv_length.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_TLV_LENGTH_H_
  6. #define _BER_TLV_LENGTH_H_
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. typedef ssize_t ber_tlv_len_t;
  11. /*
  12. * This function tries to fetch the length of the BER TLV value and place it
  13. * in *len_r.
  14. * RETURN VALUES:
  15. * 0: More data expected than bufptr contains.
  16. * -1: Fatal error deciphering length.
  17. * >0: Number of bytes used from bufptr.
  18. * On return with >0, len_r is constrained as -1..MAX, where -1 mean
  19. * that the value is of indefinite length.
  20. */
  21. ssize_t ber_fetch_length(int _is_constructed, const void *bufptr, size_t size,
  22. ber_tlv_len_t *len_r);
  23. /*
  24. * This function expects bufptr to be positioned over L in TLV.
  25. * It returns number of bytes occupied by L and V together, suitable
  26. * for skipping. The function properly handles indefinite length.
  27. * RETURN VALUES:
  28. * Standard {-1,0,>0} convention.
  29. */
  30. ssize_t ber_skip_length(
  31. const struct asn_codec_ctx_s *opt_codec_ctx, /* optional context */
  32. int _is_constructed, const void *bufptr, size_t size);
  33. /*
  34. * This function serializes the length (L from TLV) in DER format.
  35. * It always returns number of bytes necessary to represent the length,
  36. * it is a caller's responsibility to check the return value
  37. * against the supplied buffer's size.
  38. */
  39. size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size);
  40. #ifdef __cplusplus
  41. }
  42. #endif
  43. #endif /* _BER_TLV_LENGTH_H_ */