constraints.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*-
  2. * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
  3. * Redistribution and modifications are permitted subject to BSD license.
  4. */
  5. #ifndef ASN1_CONSTRAINTS_VALIDATOR_H
  6. #define ASN1_CONSTRAINTS_VALIDATOR_H
  7. #include <asn_system.h> /* Platform-dependent types */
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. struct asn_TYPE_descriptor_s; /* Forward declaration */
  12. /*
  13. * Validate the structure according to the ASN.1 constraints.
  14. * If errbuf and errlen are given, they shall be pointing to the appropriate
  15. * buffer space and its length before calling this function. Alternatively,
  16. * they could be passed as NULL's. If constraints validation fails,
  17. * errlen will contain the actual number of bytes taken from the errbuf
  18. * to encode an error message (properly 0-terminated).
  19. *
  20. * RETURN VALUES:
  21. * This function returns 0 in case all ASN.1 constraints are met
  22. * and -1 if one or more constraints were failed.
  23. */
  24. int asn_check_constraints(
  25. const struct asn_TYPE_descriptor_s *type_descriptor,
  26. const void *struct_ptr, /* Target language's structure */
  27. char *errbuf, /* Returned error description */
  28. size_t *errlen /* Length of the error description */
  29. );
  30. /*
  31. * Generic type for constraint checking callback,
  32. * associated with every type descriptor.
  33. */
  34. typedef int(asn_constr_check_f)(
  35. const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr,
  36. asn_app_constraint_failed_f *optional_callback, /* Log the error */
  37. void *optional_app_key /* Opaque key passed to a callback */
  38. );
  39. /*******************************
  40. * INTERNALLY USEFUL FUNCTIONS *
  41. *******************************/
  42. asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */
  43. asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */
  44. /*
  45. * Invoke the callback with a complete error message.
  46. */
  47. #define ASN__CTFAIL if(ctfailcb) ctfailcb
  48. #ifdef __cplusplus
  49. }
  50. #endif
  51. #endif /* ASN1_CONSTRAINTS_VALIDATOR_H */