blob: 0bd86a96bf17ee0e532dd04ed16268eb2001aaf2 [file] [log] [blame]
aa7133@att.com84bd3342020-03-16 18:04:57 +02001/*-
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
8#include <asn_system.h> /* Platform-dependent types */
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14struct asn_TYPE_descriptor_s; /* Forward declaration */
15
16/*
17 * Validate the structure according to the ASN.1 constraints.
18 * If errbuf and errlen are given, they shall be pointing to the appropriate
19 * buffer space and its length before calling this function. Alternatively,
20 * they could be passed as NULL's. If constraints validation fails,
21 * errlen will contain the actual number of bytes taken from the errbuf
22 * to encode an error message (properly 0-terminated).
23 *
24 * RETURN VALUES:
25 * This function returns 0 in case all ASN.1 constraints are met
26 * and -1 if one or more constraints were failed.
27 */
28int asn_check_constraints(
29 const struct asn_TYPE_descriptor_s *type_descriptor,
30 const void *struct_ptr, /* Target language's structure */
31 char *errbuf, /* Returned error description */
32 size_t *errlen /* Length of the error description */
33);
34
35
36/*
37 * Generic type for constraint checking callback,
38 * associated with every type descriptor.
39 */
40typedef int(asn_constr_check_f)(
41 const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr,
42 asn_app_constraint_failed_f *optional_callback, /* Log the error */
43 void *optional_app_key /* Opaque key passed to a callback */
44);
45
46/*******************************
47 * INTERNALLY USEFUL FUNCTIONS *
48 *******************************/
49
50asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */
51asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */
52
53/*
54 * Invoke the callback with a complete error message.
55 */
56#define ASN__CTFAIL if(ctfailcb) ctfailcb
57
58#ifdef __cplusplus
59}
60#endif
61
62#endif /* ASN1_CONSTRAINTS_VALIDATOR_H */