blob: 0bd86a96bf17ee0e532dd04ed16268eb2001aaf2 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin20696a42017-10-17 21:27:33 -07002 * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
Lev Walkinc6cac8e2016-03-14 02:57:07 -07005#ifndef ASN1_CONSTRAINTS_VALIDATOR_H
6#define ASN1_CONSTRAINTS_VALIDATOR_H
Lev Walkinf15320b2004-06-03 03:38:44 +00007
Lev Walkindc06f6b2004-10-20 15:50:55 +00008#include <asn_system.h> /* Platform-dependent types */
Lev Walkinf15320b2004-06-03 03:38:44 +00009
Lev Walkin21b41ac2005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
Lev Walkin5e033762004-09-29 13:26:15 +000014struct asn_TYPE_descriptor_s; /* Forward declaration */
Lev Walkinf15320b2004-06-03 03:38:44 +000015
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).
Lev Walkin1eded352006-07-13 11:19:01 +000023 *
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.
Lev Walkinf15320b2004-06-03 03:38:44 +000027 */
Lev Walkin20696a42017-10-17 21:27:33 -070028int 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);
Lev Walkinf15320b2004-06-03 03:38:44 +000034
Lev Walkin1eded352006-07-13 11:19:01 +000035
Lev Walkinf15320b2004-06-03 03:38:44 +000036/*
37 * Generic type for constraint checking callback,
38 * associated with every type descriptor.
39 */
Lev Walkin20696a42017-10-17 21:27:33 -070040typedef 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);
Lev Walkinf15320b2004-06-03 03:38:44 +000045
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 */
Lev Walkin7c1dc052016-03-14 03:08:15 -070056#define ASN__CTFAIL if(ctfailcb) ctfailcb
Lev Walkinf15320b2004-06-03 03:38:44 +000057
Lev Walkin21b41ac2005-07-24 09:03:44 +000058#ifdef __cplusplus
59}
60#endif
61
Lev Walkinc6cac8e2016-03-14 02:57:07 -070062#endif /* ASN1_CONSTRAINTS_VALIDATOR_H */