asn_random_fill.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
  3. * Redistribution and modifications are permitted subject to BSD license.
  4. */
  5. #ifndef ASN_RANDOM_FILL
  6. #define ASN_RANDOM_FILL
  7. /* Forward declarations */
  8. struct asn_TYPE_descriptor_s;
  9. struct asn_encoding_constraints_s;
  10. /*
  11. * Initialize a structure with random data according to the type specification
  12. * and optional member constraints.
  13. * ARGUMENTS:
  14. * (max_length) - See (approx_max_length_limit).
  15. * (memb_constraints) - Member constraints, if exist.
  16. * The type can be constrained differently according
  17. * to PER and OER specifications, so we find a value
  18. * at the intersection of these constraints.
  19. * In case the return differs from ARFILL_OK, the (struct_ptr) contents
  20. * and (current_length) value remain in their original state.
  21. */
  22. typedef struct asn_random_fill_result_s {
  23. enum {
  24. ARFILL_FAILED = -1, /* System error (memory?) */
  25. ARFILL_OK = 0, /* Initialization succeeded */
  26. ARFILL_SKIPPED = 1 /* Not done due to (length?) constraint */
  27. } code;
  28. size_t length; /* Approximate number of bytes created. */
  29. } asn_random_fill_result_t;
  30. typedef asn_random_fill_result_t(asn_random_fill_f)(
  31. const struct asn_TYPE_descriptor_s *td, void **struct_ptr,
  32. const struct asn_encoding_constraints_s *memb_constraints,
  33. size_t max_length);
  34. /*
  35. * Returns 0 if the structure was properly initialized, -1 otherwise.
  36. * The (approx_max_length_limit) specifies the approximate limit of the
  37. * resulting structure in units closely resembling bytes. The actual result
  38. * might be several times larger or smaller than the length limit.
  39. */
  40. int asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr,
  41. size_t approx_max_length_limit);
  42. /*
  43. * Returns a random number between min and max.
  44. */
  45. intmax_t asn_random_between(intmax_t min, intmax_t max);
  46. #endif /* ASN_RANDOM_FILL */